文章目錄
- 一、GlusterFS概述
- 1.1簡介
- 1.2特點
- 1.3GlusterFS相關術語
- 1.4模塊化堆疊式架構
- 二、GlusterFS作業原理
- 2.1彈性hash演算法
- 2.2GlusterFS作業流程
- 三、GlusterFS的卷型別
- 3.1分布式卷
- 3.2條帶卷
- 3.3復制卷
- 3.4分布式條帶卷
- 3.5分布式復制卷
- 四、部署GlusterFS卷
- 4.1實驗環境
- 4.2以下程序為構建存盤池子
- 4.3根據規劃創建如下卷
- 4.3.1創建分布式卷
- 4.3.2創建復制卷
- 4.3.3創建分布式復制卷
- 4.4破壞測驗
- 4.5訪問控制
一、GlusterFS概述
1.1簡介
Glusterfs是一個開源的分布式檔案系統,是Scale存盤的核心,能夠處理千數量級的客戶端.在傳統的解決 方案中Glusterfs能夠靈活的結合物理的,虛擬的和云資源去體現高可用和企業級的性能存盤.
Glusterfs通過TCP/IP或InfiniBand RDMA網路鏈接將客戶端的存盤資塊源聚集在一起,使用單一的全域命名空間來管理資料,磁盤和記憶體資源.
Glusterfs基于堆疊的用戶空間設計,可以為不同的作業負載提供高優的性能.
1.2特點
●擴展性和高性能
GlusterFS利用雙重特性來提供幾TB至數PB的高擴展存盤解決方案,Scale-Out架構允許通過簡單地增加資源來提高存盤容量和性能,磁盤、計算和I/O資源都可以獨立增加,支持10GbE和InfiniBand等高速網路互聯,Gluster彈性哈希(Elastic Hash)解除了GlusterFS對元資料服務器的需求,消除了單點故障和性能瓶頸,真正實作了并行化資料訪問,
●高可用性
GlusterFS可以對檔案進行自動復制,如鏡像或多次復制,從而確保資料總是可以訪問,甚至是在硬體故障的情況下也能正常訪問,自我修復功能能夠把資料恢復到正確的狀態,而且修復是以增量的方式在后臺執行,幾乎不會產生性能負載,GlusterFS沒有設計自己的私有資料檔案格式,而是采用作業系統中主流標準的磁盤檔案系統(如EXT3、ZFS)來存盤檔案,因此資料可以使用各種標準工具進行復制和訪問,
●全域統一命名空間
全域統一命名空間將磁盤和記憶體資源聚集成一個單一的虛擬存盤池,對上層用戶和應用屏蔽了底層的物理硬體,存盤資源可以根據需要在虛擬存盤池中進行彈性擴展,比如擴容或收縮,當存盤虛擬機映像時,存盤的虛擬映像檔案沒有數量限制,成千虛擬機均通過單一掛載點進行資料共享,虛擬機I/O可在命名空間內的所有服務器上自動進行負載均衡,消除了SAN環境中經常發生的訪問熱點和性能瓶頸問題,
●彈性卷管理
資料儲存在邏輯卷中,邏輯卷可以從虛擬化的物理存盤池進行獨立邏輯劃分而得到,存盤服務器可以在線進行增加和移除,不會導致應用中斷,邏輯卷可以在所有配置服務器中增長和縮減,可以在不同服務器遷移進行容量均衡,或者增加和移除系統,這些操作都可在線進行,檔案系統配置更改也可以實時在線進行并應用,從而可以適應作業負載條件變化或在線性能調優,
●基于標準協議
Gluster存盤服務支持NFS, CIFS, HTTP, FTP以及Gluster原生協議,完全與POSIX標準兼容,現有應用程式不需要作任何修改或使用專用API,就可以對Gluster中的資料進行訪問,這在公有云環境中部署Gluster時非常有用,Gluster對云服務提供商專用API進行抽象,然后提供標準POSIX介面,
1.3GlusterFS相關術語
●Brick:GFS中的存盤單元,通過是一個受信存盤池中的服務器的一個匯出目錄,可以通過主機名和目錄名來標識,如’SERVER:EXPORT’
●Volume:一組bricks的邏輯集合(卷)
●FUSE:Filesystem Userspace是一個可加載的內核模塊,其支持非特權用戶創建自己的檔案系統而不需要修改內核代碼,通過在用戶空間運行檔案系統的代碼通過FUSE代碼與內核進行橋接,
●VFS:虛擬檔案系統
●Glusterd:Gluster management daemon,要在trusted storage pool中所有的服務器上運行,
Node:一個擁有若干brick的設備
Client: 掛載了GFS卷的設備
RDMA:遠程直接記憶體訪問,支持不通過雙方的OS進行直接記憶體訪問,
RRDNS:round robin DNS是一種通過DNS輪轉回傳不同的設備以進行負載均衡的方法
Self-heal:用于后臺運行檢測復本卷中檔案和目錄的不一致性并解決這些不一致,
Split-brain:腦裂
Volfile:glusterfs行程的組態檔,通常位于/var/lib/glusterd/vols/volname
1.4模塊化堆疊式架構
●模塊化、堆疊式的架構
●通過對模塊的組合,實作復雜的功能
GlusterFS采用模塊化、堆疊式的架構,可通過靈活的配置支持高度定制化的應用環境,比如大檔案存盤、海量小檔案存盤、云存盤、多傳輸協議應用等,每個功能以模塊形式實作,然后以積木方式進行簡單的組合,即可實作復雜的功能,比如,Replicate模塊可實作RAID1,Stripe模塊可實作RAID0,通過兩者的組合可實作RAID10和RAID01,同時獲得高性能和高可靠性,如下圖所示

