Glusterfs 分布式存储系统配置

在服务器集群中,为了同步更新APP内容,利用Glusterfs分布式存储功达到相同的APP只更新一次,其他机器同步更新

试验环境:VmwareFusion3.1.1CentOS5.5

1.安装

#yum-yinstallglusterfs-clusterglusterfs-server

2.设置两台机器的别名分别为svr1,svr2

3.两台机器的服务端配置文件和客户端文件如下:

服务端配置文件glusterfsd.vol

[root@svr1~]#cat/etc/glusterfs/glusterfsd.vol

###file:server-volume.vol.sample

#####################################

###GlusterFSServerVolumeFile##

#####################################

####CONFIGFILERULES:

###"#"iscommentcharacter.

###-Configfileiscasesensitive

###-Optionswithinavolumeblockcanbeinanyorder.

###-Spacesortabsareusedasdelimitterwithinaline.

###-Multiplevaluestooptionswillbe:delimitted.

###-Eachoptionshouldendwithinaline.

###-Missingorcommentedfieldswillassumedefaultvalues.

###-Blank/commentedlinesareallowed.

###-Sub-volumesshouldalreadybedefinedabovebeforereferring.

###Exportvolume"brick"withthecontentsof"/home/export"directory.

volumeposix

typestorage/posix#POSIXFStranslator

optiondirectory/opt/export#Exportthisdirectory

end-volume

volumelocks

typefeatures/locks

#optionmandatory-lockson

subvolumesposix

end-volume

volumebrick

typeperformance/io-threads

optionthread-count8

subvolumeslocks

end-volume

###Addnetworkservingcapabilitytoabovebrick.

volumeserver

typeprotocol/server

optiontransport-typetcp

#optiontransport-typeunix

#optiontransport-typeib-sdp

#optiontransport.socket.bind-address192.168.1.10#Defaultistolistenonallinterfaces

#optiontransport.socket.listen-port6996#Defaultis6996

#optiontransport-typeib-verbs

#optiontransport.ib-verbs.bind-address192.168.1.10#Defaultistolistenonallinterfaces

#optiontransport.ib-verbs.listen-port6996#Defaultis6996

#optiontransport.ib-verbs.work-request-send-size131072

#optiontransport.ib-verbs.work-request-send-count64

#optiontransport.ib-verbs.work-request-recv-size131072

#optiontransport.ib-verbs.work-request-recv-count64

#optionclient-volume-filename/etc/glusterfs/glusterfs-client.vol

subvolumesbrick

#NOTE:Accesstoanyvolumethroughprotocol/serverisdeniedby

#default.Youneedtoexplicitlygrantaccessthrough#"auth"

#option.

optionauth.addr.brick.allow127.0.0.1,192.168.*#Allowaccessto"brick"volume

end-volume

客户端配置文件glusterfs.vol

[root@svr1~]#cat/etc/glusterfs/glusterfs.vol

###file:client-volume.vol.sample

#####################################

###GlusterFSClientVolumeFile##

#####################################

####CONFIGFILERULES:

###"#"iscommentcharacter.

###-Configfileiscasesensitive

###-Optionswithinavolumeblockcanbeinanyorder.

###-Spacesortabsareusedasdelimitterwithinaline.

###-Eachoptionshouldendwithinaline.

###-Missingorcommentedfieldswillassumedefaultvalues.

###-Blank/commentedlinesareallowed.

###-Sub-volumesshouldalreadybedefinedabovebeforereferring.

###Addclientfeatureandattachtoremotesubvolume

volumesvr1

typeprotocol/client

optiontransport-typetcp

optionremote-hostsvr1

optionremote-subvolumebrick#nameoftheremotevolume

end-volume

volumesvr2

typeprotocol/client

optiontransport-typetcp

optionremote-hostsvr2

optionremote-subvolumebrick

end-volume

volumereplicate1

typecluster/replicate

subvolumessvr1

end-volume

volumereplicate2

typecluster/replicate

subvolumessvr2

end-volume

volumedistribute

typecluster/distribute

subvolumesreplicate1replicate2

#subvolumesreplicate1

end-volume

volumewritebehind

typeperformance/write-behind

optioncache-size1MB

subvolumesdistribute

end-volume

volumecache

typeperformance/io-cache

optioncache-size64MB

subvolumeswritebehind

end-volume

4.接下来启动服务端

[root@svr1~]#glusterfsd-f/etc/glusterfs/glusterfsd.vol

执行psfax|grepgluseterfs查看是否有启动

使用以上命令操作svr2

5.启动客户端

启动客户端之前先挂起fuse

[root@svr1~]#modprobefuse

启动客户端

[root@svr1~]#glusterfs-l/var/log/glusterfs/opt-glusterfs.log-f/etc/glusterfs/glusterfs.vol/opt/clusterfs

使用df-h查看挂载是否成功

[root@svr1~]#df-h

文件系统容量已用可用已用%挂载点

/dev/hda25.7G4.6G858M85%/

/dev/hda32.9G69M2.7G3%/home

/dev/hda199M12M82M13%/boot

tmpfs502M0502M0%/dev/shm

glusterfs#/etc/glusterfs/glusterfs.vol

12G9.0G1.9G84%/opt/clusterfs

如果没有如上显示,则说明挂载没有成功,可以查看/var/log/glusterfs/opt-glusterfs.log下建立的日志进行排错

最后使用以上命令进行svr2的操作

注:假如重启到glusterfs挂连接不上,可以使用命令取消挂起

[root@svr1~]#df-h

FilesystemSizeUsedAvailUse%Mountedon

/dev/mapper/vg_webserver2-lv_root

50G2.0G45G5%/

tmpfs1.5G01.5G0%/dev/shm

/dev/sda1485M37M423M8%/boot

/dev/mapper/vg_webserver2-lv_home

46G180M44G1%/home

df:`/opt/clusterfs':Transportendpointisnotconnected

[root@svr1~]#umount/opt/clusterfs

root@svr2~]#umount/opt/clusterfs

================================

最后的效果是,不管在哪台机器上的/opt/glusterfs下新建更新文件,都会同步更新到另一台机器上,当你相同的APP在N台机器上时,这是多么轻松的事啊