1. 程式人生 > >GlusterFS分散式檔案系統使用簡介

GlusterFS分散式檔案系統使用簡介

0 術語簡介 GlusterFS是一個開源的分散式檔案系統。更多特性介紹附錄的參考文件。 Brick:GFS中的儲存單元,通過是一個受信儲存池中的伺服器的一個匯出目錄。可以通過主機名和目錄名來標識,如'SERVER:EXPORT' Client: 掛載了GFS卷的裝置 Extended Attributes:xattr是一個檔案系統的特性,其支援使用者或程式關聯檔案/目錄和元資料。 FUSE:Filesystem Userspace是一個可載入的核心模組,其支援非特權使用者建立自己的檔案系統而不需要修改核心程式碼。通過在使用者空間執行檔案系統的程式碼通過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的邏輯集合 1 Gluster安裝
[plain] view plain copy  print?
  1. #安裝依賴工具  
  2. yum install xfsprogs wget  
  3. yum install fuse fuse-libs  
  4. #格式化磁碟並建立GFS分割槽  
  5. fdisk /dev/sdb  
  6. mkfs.xfs -i size=512 /dev/sdb1  
  7. mount /dev/sdb1 /mnt/sdb1  
  8. #安裝gluster  
  9. wget http://download.gluster.org/pub/gluster/glusterfs/LATEST/CentOS/gluster-epel.repo -O /etc/yum.repo.d/glusterfs.repo  
  10. yum install glusterfs{,-server,-fuse,-geo-replication}  
  11. #啟動glusterfs  
  12. /etc/init.d/glusterd start  
  13. /etc/init.d/glusterd stop  
  14. #如果需要在系統啟動時開啟glusterd  
  15. chkconfig glusterd on  


2 cluster管理 在建立volume之前需要先將一組儲存裝置組成一個儲存池,通過儲存裝置提供的bricks來組成卷。 在裝置上啟動glusterd之後,可通過裝置的主機名或IP地址,將裝置加到儲存池中。 [plain] view plain
 copy  print?
  1. $gluster peer probe host|ip  
  2. $gluster peer status         #檢視除本機外的其他裝置狀態  
  3. $gluster peer detach host|ip #如果希望將某裝置從儲存池中刪除  


gluster對於每個節點都會生成一個UUID來標識,因此如果節點的IP或主機名發生了變化,只需要重新執行peer probe即可。不過如果一個主機名曾經用過,想再改回去,則gluster會提示已經儲存過。此時只能把節點detach掉,然後重新probe。 3 Volume管理 資料的傳輸協議支援tcp和infiniband rdma協議。 3.1 卷的型別 3.1.1 distributed volume
分佈卷可以將某個檔案隨機的儲存在卷內的一個brick內,通常用於擴充套件儲存能力,不支援資料的冗餘。除非底層的brick使用RAID等外部的冗餘措施。 [plain] view plain copy  print?
  1. $gluster volume create mamm-volume node1:/media node2:/media node3:/media ...  


3.1.2 replicated volume
複本卷在建立時可指定複本的數量,複本在儲存時會在卷的不同brick上,因此有幾個複本就必須提供至少多個brick。 [plain] view plain copy  print?
  1. $gluster volume create mamm-volume repl 2  node1:/media node2:/media  


注意:在建立複本卷時,brick數量與複本個數必須相等;否則將會報錯。 另外如果同一個節點提供了多個brick,也可以在同一個結點上建立複本卷,但這並不安全,因為一臺裝置掛掉,其上面的所有brick就無法訪問了。 3.1.3 striped volume
分片卷將單個檔案分成小塊(塊大小支援配置,預設為128K),然後將小塊儲存在不同的brick上,以提升檔案的訪問效能。 [plain] view plain copy  print?
  1. $gluster volume create mamm-volume stripe 2 node1:/media node2:/media  


stripe後的引數指明切片的分佈位置個數 注意:brick的個數必須等於分佈位置的個數 3.1.4 distribute replication volume
此型別卷是基本複本卷的擴充套件,可以指定若干brick組成一個複本卷,另外若干brick組成另個複本卷。單個檔案在複本卷內資料保持複製,不同檔案在不同複本卷之間進行分佈。 [plain] view plain copy  print?
  1. $gluster volume create dr-volume repl 2 node1:/exp1 node2:/exp2 node3:/exp3 node4:/exp4  


注意: 複本卷的組成依賴於指定brick的順序 brick必須為複本數K的N倍,brick列表將以K個為一組,形成N個複本卷 3.1.5 distribute striped volume
類似於分散式複本卷, 若建立的卷的節點提供的bricks個數為stripe個數N倍時,將建立此型別的卷。 [plain] view plain copy  print?
  1. $gluster volume create ds-volume stripe 2 node1:/exp1 node1:/exp2 [&] node2:/exp3 node2:/exp4  


注意: 切片卷的組成依賴於指定brick的順序 brick必須為複本數K的N倍,brick列表將以K個為一組,形成N個切片卷 3.1.6 striped replicated volume
資料將進行切片,切片在複本卷內進行復制,在不同卷間進行分佈。
[plain] view plain copy  print?
  1. $gluster volume create test-volume stripe 2 replica 2 server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4  


