生产中两台web目录须要保持目录一致,否则总是会读取不到图片文件。想过用sersync,想过用NFS,最后仍是决定用GlusterFs。html
两台服务器IP:linux
centos6.7 192.168.0.101 web1web
centos6.7 192.168.0.103 web3vim
第一步:配置环境
centos
GlusterFs 3.6的版本,已经整合到Centos了直接yum安装就好
bash
yum install centos-release-gluster36yum --enablerepo=centos-gluster36-test install glusterfs-server yum install glusterfs-server #这里会提示已经安装过了,省略这一步也能够。 /etc/init.d/glusterd startvim /etc/hosts 192.168.0.101 web1192.168.0.103 web3
上面安装环境,添加hosts,须要两台服务器都加好。服务器
第二步:互联两台服务器
web1上添加web3app
gluster peer probe web3
[root@WEB03 ~]#gluster peer status #查看状态Number of Peers: 1Hostname: web1 Uuid: f257de61-2932-48c2-9837-1a5fb678d6e4 State: Peer in Cluster (Connected) web3上添加web1 gluster peer probe web1 [root@WEB01 ~]# gluster peer status Number of Peers: 1 Hostname: web3 Uuid: bf2ce986-a5b2-454a-8a0d-8149c6e7b4c4 State: Peer in Cluster (Connected)
第三步:建立共享卷socket
#建立共享卷,只须要在一台服务器上执行就能够了。
tcp
gluster volume create volume1 replica 2 transport tcp web1:/gluster-storage web3:/gluster-storage force
#这条语句意思是建立名为volume1的卷,repilica 2 复制2份,到web1的/gluster-storage,web3de /gluster-storage分区传输方式为tcp force必须加,否则会报错。
#启动卷
gluster volume start volume1
#参考卷信息
[root@WEB01 ~]# gluster volume info Volume Name: volume1Type: ReplicateVolume ID: a8a3db8a-63c0-45ab-b9b1-ae75b9e36b3eStatus: StartedNumber of Bricks: 1 x 2 = 2Transport-type: tcpBricks:Brick1: web1:/gluster-storageBrick2: web3:/gluster-storage
第四步挂载共享存储
[root@WEB01 ~]# cat /etc/fstab # # /etc/fstab# Created by anaconda on Tue Jul 19 21:49:54 2016# # Accessible filesystems, by reference, are maintained under '/dev/disk'# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info /dev/mapper/vg_c41wrm21web01-lv_root / ext4 defaults 1 1 UUID=46025776-75ec-43c6-b1c8-9ae904d24c5c /boot ext4 defaults 1 2 /dev/mapper/vg_c41wrm21web01-lv_swap swap swap defaults 0 0 web3:/volume1 /var/www/html glusterfs defaults,_netdev 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 [root@WEB03 ~]# cat /etc/fstab ## /etc/fstab # Created by anaconda on Tue Jul 19 15:45:59 2016 ## Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info /dev/mapper/vg_c41wrm21web03-lv_root / ext4 defaults 1 1 UUID=17e60fe4-79ff-461e-8204-5330d0e77f50 /boot ext4 defaults 1 2 /dev/mapper/vg_c41wrm21web03-lv_swap swap swap defaults 0 0 web1:/volume1 /var/www/html glusterfs defaults,_netdev 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0
#若是/var/www/html目录下有文件的话须要备份出来,否则下一步挂载将会丢失数据。
mount /var/www/html
最后一步:测试
两台机器随意写入,或删除文件,看看是否另一台机器也跟着变更。
Ps:
[root@WEB01 ~] gluster peer status Connection failed. Please check if gluster daemon is operational.
通常状况下是glusterd服务没有启动,若是启动了仍是显示这个错误,那么,你须要停掉服务,再删掉glusterd.socket文件,再启动。最好再确认下selinux为disabled
[root@WEB01 ~] gluster peer probe web1 peer probe: failed: Probe returned with unknown errno 107
若是碰到这个状况,须要关闭防火墙,或者开放24007端口
iptables -I INPUT -p tcp --dport 24007 -j ACCEPT