1、Gluster介紹html
GlusterFS 是Scale-Out存儲解決方案Gluster的核心,它是一個開源的分佈式文件系統,具備強大的橫向擴展能力,經過擴展可以支持數PB存儲容量和處理數千客戶端。GlusterFS藉助TCP/IP或InfiniBand RDMA(一種支持多併發連接的「轉換線纜」技術)網絡將物理分佈的存儲資源彙集在一塊兒,使用單一全局命名空間來管理數據。GlusterFS基於可堆疊的用戶空間設計,可爲各類不一樣的數據負載提供優異的性能,工做原理圖:node
GlusterFS支持運行在任何標準IP網絡上標準應用程序的標準客戶端,如圖2所示,用戶能夠在全局統一的命名空間中使用NFS/CIFS等標準協議來訪問應用數據。GlusterFS使得用戶可擺脫原有的獨立、高成本的封閉存儲系統,可以利用普通廉價的存儲設備來部署可集中管理、橫向擴展、虛擬化的存儲池,存儲容量可擴展至TB/PB級。git
GlusterFS主要特徵以下:算法
一、擴展性和高性能centos
GlusterFS利用雙重特性來提供幾TB至數PB的高擴展存儲解決方案。Scale-Out架構容許經過簡單地增長資源來提升存儲容量和性能,磁盤、計算和I/O資源均可以獨立增長,支持10GbE和InfiniBand等高速網絡互聯。Gluster彈性哈希(Elastic Hash)解除了GlusterFS對元數據服務器的需求,消除了單點故障和性能瓶頸,真正實現了並行化數據訪問。bash
二、高可用性服務器
GlusterFS能夠對文件進行自動複製,如鏡像或屢次複製,從而確保數據老是能夠訪問,甚至是在硬件故障的狀況下也能正常訪問。自我修復功能可以把數據恢復到正確的狀態,並且修復是以增量的方式在後臺執行,幾乎不會產生性能負載。GlusterFS沒有設計本身的私有數據文件格式,而是採用操做系統中主流標準的磁盤文件系統(如EXT三、ZFS)來存儲文件,所以數據可使用各類標準工具進行復制和訪問。網絡
三、全局統一命名空間架構
全局統一命名空間將磁盤和內存資源彙集成一個單一的虛擬存儲池,對上層用戶和應用屏蔽了底層的物理硬件。存儲資源能夠根據須要在虛擬存儲池中進行彈性擴展, 好比擴容或收縮。當存儲虛擬機映像時,存儲的虛擬映像文件沒有數量限制,成千虛擬機均經過單一掛載點進行數據共享。虛擬機I/O可在命名空間內的全部服務器上自動進行負載均衡,消除了SAN環境中常常發生的訪問熱點和性能瓶頸問題。併發
四、彈性哈希算法
GlusterFS採用彈性哈希算法在存儲池中定位數據,而不是採用集中式或分佈式元數據服務器索引。在其餘的Scale-Out存儲系統中,元數據服務器一般會致使I/O性能瓶頸和單點故障問題。GlusterFS中,全部在Scale-Out存儲配置中的存儲系統均可以智能地定位任意數據分片,不須要查看索引或者向其餘服務器查詢。這種設計機制徹底並行化了數據訪問,實現了真正的線性性能擴展。
五、彈性卷管理
數 據儲存在邏輯卷中,邏輯卷能夠從虛擬化的物理存儲池進行獨立邏輯劃分而獲得。存儲服務器能夠在線進行增長和移除,不會致使應用中斷。邏輯卷能夠在全部配置 服務器中增加和縮減,能夠在不一樣服務器遷移進行容量均衡,或者增長和移除系統,這些操做均可在線進行。文件系統配置更改也能夠實時在線進行並應用,從而可 以適應工做負載條件變化或在線性能調優。
六、基於標準協議
Gluster存儲服務支持NFS, CIFS, HTTP, FTP以及Gluster原生協議,徹底與POSIX標準兼容。現有應用程序不須要做任何修改或使用專用API,就能夠對Gluster中的數據進行訪問。這在公有云環境中部署Gluster時很是有用,Gluster對雲服務提供商專用API進行抽象,而後提供標準POSIX接口。
參考連接
http://www.tuicool.com/articles/AbE7Vr
GlusterFS術語解釋:
Brick:GFS中的存儲單元,經過是一個受信存儲池中的服務器的一個導出目錄。能夠經過主機名和目錄名來標識,如’SERVER:EXPORT’
Client:掛載了GFS卷的設備
Extended Attributes:xattr是一個文件系統的特性,其支持用戶或程序關聯文件/目錄和元數據。
FUSE:FilesystemUserspace是一個可加載的內核模塊,其支持非特權用戶建立本身的文件系統而不須要修改內核代碼。經過在用戶空間運行文件系統的代碼經過FUSE代碼與內核進行橋接。
Geo-Replication
GFID:GFS卷中的每一個文件或目錄都有一個惟一的128位的數據相關聯,其用於模擬inode
Namespace:每一個Gluster卷都導出單個ns做爲POSIX的掛載點
Node:一個擁有若干brick的設備
RDMA:遠程直接內存訪問,支持不經過雙方的OS進行直接內存訪問。
RRDNS:round robin DNS是一種經過DNS輪轉返回不一樣的設備以進行負載均衡的方法
Self-heal:用於後臺運行檢測複本卷中文件和目錄的不一致性並解決這些不一致。
Split-brain:腦裂
Translator:
Volfile:glusterfs進程的配置文件,一般位於/var/lib/glusterd/vols/volname
Volume:一組bricks的邏輯集合
2、安裝配置
一、集羣架構
系統:Centos 6.7 x86_64 服務端: 192.168.159.128 192.168.159.129 客戶端: 192.168.159.130
二、在服務端安裝
首先安裝Gluster的yum源 #yum install centos-release-gluster38 -y 安裝Glusterfs #yum install glusterfs-server -y 安裝完成以後,查看版本 #glusterfs -V glusterfs 3.8.12 built on May 11 2017 18:24:27 Repository revision: git://git.gluster.com/glusterfs.git Copyright (c) 2006-2013 Red Hat, Inc. <http://www.redhat.com/> 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. 啓動gluster #service glusterd start Starting glusterd:[ OK ] 設置開機自啓動 #chkconfig --add glusterd #chkconfig glusterd on 查看監聽的端口 #netstat -tunlp tcp 0 0 0.0.0.0:24007 0.0.0.0:* LISTEN 65940/glusterd
三、在客戶端安裝
首先安裝Gluster的yum源 #yum install centos-release-gluster38 -y 安裝客戶端glusterfs #yum install glusterfs glusterfs-fuse glusterfs-client glusterfs-libs -y
四、在服務端配置
說明:配置glusterfs集羣通常都會在服務器掛載新的磁盤,分區格式化,將整塊磁盤掛載到一個目錄 專門用來存放數據,這樣在必定程度上提升了數據的可用性,當系統出現問題的時候,數據不丟失。 參考官網:http://gluster.readthedocs.io/en/latest/Quick-Start-Guide/Quickstart/ 配置glusterfs集羣必須知足如下條件: 一、最少要2個節點 二、一個網絡(節點之間互通) 二、節點須要有2個虛擬硬盤,一個是安裝os,一個是配置glusterfs集羣,不然會報錯以下: volume create: gfs01: failed: The brick 192.168.159.128:/data/gluster is being created in the root partition. It is recommended that you don't use the system's root partition for storage backend. Or use 'force' at the end of the command if you want to override this behavior. 可是官網說要把磁盤格式化爲xfs格式,我看有些朋友是格式化爲ext4格式,而後加入/etc/fstab /dev/sdb1 /opt ext4 defaults 0 0 因此在2臺服務端添加新的磁盤,而後分區格式化,並掛載到/data目錄! #mkdir /data #fdisk /dev/sdb #分一個區,執行n , p ,1 而後回車2次,執行w #mkfs.ext4 /dev/sdb1 #mount /dev/sdb1 /data 添加到/etc/fstab /dev/sdb1 /data ext4 defaults 0 0 ##################################### 開始配置,在服務端哪一臺機器操做均可以: 添加節點: #gluster peer probe 192.168.159.128 #提示不須要添加本機 peer probe: success. Probe on localhost not needed #gluster peer probe 192.168.159.129 peer probe: success. 查看狀態: #gluster peer status Number of Peers: 1 Hostname: 192.168.159.129 Uuid: 1aed6e01-c497-4890-9447-c3bd548dd37f State: Peer in Cluster (Connected) 在另外一臺服務端查看狀態 # gluster peer status Number of Peers: 1 Hostname: 192.168.159.128 Uuid: 851be337-84b2-460d-9a73-4eee6ad95e95 State: Peer in Cluster (Connected) ################################################## 建立gluster共享目錄(在128和129服務器上都須要建立共享目錄) #mkdir /data/gluster 建立名爲gfs01的卷: #gluster volume create gfs01 replica 2 192.168.159.128:/data/gluster 192.168.159.129:/data/gluster volume create: gfs01: success: please start the volume to access data 啓動卷 #gluster volume start gfs01 volume start: gfs01: success 查看卷信息: #gluster volume info Volume Name: gfs01 Type: Replicate Volume ID: 1cdefebd-5831-4857-b1f9-f522fc868c60 Status: Started Snapshot Count: 0 Number of Bricks: 1 x 2 = 2 Transport-type: tcp Bricks: Brick1: 192.168.159.128:/data/gluster Brick2: 192.168.159.129:/data/gluster Options Reconfigured: transport.address-family: inet performance.readdir-ahead: on nfs.disable: on 查看卷狀態: #gluster volume status Status of volume: gfs01 Gluster process TCP Port RDMA Port Online Pid ------------------------------------------------------------------------------ Brick 192.168.159.128:/data/gluster 49152 0 Y 2319 Brick 192.168.159.129:/data/gluster 49152 0 Y 4659 Self-heal Daemon on localhost N/A N/A Y 2339 Self-heal Daemon on 192.168.159.129 N/A N/A Y 4683 Task Status of Volume gfs01 ------------------------------------------------------------------------------ There are no active volume tasks 其餘的用法 gluster volume stop gfs01 #中止卷 gluster volume delete gfs01 #刪除卷
五、在客戶端配置掛載
建立一個掛載點 #mkdir /opt/test_gluster #mount -t glusterfs 192.168.159.128:/gfs01 /opt/test_gluster/ [root@client ~]# ll /opt/test_gluster/ total 0 [root@client ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 18G 822M 16G 5% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 190M 27M 154M 15% /boot 192.168.159.128:/gfs01 4.8G 11M 4.6G 1% /opt/test_gluster 注意:128和129是一個集羣,掛載哪一臺均可以,若是客戶端比較多注意負載便可。 加入開機自動掛載 #cat /etc/rc.local mount -t glusterfs 192.168.159.128:/gfs01 /opt/test_gluster/
六、測試文件
在客戶端130服務器建立一個測試文件testfile.txt,寫入內容並用md5sum測試其哈希值 #ll /opt/test_gluster/ total 3 -rw-r--r-- 1 root root 2262 Jun 1 00:10 testfile.txt [root@client test_gluster]# md5sum testfile.txt 6263c0489d0567985c28d7692bde624c testfile.txt ############################################################ 到2臺服務端查看狀況 在128上 [root@server1 ~]# ll /data/gluster/ total 8 -rw-r--r-- 2 root root 2262 Jun 1 00:10 testfile.txt [root@server1 ~]# md5sum /data/gluster/testfile.txt 6263c0489d0567985c28d7692bde624c /data/gluster/testfile.txt 在129上 [root@server2 ~]# ll /data/gluster/ total 8 -rw-r--r-- 2 root root 2262 Jun 1 00:10 testfile.txt [root@server2 ~]# md5sum /data/gluster/testfile.txt 6263c0489d0567985c28d7692bde624c /data/gluster/testfile.txt 能夠看到md5sum哈希值是一致的。
七、測試集羣數據一致性
之因此使用集羣一個是能夠分攤負載,一個是能夠實現高可用,下面就測試下: 直接將129這臺服務端服務器關機!!! 而後在128查看集羣狀態,以下: [root@server1 ~]#gluster volume status Status of volume: gfs01 Gluster process TCP Port RDMA Port Online Pid ------------------------------------------------------------------------------ Brick 192.168.159.128:/data/gluster 49152 0 Y 2319 Self-heal Daemon on localhost N/A N/A Y 2589 Task Status of Volume gfs01 ------------------------------------------------------------------------------ There are no active volume tasks 能夠看到129集羣已經不存在了! ######################################################################## 此時刪除客戶端130的testfile.txt文件 #rm -f /opt/test_gluster/testfile.txt 而後會發現服務端128/data/gluster目錄下,testfile.txt文件也消失了。 這個時候從新啓動129服務器 #service glusterd status #由於配置了開機自啓動,因此是啓動的。 glusterd (pid 1368) is running... [root@server2 ~]# ll /data/gluster/ #此時再查看文件是存在的,由於在刪除客戶端文件以前次服務器關機了! total 8 -rw-r--r-- 2 root root 2262 Jun 1 00:10 testfile.txt [root@server2 ~]#md5sum /data/gluster/testfile.txt 6263c0489d0567985c28d7692bde624c /data/gluster/testfile.txt #md5sum驗證哈希值也是同樣。 過了大概10秒左右,在129服務器的testfile.txt文件也消失了,說明gluster集羣是保持數據一致性的!
說明:glusterfs集羣,不能在服務端寫入數據,要在客戶端寫入數據,會自動同步到服務端!
3、gluster集羣經常使用的一些命令
#刪除卷 gluster volume stop gfs01 gluster volume delete gfs01 #將機器移出集羣 gluster peer detach 192.168.1.100 #只容許172.28.0.0的網絡訪問glusterfs gluster volume set gfs01 auth.allow 172.28.26.* gluster volume set gfs01 auth.allow 192.168.222.1,192.168.*.* #加入新的機器並添加到卷裏(因爲副本數設置爲2,至少要添加2(四、六、8..)臺機器) gluster peer probe 192.168.222.134 gluster peer probe 192.168.222.135 #新加捲 gluster volume add-brick gfs01 repl 2 192.168.222.134:/data/gluster 192.168.222.135:/data/gluster force #刪除卷 gluster volume remove-brick gfs01 repl 2 192.168.222.134:/opt/gfs 192.168.222.135:/opt/gfs start gluster volume remove-brick gfs01 repl 2 192.168.222.134:/opt/gfs 192.168.222.135:/opt/gfs status gluster volume remove-brick gfs01 repl 2 192.168.222.134:/opt/gfs 192.168.222.135:/opt/gfs commit 注意:擴展或收縮卷時,也要按照卷的類型,加入或減小的brick個數必須知足相應的要求。 #當對捲進行了擴展或收縮後,須要對卷的數據進行從新均衡。 gluster volume rebalance mamm-volume start|stop|status ########################################################### 遷移卷---主要完成數據在卷之間的在線遷移 #啓動遷移過程 gluster volume replace-brick gfs01 192.168.222.134:/opt/gfs 192.168.222.134:/opt/test start force #查看遷移狀態 gluster volume replace-brick gfs01 192.168.222.134:/opt/gfs 192.168.222.134:/opt/test status #遷移完成後提交完成 gluster volume replace-brick gfs01 192.168.222.134:/opt/gfs 192.168.222.134:/opt/test commit #機器出現故障,執行強制提交 gluster volume replace-brick gfs01 192.168.222.134:/opt/gfs 192.168.222.134:/opt/test commit force ########################################################### 觸發副本自愈 gluster volume heal mamm-volume #只修復有問題的文件 gluster volume heal mamm-volume full #修復全部文件 gluster volume heal mamm-volume info #查看自愈詳情 ##################################################### data-self-heal, metadata-self-heal and entry-self-heal 啓用或禁用文件內容、文件元數據和目錄項的自我修復功能,默認狀況下三個所有是「on」。 #將其中的一個設置爲off的範例: gluster volume set gfs01 entry-self-heal off 4、glusterfs的缺點分析 參考學習鏈接:https://www.cnblogs.com/langren1992/p/5316328.html 不足之處,請多多指出!