exp1和exp2組成複本卷,exp3和exp4組成複本卷,兩個複本卷組成分片卷。 注意:brick數量必須和stripe個數N和repl引數M的積N*M相等。即對於brick列表,將以M為一組,形成N個切片卷。資料切片分佈在N個切片捲上,在每個切片卷內部,切片資料複本M份。
3.1.7 distributed striped replicated vlume
[plain] view plain copy  print?
  1. $gluster volume create test-volume stripe 2 replica 2 server1:/exp1 server2:/exp2 server3:/exp3 server4:/exp4 server5:/exp5 server6:/exp6 server7:/exp7 server8:/exp8  


注意:bricks數量為stripe個數N,和repl個數M的積N*M的整數倍 exp1 exp2 exp3 exp4組成一個分佈卷,exp1和exp2組成一個stripe卷,exp3和exp4組成另一個stripe卷,1和2,3和4互為複本卷 exp4-exp8組成另一個分佈卷,略。 3.2 啟/停/刪除卷 [plain] view plain copy  print?
  1. $gluster volume start mamm-volume  
  2. $gluster volume stop mamm-volume  
  3. $gluster volume delete mamm-volume  


3.3 擴充套件收縮卷 [plain] view plain copy  print?
  1. $gluster volume add-brick mamm-volume [strip|repli <count>] brick1...  
  2. $gluster volume remove-brick mamm-volume [repl <count>] brick1...  


擴充套件或收縮卷時,也要按照卷的型別,加入或減少的brick個數必須滿足相應的要求。

3.4 遷移卷 主要完成資料在卷之間的線上遷移 [plain] view plain copy  print?
  1. gluster volume replace-brick mamm-volume old-brick new-brick [start|pause|abort|status|commit]  
  2. #遷移需要完成一系列的事務,假如我們準備將mamm卷中的brick3替換為brick5  
  3. #啟動遷移過程  
  4. $gluster volume replace-brick mamm-volume node3:/exp3 node5:/exp5 start  
  5. #暫停遷移過程  
  6. $gluster volume replace-brick mamm-volume node3:/exp3 node5:/exp5 pause  
  7. #中止遷移過程  
  8. $gluster volume replace-brick mamm-volume node3:/exp3 node5:/exp5 abort  
  9. #檢視遷移狀態  
  10. $gluster volume replace-brick mamm-volume node3:/exp3 node5:/exp5 status  
  11. #遷移完成後提交完成  
  12. $gluster volume replace-brick mamm-volume node3:/exp3 node5:/exp5 commit  


3.5 均衡卷 當對捲進行了擴充套件或收縮後,需要對卷的資料進行重新均衡。 [plain] view plain copy  print?
  1. $gluster volume rebalane mamm-volume start|stop|status  


3.6 觸發副本自愈 [plain] view plain copy  print?
  1. $gluster volume heal mamm-volume #只修復有問題的檔案  
  2. $gluster volume heal mamm-volume full #修復所有檔案  
  3. $gluster volume heal mamm-volume info#檢視自愈詳情  
  4. $gluster volume heal mamm-volume info healed|heal-failed|split-brain  


3.7 選項配置 [plain] view plain copy  print?
  1. $gluster volume set mamm-volume key value  

詳細的可設定選項: 4 排錯 4.1 錯誤 gluster使用了若干埠,如果出現probe peer或資料無法同步,考慮iptables對應用的影響。 4.2 日誌 $gluster volume log rotate mamm-vol  #實現日誌rotate 4.3 添加捲提示已經路徑已在卷中的錯誤 執行下面的指令碼,清除歷史資料及屬性資訊 [plain] view plain copy  print?
  1. path=$1 #引數為待新增目錄絕對路徑  
  2. rm -rf $path/.glu*  
  3. setfattr -x trusted.glusterfs.volume-id $path  
  4. setfattr -x trusted.gfid $path  


4.4 添加捲連線失敗 每次向卷中新增brick後,遠端的glusterd程序可能會連線關閉一段時間。此時現次執行操作會提示連線失敗。等一會再執行即可。 5 客戶端設定 客戶端使用GFS有多種方式,效能最高的方式是使用gluster的native介面,此外還有NFS和CIFS方式。 5.1 native方式 1 安裝gluserfs-fuse安裝包, 2 掛載卷:mount -t glusterfs host/ip:path mnt-point  注意,這裡提供的IP和主機只用來為客戶提供volfile資訊,後續客戶便直接和需要的伺服器通訊了。 3 設定自動掛載 echo "localhost:/mamm-vol /mnt/glusterfs glusterfs defaults,_netdev 0 0" >>/etc/fstab 5.2 NFS方式 Gluster提供了內建的NFS服務,支援其他實現了NFSv3的客戶端直接訪問。 [plain] view plain copy  print?
  1. #service nfs stop       # 關閉Linux核心自帶的NFS服務  
  2. #service rpcbind start  # 啟動rpc埠對映管理  
  3. #rpc.statd  
然後客戶端掛載 [plain] view plain copy  print?
  1. mount -t nfs -o vers=3 host/ip:/path mnt-port  


window7客戶端 程式和功能->開啟或關閉windows功能,安裝NFS客戶端功能,即可使用mount/showmount功能。 5.3 CIFS方式 cifs可以提供給WIN及samba客戶端訪問,對於windows程式,可以使用//ip/path通過SMB協議來方便的使用遠端資源 1 在伺服器將glu