二、GlusterFS作業原理
2.1彈性hash演算法
●通過hash演算法得到一個32位的整數
●劃分為N個連續的子空間,每個空間對應一個Brick
●彈性hash演算法的優點
保證資料平均分布在每一個Brick中
解決了對元資料服務器的依賴,進而解決了單點故障以及訪問瓶頸

2.2GlusterFS作業流程
1、客戶端或應用程式通過GlusterFS的掛載點訪問資料,對于用戶來說,集群系統的存在對用戶是完全透明的,用戶感覺不到是操作本地系統還是遠端的集群系統,
2、用戶的這個操作被遞交給 本地linux系統的VFS來處理,
3、VFS將資料遞交給FUSE內核檔案系統, fuse檔案系統則是將資料通過/dev/fuse設備檔案遞交給了GlusterFS client端,所以, 我們可以將 fuse檔案系統理解為一個代理,
4、GlusterFS client 收到資料后,client根據組態檔的配置對資料進行處理
5、通過網路將資料傳遞至遠端的GlusterFS Server,并且將資料寫入到服務器存盤設備上

三、GlusterFS的卷型別
3.1分布式卷
●沒有對檔案進行分塊處理
●通過擴展檔案屬性保存hash值
●支持的底層檔案系統有ext4、zfs、xfs等
●特點
檔案分布在不同的服務器,不具備冗余性
可以靈活的擴展卷的大小
單點故障會造成資料丟失
依賴底層的資料保護
●創建分布式卷
創建一個名為dis-vol的分布式卷,檔案將根據hash分布在node1:/data/sdb node2:/data/sdb中
gluster volume create dis-vol node1:/data/sdb node2:/data/sdb force
3.2條帶卷
●根據偏移量將檔案分成N塊(N個條帶節點),輪詢的存盤在每個Brick Server節點
●存盤大檔案時,性能尤為突出
●不具備冗余性,類似Raid0
●特點
資料被分割成更小塊分布到塊服務器中的不同條帶區
分布減少了負載且更小的檔案加速了存取的速度
沒有資料冗余
●創建條帶卷
創建了一個名為stripe-vol的條帶卷,檔案將被分塊輪詢的存盤在node1:/data/sdc node2:/data/sdc中
gluster volume create stripe-vol stripe 2 transport tcp node1:/data/sdc node2:/data/sdc
(transport不指明時默認是RDMA)
3.3復制卷
●同一個檔案保存一份或多份副本
●因為要保存副本,所以磁盤利用率較低
●若多個節點上的存盤空間不一致,將按照木桶效應取最低節點的容量作為該卷的總容量
●特點
卷中所有的服務器均保存一個完整的副本
卷的副本數量可由客戶創建的時候決定
至少有兩個塊服務器或更多服務器
具備冗余性
●創建復制卷
創建名為rep-vol的復制卷,檔案將同時存盤兩個副本,分別在node3:/data/sdb node4:/data/sdb兩個Brick中
gluster volume create rep-vol replica 2 node3:/data/sdb node4:/data/sdb force
3.4分布式條帶卷
●兼顧分布式卷和條帶卷的功能
●主要用于大檔案訪問處理
●最少需要4臺服務器
●創建分布式條帶卷
創建了名為dis-stripe的分布式條帶卷,配置分布式的條帶卷時,卷中Brick所包含的存盤服務器數必須是條帶數的倍數(>=2倍)
gluster volume create dis-stripe stripe 2 node1:/data/sdd node2:/data/sdd node3:/data/sdd node4:/data/sdd force
3.5分布式復制卷
●兼顧分布式卷和復制卷的功能
●用于需要冗余的情況
●創建分布式復制卷
創建名為dis-rep的分布式條帶卷,配置分布式復制卷時,卷中Brick所包含的存盤服務器數必須是條帶數的倍數(>=2倍)
gluster volume create dis-rep replica 2 node1:/data/sde node2:/data/sde node3:/data/sde node4:/data/sde force
四、部署GlusterFS卷
4.1實驗環境

