一集峦、實驗背景
Gluster是一個大尺度文件系統(tǒng)尊蚁,它是各種不同的存儲服務器之上的組合悼沈,這些服務器由以太網或無限帶寬技術Infiniband以及遠程直接內存訪問RDMA互相融匯块请,最終所形成的一個大的并行文件系統(tǒng)網絡奠支,包括云計算在內的多重應用窿给,諸如:生物醫(yī)藥科學贵白,文檔存儲。
glusterFS是一個開源的分布式文件系統(tǒng),于2011年被紅帽收購.它具有高擴展性崩泡、高性能禁荒、高可用性、可橫向擴展的彈性特點,無元數據服務器設計使glusterFS沒有單點故障隱患角撞。gluster是由GNU托管的自由軟件呛伴,證書是AGPL,Gluster公司是Gluster的首要商業(yè)贊助商谒所,且提供商業(yè)產品以及基于Gluster的解決方案热康。
Gluster是Client/Server架構,服務器典型的布置在存儲磚上劣领,每一臺服務器運行一個名為glusterfsd 的守護進程褐隆,將本地文件系統(tǒng)作為卷進行輸出。
Gluster的客戶端進程通過TCP/IP剖踊,InfiniBand或SDP一類客戶協(xié)議連接到服務器庶弃,將遠端卷組成一個大的所謂折疊式翻譯器衫贬,最終的卷通過一種叫做FUSE的用戶空間文件機制機載到客戶機。有大量文件應用的I/O同樣可以用libglusterfs 客戶端庫來直接連接服務器并內在的運行翻譯器歇攻,而無需經過文件系統(tǒng)以及FUSE.大多數GlusterFS功能被實現為翻譯器固惯,包括了:
二、實驗環(huán)境
操作系統(tǒng):CentOS7.5 Mininmal?
三、設置selinux和防火墻
在gfs01 gfs02? gfs03服務器上
關閉selinux
# setenforce 0
# sed -i 's/^SELINUX=.*/SELINUX=permissive/g'? /etc/selinux/config
開放相關服務端口
# systemctl? start firewalld.service
# systemctl? enable firewalld.service
# firewall-cmd --zone=public --add-port=24007-24008/tcp --permanent
# firewall-cmd --zone=public --add-port=24009/tcp --permanent
#? firewall-cmd --zone=public --add-service=nfs --add-service=samba --add-service=samba-client --permanent
# firewall-cmd --zone=public --add-port=111/tcp --add-port=139/tcp --add-port=445/tcp --add-port=965/tcp --add-port=2049/tcp --add-port=38465-38469/tcp --add-port=631/tcp --add-port=111/udp --add-port=963/udp --add-port=49152-49251/tcp --permanent
# firewall-cmd --reload
四、安裝glusterFS 服務端
在gfs01 gfs02? gfs03服務器上
設置host解析
# vim /etc/hosts
####################################
192.168.1.101? gfs01?
192.168.1.103? ?gfs02?
192.168.1.104? ?gfs03?
#####################################
# ping gfs01
# ping gfs02
# ping gfs03
格式化掛載數據盤
# mkdir? -p /opt/glusterfs
# mkfs.xfs -i size=512 /dev/sdb
#?echo '/dev/sdb /opt/glusterfs xfs defaults 1 2'? >>?/etc/fstab
#? mount? -a?
# lsblk?
安裝軟件包
#??yum?-y? install epel-release?
# yum? -y install?centos-release-gluster
# rpm -ql???centos-release-gluster
# cat /etc/yum.repos.d/CentOS-Gluster-6.repo
# yum list available --disablerepo="*" --enablerepo="centos-gluster6"
# yum list available --disablerepo="*" --enablerepo="centos-gluster6" | grep gluster
# yum?-y?install glusterfs glusterfs-server glusterfs-rdma
# rpm -ql glusterfs-server | grep "/etc"
# rpm -ql glusterfs-server | grep "/usr/lib/systemd"
# rpm -qc glusterfs-server
啟動glusterFS服務
# systemctl start glusterd.service
# systemctl enable glusterd.service
# systemctl status glusterd.service
# systemctl status rpcbind
# cat /usr/lib/systemd/system/glusterd.service
在gfs01節(jié)點上央勒,將gfs02 gfs03 兩個節(jié)點加入到gluster集群
# gluster peer probe gfs01
# gluster peer probe gfs02
# gluster peer probe gfs02
分別在gfs01勺美、gfs02、gfs03 查看集群peer狀態(tài)
# gluster peer status
在gfs01叙谨、gfs02、gfs03 節(jié)點上,創(chuàng)建數據目錄
#?mkdir -p /opt/glusterfs/data
# gluster volume info
在gfs01節(jié)點上烂斋,創(chuàng)建GlusterFS磁盤
#??gluster volume create models replica 3 gfs01:/opt/glusterfs/data?gfs02:/opt/glusterfs/data gfs03:/opt/glusterfs/data force
注:replica 3 表明存儲3個備份,后面指定服務器的存儲目錄
# gluster?volume?start??models
在gfs01 gfs02 gfs03 節(jié)點上础废,查看volume狀態(tài)
# gluster volume info
# ll /var/log/glusterfs
五汛骂、GlusterFS集群模式說明
GlusterFS分布式存儲集群的模式只數據在集群中的存放結構,類似于磁盤陣列中的級別评腺。
a)分布式卷(Distributed Volume)帘瞭,默認模式,DHT
又稱哈希卷蒿讥,近似于RAID0蝶念,文件沒有分片,文件根據hash算法寫入各個節(jié)點的硬盤上芋绸,優(yōu)點是容量大祸轮,缺點是沒冗余。
#?gluster volume create test-volume server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4
b)復制卷(Replicated Volume)侥钳,復制模式适袜,AFR
相當于raid1,復制的份數舷夺,決定集群的大小苦酱,通常與分布式卷或者條帶卷組合使用,解決前兩種存儲卷的冗余缺陷给猾。缺點是磁盤利用率低疫萤。復本卷在創(chuàng)建時可指定復本的數量,通常為2或者3敢伸,復本在存儲時會在卷的不同brick上扯饶,因此有幾個復本就必須提供至少多個brick,當其中一臺服務器失效后,可以從另一臺服務器讀取數據尾序,因此復制GlusterFS卷提高了數據可靠性的同事钓丰,還提供了數據冗余的功能。
#?gluster volume create test-volume replica 2 transport tcp server1:/exp1 server2:/exp2
避免腦裂每币,加入仲裁:
#?gluster volume create replica 3 arbiter 1 host1:brick1 host2:brick2 host3:brick3
c)分布式復制卷(Distributed Replicated Volume)携丁,最少需要4臺服務器。
#?gluster volume create test-volume replica 2 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4
d)條帶卷(Striped Volume)
相當于raid0兰怠,文件是分片均勻寫在各個節(jié)點的硬盤上的梦鉴,優(yōu)點是分布式讀寫,性能整體較好揭保。缺點是沒冗余肥橙,分片隨機讀寫可能會導致硬盤IOPS飽和。
#?gluster volume create test-volume stripe 2 transport tcp server1:/exp1 server2:/exp2
e)分布式條帶卷(Distributed Striped Volume)秸侣,最少需要4臺服務器存筏。
當單個文件的體型十分巨大,客戶端數量更多時塔次,條帶卷已經無法滿足需求,此時將分布式與條帶化結合起來是一個比較好的選擇名秀。其性能與服務器數量有關励负。
#?gluster volume create test-volume stripe 4 transport tcp server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4 server5:/exp5 server6:/exp6 server7:/exp7 server8:/exp8
六、glusterFS的性能調優(yōu)
在gfs01服務器
開啟 指定 volume 的配額: (models 為 volume 名稱)
# gluster volume quota models enable
限制 models 中 / (既總目錄) 最大使用 80GB 空間
# gluster volume quota models limit-usage / 99GB
設置 cache 大小(此處要根據實際情況匕得,如果設置太大可能導致后面客戶端掛載失敗)
# gluster volume set models performance.cache-size 512MB
開啟 異步继榆,后臺操作
# gluster volume set models performance.flush-behind on
設置 io 線程 32
# gluster volume set models performance.io-thread-count 32
設置 回寫 (寫數據時間,先寫入緩存內汁掠,再寫入硬盤)
# gluster volume set models performance.write-behind on
調優(yōu)之后的volume信息?
# gluster volume info
# gluster volume list
# gluster volume status models
七略吨、安裝配置glusterFS客戶端
設置host解析
# vim /etc/hosts
####################################
192.168.1.101? gfs01?
192.168.1.103? ?gfs02?
192.168.1.104? ?gfs03?
#####################################
# ping gfs01
# ping gfs02
# ping gfs03
掛載方式一:使用?glusterfs-fuse
安裝客戶端glusterfs-fuse軟件包
#??yum?-y? install epel-release?
# yum? -y install?centos-release-gluster
# yum -y install glusterfs glusterfs-fuse
建立掛載點,掛載glusterFS
# mkdir -p /opt/gfsmount?
# mount -t glusterfs gfs01:models /opt/gfsmount
或者直接用IP掛載
# mount -t glusterfs 192.168.1.101:/models /opt/gfsmount
# tail -f /var/log/glusterfs/opt-gfsmount.log
# df -hT
FUSE客戶端允許使用GlusterFS循環(huán)式連接,使用一個節(jié)點的名稱考阱,內部機制允許該節(jié)點發(fā)生故障翠忠,并且客戶端將轉移到受信任存儲池中的其他連接節(jié)點。
客戶端測試文件寫入
# time dd if=/dev/zero of=/opt/gfsmount/test bs=1024M count=1
# df -hT
設置客戶端的開機掛載
選擇1:將掛載寫入到/etc/fstab 下
#? echo "192.168.1.101:/models /opt/gfsmount glusterfs defaults,_netdev 0 0"? >>?/etc/fstab
# mount? -a?
# df -hT
選擇2:將掛載服務注冊成系統(tǒng)服務
#? vim /etc/systemd/system/glusterfs-fuse.service
######################################################
[Unit]
Description=GlusterFS Fuse
After=network-online.target rpcbind.service
Requires=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/mount -t glusterfs 192.168.1.101:/models /opt/gfsmount
ExecStop=/usr/bin/umount -l /opt/gfsmount
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
######################################################
# systemctl daemon-reload
# systemctl? start glusterfs-fuse.service
# systemctl? enable? glusterfs-fuse.service
# systemctl? status? glusterfs-fuse.service
高可用測試
將gfs01(192.168.1.101)關機乞榨,看客戶端文件掛載狀態(tài)
在gfs01(192.168.1.101)節(jié)點
#? init? 0?
在gfs02 gfs03節(jié)點
# gluster volume status models
在gfsClient節(jié)點
# systemctl status glusterfs-fuse.service
# df -hT
雖然我們掛載的是 gfs01節(jié)點秽之,當gfs01節(jié)點宕機時,客戶端掛載不受影響吃既,實現了高可用性考榨!
掛載方式二:使用NFS
# yum -y install nfs-utils??rpcbind?
# mount -t nfs -o mountproto=tcp,vers=3? ??gfs01:/models /opt/gfsmount? ?-vvv
或者直接用IP掛載
# mount -t nfs -o mountproto=tcp,vers=3? ?192.168.1.101:/models /opt/gfsmount? ? -vvv
The gluster NFS server has been disabled by default for GlusterFS-3.8 upstream [1].?
This is done to encourage users to use NFS-Ganesha for their NFS needs.If RHGS requires this, it can be enabled downstream.
如果要使用NFS掛載,我們需要在glusterfs服務端安裝NFS-Ganesha鹦倚,也就是服務端應該是GlusterFS + NFS-Ganesha的組合河质。
安裝NFS-Ganesha
在gfs01 gfs02? gfs03服務器上
#?gluster volume get? models nfs.disable?
#?gluster volume set vol_distributed nfs.disable on?
# sysemctl stop nfs-server?
# systemctl disable nfs-server
# yum -y install nfs-ganesha? nfs-ganesha-gluster??--disablerepo="*" --enablerepo="centos-gluster6"
# rpm -ql nfs-ganesha
配置NFS-Ganesha
在gfs01服務器上
#? vim?/etc/ganesha/ganesha.conf
#####################################################
# create new
NFS_CORE_PARAM {
? ? # possible to mount with NFSv3 to NFSv4 Pseudo path
? ? mount_path_pseudo = true;
? ? # NFS protocol
? ? Protocols = 3,4;
}
EXPORT_DEFAULTS {
? ? # default access mode
? ? Access_Type = RW;
}
EXPORT {
? ? # uniq ID
? ? Export_Id = 101;
? ? # mount path of Gluster Volume
? ? Path = "/models";
? ? FSAL {
? ? ? ? # any name
? ? ? ? name = GLUSTER;
? ? ? ? # hostname or IP address of this Node
? ? ? ? hostname="192.168.1.101";
? ? ? ? # Gluster volume name
? ? ? ? volume="models";
? ? }
? ? # config for root Squash
? ? Squash="No_root_squash";
? ? # NFSv4 Pseudo path
? ? Pseudo="/opt/glusterfs/data";
? ? # allowed security options
? ? SecType = "sys";
}
LOG {
? ? # default log level
? ? Default_Log_Level = WARN;
}
######################################################
在gfs02服務器上
#? vim?/etc/ganesha/ganesha.conf
#####################################################
# create new
NFS_CORE_PARAM {
? ? # possible to mount with NFSv3 to NFSv4 Pseudo path
? ? mount_path_pseudo = true;
? ? # NFS protocol
? ? Protocols = 3,4;
}
EXPORT_DEFAULTS {
? ? # default access mode
? ? Access_Type = RW;
}
EXPORT {
? ? # uniq ID
? ? Export_Id = 103;
? ? # mount path of Gluster Volume
? ? Path = "/models";
? ? FSAL {
? ? ? ? # any name
? ? ? ? name = GLUSTER;
? ? ? ? # hostname or IP address of this Node
? ? ? ? hostname="192.168.1.103";
? ? ? ? # Gluster volume name
? ? ? ? volume="models";
? ? }
? ? # config for root Squash
? ? Squash="No_root_squash";
? ? # NFSv4 Pseudo path
? ? Pseudo="/opt/glusterfs/data";
? ? # allowed security options
? ? SecType = "sys";
}
LOG {
? ? # default log level
? ? Default_Log_Level = WARN;
}
######################################################
在gfs03服務器上
#? vim?/etc/ganesha/ganesha.conf
#####################################################
# create new
NFS_CORE_PARAM {
? ? # possible to mount with NFSv3 to NFSv4 Pseudo path
? ? mount_path_pseudo = true;
? ? # NFS protocol
? ? Protocols = 3,4;
}
EXPORT_DEFAULTS {
? ? # default access mode
? ? Access_Type = RW;
}
EXPORT {
? ? # uniq ID
? ? Export_Id = 104;
? ? # mount path of Gluster Volume
? ? Path = "/models";
? ? FSAL {
? ? ? ? # any name
? ? ? ? name = GLUSTER;
? ? ? ? # hostname or IP address of this Node
? ? ? ? hostname="192.168.1.104";
? ? ? ? # Gluster volume name
? ? ? ? volume="models";
? ? }
? ? # config for root Squash
? ? Squash="No_root_squash";
? ? # NFSv4 Pseudo path
? ? Pseudo="/opt/glusterfs/data";
? ? # allowed security options
? ? SecType = "sys";
}
LOG {
? ? # default log level
? ? Default_Log_Level = WARN;
}
#####################################################
在gfs01 gfs02? gfs03服務器上
#? showmount -e localhost?
在gfsClient服務器上
# mount -t nfs gfs01:/opt/glusterfs/data /opt/gfsmount? ? ? -vvv
或者直接用IP掛載
# mount -t nfs 192.168.1.101:/opt/glusterfs/data /opt/gfsmount? ? -vvv
設置客戶端的開機掛載
選擇1:將掛載寫入到/etc/fstab 下
# echo? "192.168.1.101:/opt/glusterfs/data /opt/gfsmount nfs defaults,_netdev,mountproto=tcp 0 0"? >>?/etc/fstab
# mount? -a
# df -hT
# mount -l | grep "/opt/glusterfs/data"
選擇2:將掛載服務注冊成系統(tǒng)服務
#? vim /etc/systemd/system/glusterfs-nfs.service
######################################################
[Unit]
Description=GlusterFS NFS
After=network-online.target rpcbind.service
Requires=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/mount -t nfs 192.168.1.101:/opt/glusterfs/data /opt/gfsmount
ExecStop=/usr/bin/umount -l /opt/gfsmount
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
######################################################
# systemctl daemon-reload
# systemctl? start glusterfs-nfs.service
# systemctl? enable? glusterfs-nfs.service
# systemctl? status? glusterfs-nfs.service
# mount -l | grep "/opt/glusterfs/data"
# df -hT
高可用測試
將gfs01(192.168.1.101)關機,看客戶端文件掛載狀態(tài)
在gfs01(192.168.1.101)節(jié)點
#? init? 0?
在gfs02 gfs03節(jié)點
# gluster volume status models
在gfsClient節(jié)點
# systemctl status glusterfs-nfs.service
# df -hT
掛載的是 gfs01節(jié)點,當gfs01節(jié)點宕機時掀鹅,客戶端hang住了散休,存在使用的單點故障,需要手動切換掛載源淫半!
關于使用FUSE和NFS的選擇
NFS使用標準文件系統(tǒng)緩存溃槐,Native GlusterFS使用應用程序空間RAM,并且是必須定義的硬件編號科吭。
FUSE客戶端允許使用GlusterFS循環(huán)式連接昏滴, 在/ etc / fstab中使用一個節(jié)點的名稱;,但是內部機制允許該節(jié)點發(fā)生故障对人,并且客戶端將轉移到受信任存儲池中的其他連接節(jié)點谣殊。 性能比基于測試的NFS方法略慢,但不是那么大牺弄。 增益是自動HA客戶端故障轉移姻几,這通常值得對性能產生影響。
總而言之势告,這取決于應用要求蛇捌, 當系統(tǒng)上有足夠的RAM并且性能不是很重要時,FUSE似乎是更好的選擇咱台。
八络拌、參考
Installing GlusterFS - a Quick Start Guide
https://docs.gluster.org/en/latest/Quick-Start-Guide/Quickstart
Getting started with GlusterFS
https://gluster.readthedocs.io/en/latest/Administrator%20Guide/NFS-Ganesha%20GlusterFS%20Intergration
GlusterFS安裝
https://www.rainbond.com/docs/v5.0/operation-manual/storage/GlusterFS/install.html
CentOS 7 上的 GlusterFS 存儲群集
https://wiki.centos.org/zh/HowTos/GlusterFSonCentOS
分布式存儲系統(tǒng)GlusterFS安裝配置
https://blog.51cto.com/navyaijm/1258250
CentOS 7 安裝 GlusterFS
https://www.cnblogs.com/jicki/p/5801712.html
CentOS7 安裝GlusterFS
https://blog.csdn.net/wh211212/article/details/79412081
gluster/gluster-ansible
https://github.com/gluster/gluster-ansible
安裝GlusterFS-一個快速開始指南
https://github.com/Broadroad/Glusterfs-cn/blob/master/%E5%AE%89%E8%A3%85GlusterFS-%E4%B8%80%E4%B8%AA%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B%E6%8C%87%E5%8D%97.md
深入理解GlusterFS之數據均衡
https://blog.csdn.net/younger_china/article/details/85211186
談談GlusterFS的問題和不足,加深對GlusterFS系統(tǒng)的理解
https://blog.csdn.net/liuaigui/article/details/20941159
分布式文件系統(tǒng)
https://www.cnblogs.com/kevingrace/p/8709544.html
CentOS 7.x 下GlusterFS分布式存儲集群環(huán)境部署
https://www.cnblogs.com/kevingrace/p/8743812.html
用戶空間文件系統(tǒng) Filesystem in Userspace
https://zh.wikipedia.org/wiki/FUSE
分布式存儲GlusterFS實戰(zhàn)回溺,GlusterFS快速入門及概述
https://chegva.com/1745.html
https://mrlichangming.github.io/2018/10/27/GlusterFS%E4%BD%BF%E7%94%A8%E4%B8%AD%E7%9A%84%E4%B8%80%E4%BA%9B%E5%91%BD%E4%BB%A4%E7%A7%AF%E7%B4%AF
gluster文檔
https://github.com/maqingqing/TStor/wiki/%E6%96%87%E6%A1%A301%EF%BC%9Agluster%E7%9A%84%E8%BF%9B%E7%A8%8B%E4%B8%8E%E6%9C%AF%E8%AF%AD
How to Setup GlusterFS Storage on CentOS 7 / RHEL 7
https://www.linuxtechi.com/setup-glusterfs-storage-on-centos-7-rhel-7
Using NFS to Mount Red Hat Storage Volumes
https://access.redhat.com/documentation/en-US/Red_Hat_Storage/2.0/html/Administration_Guide/sect-Administration_Guide-GlusterFS_Client-NFS.html
Using NFS to Mount Volumes
https://gluster-documentations.readthedocs.io/en/latest/Administrator%20Guide/Setting%20Up%20Clients
Accessing Data - Setting Up GlusterFS Client
https://docs.gluster.org/en/latest/Administrator%20Guide/Setting%20Up%20Clients
Should I mount GlusterFS as NFS or FUSE?
https://serverfault.com/questions/796036/should-i-mount-glusterfs-as-nfs-or-fuse
gluster-set-auth.sh
https://gist.github.com/imamdigmi/fc5f2177b4124052006bdf5a11934b56
Get started with GlusterFS - considerations and installation
https://support.rackspace.com/how-to/getting-started-with-glusterfs-considerations-and-installation
GlusterFS 5 : GlusterFS + NFS-Ganesha
https://www.server-world.info/en/note?os=CentOS_7&p=glusterfs5&f=8
Configuring NFS-Ganesha over GlusterFS
https://docs.gluster.org/en/v3/Administrator%20Guide/NFS-Ganesha%20GlusterFS%20Integration
https://www.mankier.com/8/ganesha-config