分散式儲存glusterfs 安裝和使用(一)
glusterfs
GlusterFS是一個可伸縮的網路檔案系統,使用常見的現成的硬體,您可以建立大型分散式儲存流媒體解決方案、資料分析、和其他資料相關的任務。GlusterFS是自由和開源軟體。
詳細參考官網: ofollow,noindex">gluster
資源定義
- Brick: 儲存的基本單元,表現為伺服器上可信儲存池的匯出目錄
- Volume: 卷是bricks的邏輯集合
- Cluster: 一組計算機組成的叢集
- Distributed File System: 允許多個客戶端通過網路併發訪問的檔案系統
- GFID: 每個GlusterFs中的檔案或者目錄都有一個128bit的數字標識稱為GFID
- glusterd: 管理守護程序需要執行在所有的提供授信儲存池的伺服器上
- Namespace: 名稱空間是被建立的一個抽象容器或環境用來儲存唯一識別符號號
- Quorum: 設定一個可信的儲存池中最多失效的主機節點數量
- Quota: 允許通過目錄或者卷設定對磁碟空間使用的限制
- Posix: 可移植作業系統介面是IEEE定義的一系列相關api標準
- Vol File: Vol檔案是glusterfs程序使用的配置檔案
- Distributed: 分佈卷
- Replicated: 複本卷
- Distributed Replicated: 分散式複製卷
- Geo-Replication: 異地備份為站點通過區域網、廣域網、網際網路提供一個連續的非同步的和增量複製服務
- Metedata: 元資料定義為關於資料的資料描述資訊,在GlusterFs沒有專用的元資料儲存內容
- Extended Attributes: 擴充套件屬性是檔案系統的一個特性
FUSE: 使用者空間的檔案系統是一個用於類Unix作業系統的可載入核心模組,以允許非特權使用者在適用核心程式碼的情況下建立自己的檔案系統。實現了在使用者空間下執行檔案系統程式碼
環境基礎
10.1.1.11c6-vm1centos6.6glusterfs-3.10 第二塊硬碟10G 10.1.1.12c6-vm2centos6.6glusterfs-3.10 第二塊硬碟10G 10.1.1.13c6-vm3centos6.6client
yum 倉庫安裝
[root@c6-vm1 yum.repos.d]# cat glusterfs.repo [glusterfs] name=glusterfs baseurl=http://buildlogs.centos.org/centos/6/storage/x86_64/gluster-3.10/ enabled=1 gpgcheck=0 [debuginfo] name=glusterfs debuginfo baseurl=http://debuginfo.centos.org/centos/6/storage/x86_64/ enabled=1 gpgcheck=0
install
yuminstall -y glusterfs-server glusterfs-cli glusterfs-geo-replication
啟動程式加入開啟自啟動
[root@c6-vm1]# /etc/init.d/glusterd start [root@c6-vm1 ~]# chkconfig glusterd on
儲存主機加入信任儲存池
# 在其餘主機新增除自己之外的主機就可以 [root@c6-vm1]#gluster peer probe c6-vm2 peer probe: success.
檢視狀態
[root@c6-vm1 ~]# gluster peer status Number of Peers: 1 Hostname: c6-vm2 Uuid: 60eac2bb-ae30-4c3d-8c14-b93a3cb0ad98 State: Peer in Cluster (Connected)
磁碟分割槽
fdisk -l 檢視磁碟塊裝置,可以看到/dev/sdb 第二塊新硬碟
[root@c6-vm1 ~]# fdisk -l Disk /dev/sda: 37.6 GB, 37580963840 bytes 255 heads, 63 sectors/track, 4568 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000f1817 Device BootStartEndBlocksIdSystem /dev/sda1*12620480083Linux Partition 1 does not end on cylinder boundary. /dev/sda22638513072000083Linux /dev/sda338514569577433682Linux swap / Solaris Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
注:mkfs支援的分割槽型別有限,且最大隻支援16TB;當分割槽大於4T時,fdisk不適用,推薦用parted分割槽
# fdisk 分割槽操作 在二臺機器上分別執行 # fdisk/dev/vdb => n => p => 1 => 回車 => w(w為儲存、m為幫助) [root@c6-vm1 ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xf2a1a3ec. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action eextended pprimary partition (1-4) p Partition number (1-4): 1 First cylinder (1-1305, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): Using default value 1305 [root@c6-vm1 ~]# mkfs.ext4/dev/sdb1
# 在二臺機器上分別執行 建立掛載塊裝置的目錄並掛載加入fstab中 [root@c6-vm1 ~]# mkdir /data/gfs1 [root@c6-vm1 ~]# mount /dev/sdb1/data/gfs1 [root@c6-vm1 ~]# mount -a [root@c6-vm1 ~]# df -h FilesystemSizeUsed Avail Use% Mounted on /dev/sda229G874M27G4% / tmpfs358M0358M0% /dev/shm /dev/sda1190M25M156M14% /boot /dev/sdb19.8G23M9.2G1% /data/gfs1 [root@c6-vm1 ~]# echo "/dev/sdb1/data/gfs1 ext4 defaults 1 2" >> /etc/fstab
公司如果有raid卡,可以在底層做一層raid5提高IO效能,再在上頭做GlusterFS。當然沒有raid卡直接做GlusterFS也沒事
建立volume
Distributed:分散式卷,檔案通過hash演算法隨機的分佈到由bricks組成的捲上。 Replicated:複製式卷,類似raid1,replica數必須等於volume中brick所包含的儲存伺服器數,可用性高。 Striped:條帶式卷,類似與raid0,stripe數必須等於volume中brick所包含的儲存伺服器數,檔案被分成資料塊,以Round Robin的方式儲存在bricks中,併發粒度是資料塊,大檔案效能好。 Distributed Striped:分散式的條帶卷,volume中brick所包含的儲存伺服器數必須是stripe的倍數(>=2倍),兼顧分散式和條帶式的功能。 Distributed Replicated:分散式的複製卷,volume中brick所包含的儲存伺服器數必須是 replica 的倍數(>=2倍),兼顧分散式和複製式的功能。
建立複製卷
[root@c6-vm1 ~]# gluster volume create gv2replica 2 c6-vm1:/data/gfs1 c6-vm2:/data/gfs1 force volume create: gv2: success: please start the volume to access data [root@c6-vm1 ~]# gluster volume info Volume Name: gv2 Type: Replicate Volume ID: fa64409f-814b-4191-b9e4-8c317bf63a94 Status: Created#這裡狀態表示剛剛被建立但是還沒有啟動 Snapshot Count: 0 Number of Bricks: 1 x 2 = 2 Transport-type: tcp Bricks: Brick1: c6-vm1:/data/gfs1 Brick2: c6-vm2:/data/gfs1 Options Reconfigured: transport.address-family: inet nfs.disable: on
start volume
[root@c6-vm1 gfs1]#gluster volume start gv2 volume start: gv2: success [root@c6-vm1 gfs1]# gluster volume info Volume Name: gv2 Type: Replicate Volume ID: fa64409f-814b-4191-b9e4-8c317bf63a94 Status: Started#啟動後狀態變成start Snapshot Count: 0 Number of Bricks: 1 x 2 = 2 Transport-type: tcp Bricks: Brick1: c6-vm1:/data/gfs1 Brick2: c6-vm2:/data/gfs1 Options Reconfigured: transport.address-family: inet nfs.disable: off
客戶端掛載
c6-vm3
yum glusterfs
yum install -y glusterfs gluster-fuse
glusterfs 方式掛載
[root@c6-vm3 yum.repos.d]# mount -t glusterfs c6-vm1:/gv2 /mnt [root@c6-vm3 mnt]# df -h FilesystemSizeUsed Avail Use% Mounted on /dev/sda229G923M27G4% / tmpfs358M0358M0% /dev/shm /dev/sda1190M25M156M14% /boot c6-vm1:/gv29.8G23M9.2G1% /mnt
nfs 方式掛載
[root@c6-vm2 gfs1]# mount -t nfs -o mountproto=tcp,vers=3 c6-vm2:gv2/mnt/ [root@c6-vm2 gfs1]# df -h FilesystemSizeUsed Avail Use% Mounted on /dev/sda229G875M27G4% / tmpfs358M0358M0% /dev/shm /dev/sda1190M25M156M14% /boot /dev/sdb19.8G23M9.2G1% /data/gfs1 c6-vm2:gv29.8G33M14G1% /mnt
# 建立檔案 [root@c6-vm3 mnt]# cd /mnt/ [root@c6-vm3 mnt]# touch file{1..10}
在儲存端驗證
c6-vm1
[root@c6-vm1 gfs1]# ls file1file10file2file3file4file5file6file7file8file9lost+found
c6-vm2
[root@c6-vm2 gfs1]# ls file1file10file2file3file4file5file6file7file8file9lost+found
status
[root@c6-vm1 gfs1]#gluster volume status gv2 Status of volume: gv2 Gluster processTCP PortRDMA PortOnlinePid ------------------------------------------------------------------------------ Brick c6-vm1:/data/gfs1491520Y1976 Brick c6-vm2:/data/gfs1491520Y1883 NFS Server on localhost20490Y1996 Self-heal Daemon on localhostN/AN/AY2007 NFS Server on c6-vm220490Y1903 Self-heal Daemon on c6-vm2N/AN/AY1914 Task Status of Volume gv2 ------------------------------------------------------------------------------ There are no active volume task
故障演練
把c6-vm1關機
因為我們之前在c6-vm3(client)端mount掛載的時候指定的是c6-vm1主機
當我們把c6-vm1關機,觀察後面的情況是怎麼樣

-w935
檢視volume狀態

-w808
在c6-vm3上操作 明顯沒有問題
注意: 當c6-vm1關機的時候,在ls該目錄會有短暫時間的延遲卡主的現象

-w1006
在去c6-vm2上看檔案狀態
新建的bds已經有了,刪除的file0也沒有刪除成功

-w1051
現在我們嘗試開機c6-vm1
發現檔案系統報錯了,完了這個機器成功被我們弄壞了 修復吧

-w804
可以看到我們進入了 只讀檔案系統中 根本註釋不了這行

-w855
解決辦法重新掛載
# 根系統重新掛載 救命的命令啊 mount -o remount rw /

image
下圖可以看到 我們已經把有問題那行 註釋掉了 然後reboot

image
登入c6-vm1
[root@c6-vm1 gfs1]# mount /dev/sdb1 /data/gfs1/ [root@c6-vm1 gfs1]# gluster volume status Status of volume: gv2 Gluster processTCP PortRDMA PortOnlinePid ------------------------------------------------------------------------------ Brick c6-vm1:/data/gfs1N/AN/ANN/A Brick c6-vm2:/data/gfs1491520Y1883 NFS Server on localhost20490Y1082 Self-heal Daemon on localhostN/AN/AY1146 NFS Server on c6-vm220490Y1903 Self-heal Daemon on c6-vm2N/AN/AY1914 Task Status of Volume gv2 ------------------------------------------------------------------------------ There are no active volume tasks
在正常的節點c6-vm2 執行命令檢視資訊
[root@c6-vm2 gfs1]# getfattr -d -m '.*' /data/gfs1/ getfattr: Removing leading '/' from absolute path names # file: data/gfs1/ trusted.afr.dirty=0sAAAAAAAAAAAAAAAA trusted.afr.gv2-client-0=0sAAAAAAAAAAAAAAAD trusted.gfid=0sAAAAAAAAAAAAAAAAAAAAAQ== trusted.glusterfs.dht=0sAAAAAQAAAAAAAAAA/////w== trusted.glusterfs.volume-id=0s+mRAn4FLQZG55Iwxe/Y6lA==
在機器關機的c6-vm1節點上進行set寫入
[root@c6-vm1 gfs1]# setfattr -n trusted.glusterfs.volume-id -v 0s+mRAn4FLQZG55Iwxe/Y6lA== /data/gfs1/ [root@c6-vm1 gfs1]# setfattr -n trusted.glusterfs.volume-id -v 0s+mRAn4FLQZG55Iwxe/Y6lA== /data/gfs1/ [root@c6-vm1 gfs1]# setfattr -n trusted.gfid -v 0sAAAAAAAAAAAAAAAAAAAAAQ== /data/gfs1/ [root@c6-vm1 gfs1]# setfattr -n trusted.afr.dirty -v 0sAAAAAAAAAAAAAAAA/data/gfs1/ [root@c6-vm1 gfs1]# setfattr -n trusted.glusterfs.dht -v 0sAAAAAQAAAAAAAAAA/////w== /data/gfs1/
重啟glusterfs
[root@c6-vm1 gfs1]# /etc/init.d/glusterd restart Stopping glusterd:[確定] Starting glusterd:[確定]
重啟完成之後,根據資料的大小,等待片刻,則同步完成 觀察下面目錄變化
[root@c6-vm1 gfs1]# ll 總用量 32 -rw-r--r-- 2 root root5 10月9 23:08 a -rw-r--r-- 2 root root29 10月9 19:53 a.txt -rw-r--r-- 2 root root0 10月2 13:29 ba -rw-r--r-- 2 root root0 10月2 12:54 file1 -rw-r--r-- 2 root root0 10月2 12:54 file10 -rw-r--r-- 2 root root5 10月9 19:14 file2 -rw-r--r-- 2 root root0 10月2 12:54 file3 -rw-r--r-- 2 root root0 10月2 12:54 file4 -rw-r--r-- 2 root root0 10月2 12:54 file5 -rw-r--r-- 2 root root0 10月2 12:54 file6 -rw-r--r-- 2 root root0 10月2 12:54 file7 -rw-r--r-- 2 root root0 10月2 12:54 file8 -rw-r--r-- 2 root root0 10月2 12:54 file9 drwx------ 2 root root 16384 10月9 03:12 lost+found
這個目錄裡面儲存一些同步資訊
[root@c6-vm1 gfs1]# cd .glusterfs/ [root@c6-vm1 .glusterfs]# ls 001c313e3f464c56648289a3c7changelogsebgfs1.dbhealth_checkindiceslandfillquanrantineunlink [root@c6-vm1 .glusterfs]# ll 總用量 100 drwx------ 3 root root4096 10月9 23:06 00 drwx------ 3 root root4096 10月9 23:08 1c drwx------ 3 root root4096 10月9 23:08 31 drwx------ 3 root root4096 10月9 23:08 3e drwx------ 3 root root4096 10月9 23:08 3f drwx------ 3 root root4096 10月9 23:08 46 drwx------ 3 root root4096 10月9 23:08 4c drwx------ 3 root root4096 10月9 23:07 56 drwx------ 3 root root4096 10月9 23:08 64 drwx------ 3 root root4096 10月9 23:08 82 drwx------ 3 root root4096 10月9 23:08 89 drwx------ 3 root root4096 10月9 23:08 a3 drwx------ 4 root root4096 10月9 23:08 c7 drw------- 4 root root4096 10月9 22:30 changelogs drwx------ 3 root root4096 10月9 23:08 eb -rw-r--r-- 1 root root 20480 10月9 22:30 gfs1.db -rw-r--r-- 1 root root19 10月9 23:17 health_check drw------- 5 root root4096 10月9 22:30 indices drwxr-xr-x 2 root root4096 10月9 23:06 landfill drw------- 2 root root4096 10月9 22:30 quanrantine drw------- 2 root root4096 10月9 23:06 unlink
同步後的目錄 與正常節點c6-vm2目錄保持一致了
[root@c6-vm1 .glusterfs]# cd .. [root@c6-vm1 gfs1]# ls bdsfile1file10file2file3file4file5file6file7file8file9lost+found [root@c6-vm1 gfs1]# ll 總用量 24 -rw-r--r-- 2 root root8 10月9 23:21 bds -rw-r--r-- 2 root root0 10月2 12:54 file1 -rw-r--r-- 2 root root0 10月2 12:54 file10 -rw-r--r-- 2 root root5 10月9 19:14 file2 -rw-r--r-- 2 root root0 10月2 12:54 file3 -rw-r--r-- 2 root root0 10月2 12:54 file4 -rw-r--r-- 2 root root0 10月2 12:54 file5 -rw-r--r-- 2 root root0 10月2 12:54 file6 -rw-r--r-- 2 root root0 10月2 12:54 file7 -rw-r--r-- 2 root root0 10月2 12:54 file8 -rw-r--r-- 2 root root0 10月2 12:54 file9 drwx------ 2 root root 16384 10月9 03:12 lost+found