安裝軟體:
服務端:glusterfs;glusterfs-server;glusterfs-fuse;glusterfs-rdma
客戶端:glusterfs;glusterfs-fuse
glusterfs:命令軟體包
glusterfs-server:glusterfs服務軟體
glusterfs-fuse:內核模塊軟體
glusterfs-rdma:通訊協議RDMA軟體包
4.2以下程序為構建存盤池子
1.每個節點添加4塊磁盤,每塊都是20G,格式化后進行掛載
采用如下的腳本進行格式化并掛載到系統中
#!/bin/bash
for i in {b,c,d,e}
do
echo "n
p
w" | fdisk /dev/sd$i
mkdir -p /data/sd$i
mkfs.xfs /dev/sd${i}1
cat>>/etc/fstab<<EOF
/dev/sd${i}1 /data/sd$i xfs defaults 0 0
EOF
done
mount -a
2.為四臺節點修改主機名,添加主機名決議到本地hosts檔案中
[root@localhost ~]# hostnamectl set-hostname node1
[root@localhost ~]# su
[root@node1 ~]# vim /etc/hosts
14.0.0.10 node1
14.0.0.20 node2
14.0.0.30 node3
14.0.0.40 node4
3.安裝glusterfs相應軟體并啟動服務
[root@localhost data]# yum -y install centos-release-gluster
#Gluster的安裝包在centos-release-gluster源里面,CentOS7.5默認帶的是GlusterFS 3.11版本,默認版本比較低,如果要安裝更高的版本需要安裝centos-release-gluster源
[root@localhost ~]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
[root@localhost ~]# systemctl start glusterd
[root@localhost ~]# systemctl enable glusterd
[root@localhost ~]# systemctl status glusterd
4.時間同步
[root@localhost ~]# ntpdate ntp1.aliyun.com
13 Sep 21:56:31 ntpdate[10857]: adjust time server 120.25.115.20 offset 0.000978 sec
5.構建存盤池子(在任意節點即可)
[root@node1 ~]# gluster peer probe node2
peer probe: success.
[root@node1 ~]# gluster peer probe node3
peer probe: success.
[root@node1 ~]# gluster peer probe node4
peer probe: success.
#查看所有節點
[root@node1 ~]# gluster peer status
Number of Peers: 3
Hostname: node2
Uuid: 472754cd-a486-435b-9dc6-30cc2e3f8165
State: Peer in Cluster (Connected)
Hostname: node3
Uuid: 95f22b8a-6ac6-417d-bb60-4fb5c0a612a2
State: Peer in Cluster (Connected)
Hostname: node4
Uuid: 13d749b8-715d-4abd-94ca-5d38852271e0
State: Peer in Cluster (Connected)
4.3根據規劃創建如下卷

注意!!!從glusterfs 6.0版本 開始,已經棄用stripe模式
[root@node1 ~]# gluster --version #查看安裝的glusterfs版本
glusterfs 7.7
Repository revision: git://git.gluster.org/glusterfs.git
Copyright (c) 2006-2016 Red Hat, Inc. <https://www.gluster.org/>
GlusterFS comes with ABSOLUTELY NO WARRANTY.
It is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3
or later), or the GNU General Public License, version 2 (GPLv2),
in all cases as published by the Free Software Foundation.
[root@node1 ~]# gluster volume create stripe-vol stripe 2 node1:/data/sdc node2:/data/sdc force
stripe option not supported #從glusterfs 6.0版本 開始,已經棄用stripe模式
所以本實驗將演示如何構建分布式卷、復制卷和分布式復制卷;生產環境中分布式復制卷用的最多,
客戶端配置:
1.添加4個服務器節點的主機名決議
[root@client ~]# vim /etc/hosts
14.0.0.10 node1
14.0.0.20 node2
14.0.0.30 node3
14.0.0.40 node4
2.安裝glusterfs軟體
[root@client ~]# yum -y install glusterfs glusterfs-fuse
3.創建5個40M的檔案
[root@client ~]# dd if=/dev/zero of=/opt/test1.txt bs=1M count=40
[root@client ~]# dd if=/dev/zero of=/opt/test2.txt bs=1M count=40
[root@client ~]# dd if=/dev/zero of=/opt/test3.txt bs=1M count=40
[root@client ~]# dd if=/dev/zero of=/opt/test4.txt bs=1M count=40
[root@client ~]# dd if=/dev/zero of=/opt/test5.txt bs=1M count=40
4.3.1創建分布式卷
[root@node1 ~]# gluster volume create dis-vol node1:/data/sdb node2:/data/sdb force
volume create: dis-vol: success: please start the volume to access data
[root@node1 ~]# gluster volume info dis-vol #查看dis-vol卷資訊
...省略內容
Status: Created
[root@node1 ~]# gluster volume start dis-vol #啟用dis-vol卷
volume start: dis-vol: success
[root@node1 ~]# gluster volume info dis-vol
...省略內容
Status: Started
#客戶端掛載分布式卷到/test/dis目錄下,并將5個測驗檔案拷貝進去
[root@client ~]# mkdir -p /test/dis
[root@client ~]# mount.glusterfs node1:dis-vol /test/dis/
[root@client ~]# cp /opt/test* /test/dis/
[root@client ~]# df -Th
檔案系統 型別 容量 已用 可用 已用% 掛載點
...省略內容
node1:dis-vol fuse.glusterfs 40G 475M 40G 2% /test/dis
#回到node1和node2節點中查看5個檔案分布情況
node1下/data/sdb/被分布到了3個檔案
[root@node1 ~]# ll -h /data/sdb/
總用量 120M
-rw-r--r--. 2 root root 40M 9月 13 22:48 test1.txt
-rw-r--r--. 2 root root 40M 9月 13 22:48 test3.txt
-rw-r--r--. 2 root root 40M 9月 13 22:48 test4.txt
node2下/data/sdb/被分布到了2個檔案
[root@node2 ~]# ll -h /data/sdb/
總用量 80M
-rw-r--r--. 2 root root 40M 9月 13 22:48 test2.txt
-rw-r--r--. 2 root root 40M 9月 13 22:48 test5.txt
4.3.2創建復制卷
[root@node1 ~]# gluster volume create rep-vol replica 2 node3:/data/sdb node4:/data/sdb force
[root@node1 ~]# gluster volume start rep-vol
[root@node1 ~]# gluster volume status rep-vol #查看rep-vol卷狀態
Status of volume: rep-vol
Gluster process TCP Port RDMA Port Online Pid
------------------------------------------------------------------------------
Brick node3:/data/sdb 49152 0 Y 68129
Brick node4:/data/sdb 49152 0 Y 11283
...省略內容
#客戶端掛載分布式卷到/test/rep-vol目錄下,并將5個測驗檔案拷貝進去
[root@client test]# mkdir /test/rep-vol
[root@client test]# mount.glusterfs node1:rep-vol/ /test/rep-vol/
[root@client test]# df -Th
檔案系統 型別 容量 已用 可用 已用% 掛載點
...省略內容
node1:rep-vol fuse.glusterfs 20G 238M 20G 2% /test/rep-vol #復制卷容量是總和一半
[root@client ~]# cp /opt/test* /test/rep-vol/
#回到node3和node4節點中查看5個檔案分布情況
node3下/data/sdb/被分布到了5個檔案
[root@node3 sdb]# ll -h /data/sdb
總用量 200M
-rw-r--r--. 2 root root 40M 9月 13 23:22 test1.txt
-rw-r--r--. 2 root root 40M 9月 13 23:22 test2.txt
-rw-r--r--. 2 root root 40M 9月 13 23:22 test3.txt
-rw-r--r--. 2 root root 40M 9月 13 23:22 test4.txt
-rw-r--r--. 2 root root 40M 9月 13 23:22 test5.txt
node4下/data/sdb/也被分布到了5個檔案
[root@node4 ~]# ll -h /data/sdb
總用量 200M
-rw-r--r--. 2 root root 40M 9月 13 23:22 test1.txt
-rw-r--r--. 2 root root 40M 9月 13 23:22 test2.txt
-rw-r--r--. 2 root root 40M 9月 13 23:22 test3.txt
-rw-r--r--. 2 root root 40M 9月 13 23:22 test4.txt
-rw-r--r--. 2 root root 40M 9月 13 23:22 test5.txt
4.3.3創建分布式復制卷
[root@node1 ~]# gluster volume create dis-rep replica 2 node1:/data/sde node2:/data/sde node3:/data/sde node4:/data/sde force
volume create: dis-rep: success: please start the volume to access data
[root@node1 ~]# gluster volume start dis-rep
volume start: dis-rep: success
#客戶端掛載分布式卷到/test/dis-rep目錄下,并將5個測驗檔案拷貝進去
[root@client ~]# mkdir /test/dis-rep
[root@client ~]# mount.glusterfs node1:dis-rep /test/dis-rep
[root@client ~]# df -Th
檔案系統 型別 容量 已用 可用 已用% 掛載點
...省略內容
node1:dis-rep fuse.glusterfs 40G 475M 40G 2% /test/dis-rep
[root@client ~]# cp /opt/test* /test/dis-rep
#回到node1、node2、node3和node4節點中查看5個檔案分布情況
#node1和node2節點中互為備份的存了三個檔案
[root@node1 ~]# ll -h /data/sde/
總用量 120M
-rw-r--r--. 2 root root 40M 9月 13 23:29 test1.txt
-rw-r--r--. 2 root root 40M 9月 13 23:29 test3.txt
-rw-r--r--. 2 root root 40M 9月 13 23:29 test4.txt
[root@node2 ~]# ll -h /data/sde/
總用量 120M
-rw-r--r--. 2 root root 40M 9月 13 23:29 test1.txt
-rw-r--r--. 2 root root 40M 9月 13 23:29 test3.txt
-rw-r--r--. 2 root root 40M 9月 13 23:29 test4.txt
#node3和node4節點中互為備份的存了剩下的兩個檔案
[root@node3 sdb]# ll -h /data/sde/
總用量 80M
-rw-r--r--. 2 root root 40M 9月 13 23:29 test2.txt
-rw-r--r--. 2 root root 40M 9月 13 23:29 test5.txt
[root@node4 ~]# ll -h /data/sde/
總用量 80M
-rw-r--r--. 2 root root 40M 9月 13 23:29 test2.txt
-rw-r--r--. 2 root root 40M 9月 13 23:29 test5.txt
4.4破壞測驗
將node2宕機掉模擬故障,查看客戶端中掛載點中依然存在的檔案:
[root@client test]# ll -h dis
總用量 120M
-rw-r--r-- 1 root root 40M 9月 13 22:48 test1.txt
-rw-r--r-- 1 root root 40M 9月 13 22:48 test3.txt
-rw-r--r-- 1 root root 40M 9月 13 22:48 test4.txt
[root@client test]# ll -h dis-rep
總用量 200M
-rw-r--r-- 1 root root 40M 9月 13 23:37 test1.txt
-rw-r--r-- 1 root root 40M 9月 13 23:37 test2.txt
-rw-r--r-- 1 root root 40M 9月 13 23:37 test3.txt
-rw-r--r-- 1 root root 40M 9月 13 23:37 test4.txt
-rw-r--r-- 1 root root 40M 9月 13 23:37 test5.txt
[root@client test]# ll -h rep-vol
總用量 200M
-rw-r--r-- 1 root root 40M 9月 13 23:22 test1.txt
-rw-r--r-- 1 root root 40M 9月 13 23:22 test2.txt
-rw-r--r-- 1 root root 40M 9月 13 23:22 test3.txt
-rw-r--r-- 1 root root 40M 9月 13 23:22 test4.txt
-rw-r--r-- 1 root root 40M 9月 13 23:22 test5.txt
總結:復制卷、分布式復制卷的資料完整,條帶卷資料全部丟失,分布式卷丟失一部分
4.5訪問控制
#僅拒絕某個用戶
[root@node1 ~]# gluster volume set dis-rep auth.reject 14.0.0.50
volume set: success
#僅允許某個用戶
[root@node1 ~]# gluster volume set dis-rep auth.allow 14.0.0.50
volume set: success
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/51896.html
標籤:AI
上一篇:shader 矩形
下一篇:git小烏龜
