NFS 结合docker 技术:
使用NFS作为存储共享服务器:
这是大型的共享存储技术:
创建一台主机:
搭建NFS服务器:
[root@room9pc01 ~]# cd /var/lib/libvirt/images/
[root@room9pc01 images]# qemu-img create -b king.img -f qcow2 coke3.img 32G
[root@room9pc01 images]# cd /etc/libvirt/qemu/
[root@room9pc01 qemu]# sed 's/node/coke3/' node.xml > /etc/libvirt/qemu/coke3.xml
[root@room9pc01 qemu]# virsh define /etc/libvirt/qemu/coke3.xml
定义域 coke3(从 /etc/libvirt/qemu/coke3.xml)
[root@room9pc01 qemu]# virsh start coke3
域 coke3 已开始
[root@room9pc01 qemu]# virsh console coke3
连接到域 coke3
换码符为 ^]
vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
DEVICE="eth0"
ONBOOT="yes"
NM_CONTROLLED="no"
TYPE="Ethernet"
BOOTPROTO="none"
IPADDR="192.168.1.10"
PREFIX="24"
GATEWAY="192.168.1.254"
:wq
[root@localhost ~]# systemctl restart network
[root@localhost ~]# ip a s
[root@docker3 ~]# yum -y install nfs-utils
[root@docker3 ~]# mkdir /var/webroot
[root@docker3 ~]# chmod 777 /var/webroot/
[root@docker3 ~]# vim /etc/exports
[root@docker3 ~]# man exports
/var/webroot *(rw,root_squash)
:wq
[root@docker3 ~]# systemctl start nfs
[root@docker3 ~]# exportfs -avr
exporting *:/var/webroot
[root@docker3 ~]# showmount -e 192.168.1.10
Export list for 192.168.1.10:
/var/webroot *
doccke1服务器:
[root@coker1 ~]# yum -y install nfs-utils
[root@coker1 ~]# mount -t nfs 192.168.1.10:/var/webroot /mnt
[root@coker1 ~]# df -h
192.168.1.10:/var/webroot 32G 1.1G 31G 4% /mnt
[root@coker1 ~]# showmount -e 192.168.1.10
Export list for 192.168.1.10:
/var/webroot *
查看注册信息:
[root@coker1 ~]# rpcinfo 192.168.1.10
启动容器:
[root@coker1 ~]# docker run -itd -v /mnt:/var/www/html 192.168.1.50:5000/myos:httpd
efc02541fbaa6913255e0f48bcb8de06fa42cf587389b720aa314b12c770b915
使用容器:
[root@coker1 ~]# docker ps
[root@coker1 ~]# docker inspect ef
[root@coker1 ~]# curl -i http://172.17.0.4 | head
docker2服务器:
[root@coker2 ~]# yum -y install nfs-utils.x86_64
[root@coker2 ~]# mount -t nfs 192.168.1.10:/var/webroot /mnt
[root@coker2 ~]# df -h
192.168.1.10:/var/webroot 32G 1.1G 31G 4% /mnt
[root@coker2 ~]# showmount -e 192.168.1.10
Export list for 192.168.1.10:
/var/webroot *
[root@coker2 ~]# rpcinfo 192.168.1.10
启动容器:
[root@coker2 ~]# docker run -itd -v /mnt:/var/www/html 192.168.1.50:5000/myos:httpd
使用容器:
[root@coker2 ~]# docker ps
[root@coker2 ~]# docker exec -it 3e8 /bin/bash
[root@3e8eb3f8c76c html]# cd /var/www/html/
[root@3e8eb3f8c76c html]# echo haha > index.html
bash: index.html: Permission denied
是因为共享目录,没有给与权限
[root@3e8eb3f8c76c html]# echo haha > index.html
再次回到docker1 查看共享效果:
[root@coker1 ~]# curl -i http://172.17.0.4 | head
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5 100 5 0 0 2608 0 --:--:-- --:--:-- --:--:-- 5000
HTTP/1.1 200 OK
Date: Wed, 22 Aug 2018 07:39:03 GMT
Server: Apache/2.4.6 (CentOS)
Last-Modified: Wed, 22 Aug 2018 07:36:19 GMT
ETag: "5-5740132cf00a7"
Accept-Ranges: bytes
Content-Length: 5
Content-Type: text/html; charset=UTF-8
haha
这就是多个宿主机的共享:通过共享目录把数据共享给所有的宿主机上: