一、GlusterFS簡述
分佈式文件系統(Distributed File System)是指文件系統管理的物理存儲資源並不直接與本地節點相連,而是分佈於計算網絡中的一個或者多個節點的計算機上。目前意義上的分佈式文件系統大多都是由多個節點計算機構成,結構上是典型的客戶機/服務器模式。流行的模式是當客戶機須要存儲數據時,服務器指引其將數據分散的存儲到多個存儲節點上,以提供更快的速度,更大的容量及更好的冗餘特性。GlusterFS系統是一個可擴展的網絡文件系統,相比其餘分佈式文件系統,GlusterFS具備高擴展性、高可用性、高性能、可橫向擴展等特色,而且其沒有元數據服務器的設計,讓整個服務沒有單點故障的隱患。node
術語:linux
Brick:GFS中的存儲單元,經過是一個受信存儲池中的服務器的一個導出目錄。能夠經過主機名和目錄名來標識,如‘SERVER:EXPORT‘算法
Client:掛載了GFS卷的設備vim
Extended Attributes:xattr是一個文件系統的特性,其支持用戶或程序關聯文件/目錄和元數據。centos
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的邏輯集合
a、無元數據設計
元數據是用來描述一個文件或給定區塊在分佈式文件系統中所在的位置,簡而言之就是某個文件或某個區塊存儲的位置。傳統分佈式文件系統大都會設置元數據服務器或者功能相近的管理服務器,主要做用就是用來管理文件與數據區塊之間的存儲位置關係。相較其餘分佈式文件系統而言,GlusterFS並無集中或者分佈式的元數據的概念,取而代之的是彈性哈希算法。集羣中的任何服務器和客戶端均可以利用哈希算法、路徑及文件名進行計算,就能夠對數據進行定位,並執行讀寫訪問操做。
這種設計帶來的好處是極大的提升了擴展性,同時也提升了系統的性能和可靠性;另外一顯著的特色是若是給定肯定的文件名,查找文件位置會很是快。可是若是要列出文件或者目錄,性能會大幅降低,由於列出文件或者目錄時,須要查詢所在節點並對各節點中的信息進行聚合。此時有元數據服務的分佈式文件系統的查詢效率反而會提升許多。
b、服務器間的部署
在以前的版本中服務器間的關係是對等的,也就是說每一個節點服務器都掌握了集羣的配置信息,這樣作的好處是每一個節點度擁有節點的配置信息,高度自治,全部信息均可以在本地查詢。每一個節點的信息更新都會向其餘節點通告,保證節點間信息的一致性。但若是集羣規模較大,節點衆多時,信息同步的效率就會降低,節點信息的非一致性機率就會大大提升。所以GlusterFS將來的版本有向集中式管理變化的趨勢。
二、訪問流程
Glusterfs基於內核的fuse模塊,fuse模塊除了建立fuse文件系統外,還提供了一個字符設備(/dev/fuse),經過這個字符設備,Glusterfs能夠讀取請求,併發送響應,而且能夠發送notify消息。
下面是在Glusterfs下的一個讀/寫請求的完整流程:
過程說明:
藍實線表示一個請求經過系統調用到VFS,而後經由Fuse封裝爲一個req併發送到等待隊列,而後喚醒在該等待隊列上阻塞的Glusterfs讀進程,讀取請求
綠虛線表示Glusterfsd進程讀取請求後,處理請求的過程
紅虛線表示Glusterfs處理完請求後,封裝響應消息並將消息發送到/dev/fuse下,並喚醒相應的請求進程(請求進程在將請求發送後,一直阻塞,直到該請求收到響應並處理完成)。
請求進程被喚醒後,將Glusterfs封裝的響應信息返回給用戶。
爲方便說明問題,下圖是一個讀請求走到Fuse的完整流程:
下面是上面這些步驟的說明:
①read系統調用,陷入到內核
②vfs經過fd及當前進程維護的打開的文件表找到fd對應的file,而後調用該file被賦值的read函數進行讀操做
③由於該file是基於fuse文件系統建立的,所以調用fuse的read函數do_sync_read
④-1.最終調用do_generic_file_read基於讀操做的偏移量及該文件的緩存樹查找該對應的緩存頁,該緩存頁存在且是最新的,直接從該緩存中讀數據給用戶
④-2.若是該緩存頁不存在,則申請一個頁做爲緩存。並調用readpage去讀數據。fuse的readpage會封裝一個請求到字符設備的等待隊列中。收到glusterfs的響應後會將響應寫到緩存中並返回
分佈(distributed)
複製(replicate)
條帶(striped)
(1) distribute volume:分佈式卷
(2) stripe volume:條帶卷
(3) replica volume:複製卷
複合卷:
(4) distribute stripe volume:分佈式條帶卷
(5) distribute replica volume:分佈式複製卷
(6) stripe replica volume:條帶複製卷
(7) distribute stripe replicavolume:分佈式條帶複製卷
三、實驗環境及規劃:
操做系統 | IP地址 | 主機名 | 硬盤數量(3塊) | 角色 |
CentOS7.2 | 192.168.0.51 | node01 | sdb:10G sdc:10G sdd:10G | 存儲節點 |
CentOS7.2 | 192.168.0.52 | node02 | sdb:10G sdc:10G sdd:10G | 存儲節點 |
CentOS7.2 | 192.168.0.53 | node03 | sdb:10G sdc:10G sdd:10G | 存儲節點 |
CentOS7.2 | 192.168.0.54 | node04 | sdb:10G sdc:10G sdd:10G | 存儲節點 |
CentOS7.2 | 192.168.0.55 | node05 | sdb:10G sdc:10G sdd:10G | 存儲節點 |
CentOS7.2 | 192.168.0.56 | node06 | sdb:10G sdc:10G sdd:10G | 存儲節點 |
CentOS7.2 | 192.168.0.57 | node07 | sda:100G | 客戶端 |
3.1 關閉防火牆:
systemctl stop firewalld
systemctl disable firewalld
3.2 關閉selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
3.3 同步時間
yum install chrony -y
systemctl enable chronyd.service
systemctl start chronyd.service
3.4 主機名解析
192.168.0.51 node01
192.168.0.52 node02
192.168.0.53 node03
192.168.0.54 node04
192.168.0.55 node05
192.168.0.56 node06
192.168.0.57 node07
3.5 安裝epel源
yum install http://mirrors.163.com/centos/7/extras/x86_64/Packages/epel-release-7-9.noarch.rpm -y
配置yum源
vim /etc/yum.repos.d/gluster.repo
[gluster]
name=gluster
baseurl=https://buildlogs.centos.org/centos/7/storage/x86_64/gluster-3.8/
gpgcheck=0
enabled=1
3.6 安裝gluster主服務及輔助包
yum install -y glusterfs-server samba rpcbind
systemctl start glusterd.service
systemctl enable glusterd.service
systemctl start rpcbind
systemctl enable rpcbind
systemctl status rpcbind
以上操做3.1~3.6操做在node01---node06上同時操做,並確保生效
四、gluster基本操做
4.1 經常使用命令
gluster help volume info [all|<VOLNAME>] - list information of all volumes volume create <NEW-VOLNAME> [stripe <COUNT>] [replica <COUNT> [arbiter <COUNT>]] [disperse [<COUNT>]] [disperse-data <COUNT>] [redundancy <COUNT>] [transport <tcp|rdma|tcp,rdma>] <NEW-BRICK>?<vg_name>... [force] - create a new volume of specified type with mentioned bricks volume delete <VOLNAME> - delete volume specified by <VOLNAME> volume start <VOLNAME> [force] - start volume specified by <VOLNAME> volume stop <VOLNAME> [force] - stop volume specified by <VOLNAME> volume tier <VOLNAME> status volume tier <VOLNAME> start [force] volume tier <VOLNAME> attach [<replica COUNT>] <NEW-BRICK>... volume tier <VOLNAME> detach <start|stop|status|commit|[force]> - Tier translator specific operations. volume attach-tier <VOLNAME> [<replica COUNT>] <NEW-BRICK>... - NOTE: this is old syntax, will be depreciated in next release. Please use gluster volume tier <vol> attach [<replica COUNT>] <NEW-BRICK>... volume detach-tier <VOLNAME> <start|stop|status|commit|force> - NOTE: this is old syntax, will be depreciated in next release. Please use gluster volume tier <vol> detach {start|stop|commit} [force] volume add-brick <VOLNAME> [<stripe|replica> <COUNT> [arbiter <COUNT>]] <NEW-BRICK> ... [force] - add brick to volume <VOLNAME> volume remove-brick <VOLNAME> [replica <COUNT>] <BRICK> ... <start|stop|status|commit|force> - remove brick from volume <VOLNAME> volume rebalance <VOLNAME> {{fix-layout start} | {start [force]|stop|status}} - rebalance operations volume replace-brick <VOLNAME> <SOURCE-BRICK> <NEW-BRICK> {commit force} - replace-brick operations volume set <VOLNAME> <KEY> <VALUE> - set options for volume <VOLNAME> volume help - display help for the volume command volume log <VOLNAME> rotate [BRICK] - rotate the log file for corresponding volume/brick volume log rotate <VOLNAME> [BRICK] - rotate the log file for corresponding volume/brick NOTE: This is an old syntax, will be deprecated from next release. volume sync <HOSTNAME> [all|<VOLNAME>] - sync the volume information from a peer volume reset <VOLNAME> [option] [force] - reset all the reconfigured options volume profile <VOLNAME> {start|info [peek|incremental [peek]|cumulative|clear]|stop} [nfs] - volume profile operations volume quota <VOLNAME> {enable|disable|list [<path> ...]| list-objects [<path> ...] | remove <path>| remove-objects <path> | default-soft-limit <percent>} | volume quota <VOLNAME> {limit-usage <path> <size> [<percent>]} | volume quota <VOLNAME> {limit-objects <path> <number> [<percent>]} | volume quota <VOLNAME> {alert-time|soft-timeout|hard-timeout} {<time>} - quota translator specific operations volume inode-quota <VOLNAME> enable - quota translator specific operations volume top <VOLNAME> {open|read|write|opendir|readdir|clear} [nfs|brick <brick>] [list-cnt <value>] | volume top <VOLNAME> {read-perf|write-perf} [bs <size> count <count>] [brick <brick>] [list-cnt <value>] - volume top operations volume status [all | <VOLNAME> [nfs|shd|<BRICK>|quotad]] [detail|clients|mem|inode|fd|callpool|tasks] - display status of all or specified volume(s)/brick volume heal <VOLNAME> [enable | disable | full |statistics [heal-count [replica <HOSTNAME:BRICKNAME>]] |info [healed | heal-failed | split-brain] |split-brain {bigger-file <FILE> | latest-mtime <FILE> |source-brick <HOSTNAME:BRICKNAME> [<FILE>]} |granular-entry-heal {enable | disable}] - self-heal commands on volume specified by <VOLNAME> volume statedump <VOLNAME> [nfs|quotad] [all|mem|iobuf|callpool|priv|fd|inode|history]... - perform statedump on bricks volume list - list all volumes in cluster volume clear-locks <VOLNAME> <path> kind {blocked|granted|all}{inode [range]|entry [basename]|posix [range]} - Clear locks held on path volume barrier <VOLNAME> {enable|disable} - Barrier/unbarrier file operations on a volume volume get <VOLNAME> <key|all> - Get the value of the all options or given option for volume <VOLNAME> volume bitrot <VOLNAME> {enable|disable} | volume bitrot <volname> scrub-throttle {lazy|normal|aggressive} | volume bitrot <volname> scrub-frequency {hourly|daily|weekly|biweekly|monthly} | volume bitrot <volname> scrub {pause|resume|status} - Bitrot translator specific operation. For more information about bitrot command type 'man gluster' peer probe { <HOSTNAME> | <IP-address> } - probe peer specified by <HOSTNAME> peer detach { <HOSTNAME> | <IP-address> } [force] - detach peer specified by <HOSTNAME> peer status - list status of peers peer help - Help command for peer pool list - list all the nodes in the pool (including localhost) quit - quit help - display command options exit - exit snapshot help - display help for snapshot commands snapshot create <snapname> <volname> [no-timestamp] [description <description>] [force] - Snapshot Create. snapshot clone <clonename> <snapname> - Snapshot Clone. snapshot restore <snapname> - Snapshot Restore. snapshot status [(snapname | volume <volname>)] - Snapshot Status. snapshot info [(snapname | volume <volname>)] - Snapshot Info. snapshot list [volname] - Snapshot List. snapshot config [volname] ([snap-max-hard-limit <count>] [snap-max-soft-limit <percent>]) | ([auto-delete <enable|disable>])| ([activate-on-create <enable|disable>]) - Snapshot Config. snapshot delete (all | snapname | volume <volname>) - Snapshot Delete. snapshot activate <snapname> [force] - Activate snapshot volume. snapshot deactivate <snapname> - Deactivate snapshot volume. global help - list global commands nfs-ganesha {enable| disable} - Enable/disable NFS-Ganesha support
4.2 添加存儲節點到gluster池(任意一個存儲節點上操做都行,這裏在node01上,從node02開始,node01默認本身會添加)
命令:peer probe { <HOSTNAME> | <IP-address> } - probe peer specified by <HOSTNAME>
[root@node01 ~]# gluster peer probe node02 peer probe: success. [root@node01 ~]# gluster peer probe node03 peer probe: success. [root@node01 ~]# gluster peer probe node04 peer probe: success. [root@node01 ~]# gluster peer probe node05 peer probe: success. [root@node01 ~]# gluster peer probe node06 peer probe: success. [root@node01 ~]# gluster peer status Number of Peers: 5 Hostname: node02 Uuid: a6052b2f-7724-428b-a030-3372663c8896 State: Peer in Cluster (Connected) Hostname: node03 Uuid: df99aea5-24aa-4176-8b45-ecea75bbb34a State: Peer in Cluster (Connected) Hostname: node04 Uuid: 6baedfed-7132-421d-8227-b79b76339688 State: Peer in Cluster (Connected) Hostname: node05 Uuid: e6027a77-1b9a-4d58-bb7e-e3eb13c8b3d8 State: Peer in Cluster (Connected) Hostname: node06 Uuid: 85f56ce4-0a47-4934-bbe9-a5ebaabf3bc9 State: Peer in Cluster (Connected) [root@node01 ~]#
4.3 建立分佈式卷
[root@node01 ~]# gluster volume create dis_volume node01:/gluster/sdb/ds01 node02:/gluster/sdb/ds01 node03:/gluster/sdb/ds01 volume create: dis_volume: success: please start the volume to access data [root@node01 ~]# [root@node01 ~]# gluster volume info dis_volume Volume Name: dis_volume Type: Distribute Volume ID: 14670a39-4d6f-40c7-a7c4-4dde95faef8b Status: Created Snapshot Count: 0 Number of Bricks: 3 Transport-type: tcp Bricks: Brick1: node01:/gluster/sdb/ds01 Brick2: node02:/gluster/sdb/ds01 Brick3: node03:/gluster/sdb/ds01 Options Reconfigured: transport.address-family: inet performance.readdir-ahead: on nfs.disable: on [root@node01 ~]# [root@node01 ~]# gluster volume start dis_volume volume start: dis_volume: success [root@node01 ~]# gluster volume status dis_volume Status of volume: dis_volume Gluster process TCP Port RDMA Port Online Pid ------------------------------------------------------------------------------ Brick node01:/gluster/sdb/ds01 49152 0 Y 27346 Brick node02:/gluster/sdb/ds01 49152 0 Y 27055 Brick node03:/gluster/sdb/ds01 49152 0 Y 27132 Task Status of Volume dis_volume ------------------------------------------------------------------------------ There are no active volume tasks [root@node01 ~]#
4.3.1 掛在分佈式卷,進行寫入操做
[root@node07 ~]# mount -t glusterfs node01:/dis_volume /ds01 [root@node07 ~]# cd /ds01/ [root@node07 ds01]# ll total 0 [root@node07 ds01]# [root@node07 ds01]# for i in `seq 10`;do echo $i > $i.txt;done [root@node07 ds01]# [root@node07 ds01]# [root@node07 ds01]# ll total 5 -rw-r--r-- 1 root root 3 Jun 22 2018 10.txt -rw-r--r-- 1 root root 2 Jun 22 2018 1.txt -rw-r--r-- 1 root root 2 Jun 22 2018 2.txt -rw-r--r-- 1 root root 2 Jun 22 2018 3.txt -rw-r--r-- 1 root root 2 Jun 22 2018 4.txt -rw-r--r-- 1 root root 2 Jun 22 2018 5.txt -rw-r--r-- 1 root root 2 Jun 22 2018 6.txt -rw-r--r-- 1 root root 2 Jun 22 2018 7.txt -rw-r--r-- 1 root root 2 Jun 22 2018 8.txt -rw-r--r-- 1 root root 2 Jun 22 2018 9.txt [root@node07 ds01]# node0一、node0二、node03對應的目錄/gluster/sdb/ds01下查看文件分佈狀況: node01: [root@node01 ~]# cd /gluster/sdb/ds01/ [root@node01 ds01]# ls -l total 20 -rw-r--r-- 2 root root 3 Jun 22 07:20 10.txt -rw-r--r-- 2 root root 2 Jun 22 07:20 1.txt -rw-r--r-- 2 root root 2 Jun 22 07:20 2.txt -rw-r--r-- 2 root root 2 Jun 22 07:20 3.txt -rw-r--r-- 2 root root 2 Jun 22 07:20 6.txt [root@node01 ds01]# node02: [root@node02 ~]# cd /gluster/sdb/ds01/ [root@node02 ds01]# ls -l total 8 -rw-r--r-- 2 root root 2 Jun 22 07:20 4.txt -rw-r--r-- 2 root root 2 Jun 22 07:20 8.txt [root@node02 ds01]# node03: [root@node03 ~]# cd /gluster/sdb/ds01/ [root@node03 ds01]# ls -l total 12 -rw-r--r-- 2 root root 2 Jun 22 07:20 5.txt -rw-r--r-- 2 root root 2 Jun 22 07:20 7.txt -rw-r--r-- 2 root root 2 Jun 22 07:20 9.txt [root@node03 ds01]#
從上狀況下,node01上分佈的是一、二、三、六、10文件,node02分佈的是四、8文件,node03分佈的是五、七、9文件,從而說明分佈式卷,將文件分散到各個存儲節點上,
咱們演示下看下分佈式卷有沒有容錯功能,這裏假設node02節點宕機:
關閉node02,而後再node07上查看目錄/ds01下的文件:
關閉前node02前:
[root@node07 ds01]# ls -lh total 5.0K -rw-r--r-- 1 root root 3 Jun 22 07:20 10.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 1.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 2.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 3.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 4.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 5.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 6.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 7.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 8.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 9.txt [root@node07 ds01]#
關閉node02以後:
[root@node07 ds01]# pwd /ds01 [root@node07 ds01]# df -Th|grep ds01 node01:/dis_volume fuse.glusterfs 20G 65M 20G 1% /ds01 [root@node07 ds01]# [root@node07 ds01]# ls -lh total 4.0K -rw-r--r-- 1 root root 3 Jun 22 07:20 10.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 1.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 2.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 3.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 5.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 6.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 7.txt -rw-r--r-- 1 root root 2 Jun 22 07:20 9.txt [root@node07 ds01]#
到node01上查看集羣狀態:
[root@node01 ~]# gluster volume info all
Volume Name: dis_volume
Type: Distribute
Volume ID: 14670a39-4d6f-40c7-a7c4-4dde95faef8b
Status: Started
Snapshot Count: 0
Number of Bricks: 3
Transport-type: tcp
Bricks:
Brick1: node01:/gluster/sdb/ds01
Brick2: node02:/gluster/sdb/ds01
Brick3: node03:/gluster/sdb/ds01
Options Reconfigured:
nfs.disable: on
performance.readdir-ahead: on
transport.address-family: inet
[root@node01 ~]# gluster peer status
Number of Peers: 5
Hostname: node02
Uuid: a6052b2f-7724-428b-a030-3372663c8896
State: Peer in Cluster (Disconnected)
Hostname: node03
Uuid: df99aea5-24aa-4176-8b45-ecea75bbb34a
State: Peer in Cluster (Connected)
Hostname: node04
Uuid: 6baedfed-7132-421d-8227-b79b76339688
State: Peer in Cluster (Connected)
Hostname: node05
Uuid: e6027a77-1b9a-4d58-bb7e-e3eb13c8b3d8
State: Peer in Cluster (Connected)
Hostname: node06
Uuid: 85f56ce4-0a47-4934-bbe9-a5ebaabf3bc9
State: Peer in Cluster (Connected)
[root@node01 ~]#
從上述發現node02的狀態是Disconnected,node07的目錄/ds01下少了4.txt和8.txt文件,說明分佈式卷沒有容錯功能,可是丟失一個節點glusterfs集羣還能繼續使用,同時也說明了集羣無中心特性
另外分佈式卷空間分佈以下:
[root@node07 ds03]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 97G 1.6G 96G 2% /
devtmpfs devtmpfs 904M 0 904M 0% /dev
tmpfs tmpfs 913M 0 913M 0% /dev/shm
tmpfs tmpfs 913M 8.6M 904M 1% /run
tmpfs tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 125M 890M 13% /boot
tmpfs tmpfs 183M 0 183M 0% /run/user/0
node01:/dis_volume fuse.glusterfs 30G 98M 30G 1% /ds01
4.4 建立複製式卷
4.4,1操做過程以下:
[root@node01 ~]# gluster volume create rep_volume replica 3 node01:/gluster/sdb/rv2 node02:/gluster/sdb/rv2/ node03:/gluster/sdb/rv2 volume create: rep_volume: success: please start the volume to access data
[root@node01 ~]#
查看建立複製式卷狀態 [root@node01 ~]# gluster volume info rep_volume Volume Name: rep_volume Type: Replicate Volume ID: 65167369-9fbe-4bb9-a71a-6b4b7547ca2e Status: Created Snapshot Count: 0 Number of Bricks: 1 x 3 = 3 Transport-type: tcp Bricks: Brick1: node01:/gluster/sdb/rv2 Brick2: node02:/gluster/sdb/rv2 Brick3: node03:/gluster/sdb/rv2 Options Reconfigured: transport.address-family: inet performance.readdir-ahead: on nfs.disable: on
[root@node01 ~]
啓動複製式卷 [root@node01 ~]# gluster volume start rep_volume volume start: rep_volume: success [root@node01 ~]#
4.4.2 驗證複製式卷特性
複製式卷相似於RAID1,每一個存儲節點上的數據都是一致,任何一個節點損壞,數據不會丟失
[root@node07 ~]# mount -t glusterfs node01:/repo_volume /ds02/ [root@node07 ~]# cd /ds02/ 在目錄/ds02下建立測試文件 [root@node07 ds02]# for i in `seq 10`;do echo $i > $i.file;done [root@node07 ds02]# ll total 5 -rw-r--r-- 1 root root 3 Jul 6 07:50 10.file -rw-r--r-- 1 root root 2 Jul 6 07:50 1.file -rw-r--r-- 1 root root 2 Jul 6 07:50 2.file -rw-r--r-- 1 root root 2 Jul 6 07:50 3.file -rw-r--r-- 1 root root 2 Jul 6 07:50 4.file -rw-r--r-- 1 root root 2 Jul 6 07:50 5.file -rw-r--r-- 1 root root 2 Jul 6 07:50 6.file -rw-r--r-- 1 root root 2 Jul 6 07:50 7.file -rw-r--r-- 1 root root 2 Jul 6 07:50 8.file -rw-r--r-- 1 root root 2 Jul 6 07:50 9.file [root@node07 ds02]#
複製式卷用到節點的目錄爲:node01/gluster/sdb/rv二、node02/gluster/sdb/rv二、node03/gluster/sdb/rv2,查看各個節點所在目錄中的文件:
node01: [root@node01 ~]# cd /gluster/sdb/rv2 [root@node01 rv2]# ls -lh total 40K -rw-r--r-- 2 root root 3 Jul 5 23:04 10.file -rw-r--r-- 2 root root 2 Jul 5 23:04 1.file -rw-r--r-- 2 root root 2 Jul 5 23:04 2.file -rw-r--r-- 2 root root 2 Jul 5 23:04 3.file -rw-r--r-- 2 root root 2 Jul 5 23:04 4.file -rw-r--r-- 2 root root 2 Jul 5 23:04 5.file -rw-r--r-- 2 root root 2 Jul 5 23:04 6.file -rw-r--r-- 2 root root 2 Jul 5 23:04 7.file -rw-r--r-- 2 root root 2 Jul 5 23:04 8.file -rw-r--r-- 2 root root 2 Jul 5 23:04 9.file [root@node01 rv2]# node02: [root@node02 ~]# cd /gluster/sdb/rv2 [root@node02 rv2]# ls -lh total 40K -rw-r--r-- 2 root root 3 Jul 6 07:50 10.file -rw-r--r-- 2 root root 2 Jul 6 07:50 1.file -rw-r--r-- 2 root root 2 Jul 6 07:50 2.file -rw-r--r-- 2 root root 2 Jul 6 07:50 3.file -rw-r--r-- 2 root root 2 Jul 6 07:50 4.file -rw-r--r-- 2 root root 2 Jul 6 07:50 5.file -rw-r--r-- 2 root root 2 Jul 6 07:50 6.file -rw-r--r-- 2 root root 2 Jul 6 07:50 7.file -rw-r--r-- 2 root root 2 Jul 6 07:50 8.file -rw-r--r-- 2 root root 2 Jul 6 07:50 9.file [root@node02 rv2]# node03: [root@node03 ~]# cd /gluster/sdb/rv2 [root@node03 rv2]# ls -lh total 40K -rw-r--r-- 2 root root 3 Jul 5 23:06 10.file -rw-r--r-- 2 root root 2 Jul 5 23:06 1.file -rw-r--r-- 2 root root 2 Jul 5 23:06 2.file -rw-r--r-- 2 root root 2 Jul 5 23:06 3.file -rw-r--r-- 2 root root 2 Jul 5 23:06 4.file -rw-r--r-- 2 root root 2 Jul 5 23:06 5.file -rw-r--r-- 2 root root 2 Jul 5 23:06 6.file -rw-r--r-- 2 root root 2 Jul 5 23:06 7.file -rw-r--r-- 2 root root 2 Jul 5 23:06 8.file -rw-r--r-- 2 root root 2 Jul 5 23:06 9.file [root@node03 rv2]#
node0一、node0二、node03節點對應目錄下的文件都一致,說明覆制式的特色確實相似於RAID1,接下來演示故障問題,這裏以node02爲故障點(假設node02宕機)
[root@node01 rv2]# gluster volume info rep_volume
Volume Name: rep_volume
Type: Replicate
Volume ID: 65167369-9fbe-4bb9-a71a-6b4b7547ca2e
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 3 = 3
Transport-type: tcp
Bricks:
Brick1: node01:/gluster/sdb/rv2
Brick2: node02:/gluster/sdb/rv2
Brick3: node03:/gluster/sdb/rv2
Options Reconfigured:
transport.address-family: inet
performance.readdir-ahead: on
nfs.disable: on
[root@node01 rv2]# gluster peer status
Number of Peers: 5
Hostname: node02
Uuid: a6052b2f-7724-428b-a030-3372663c8896
State: Peer in Cluster (Disconnected)
Hostname: node03
Uuid: df99aea5-24aa-4176-8b45-ecea75bbb34a
State: Peer in Cluster (Connected)
Hostname: node04
Uuid: 6baedfed-7132-421d-8227-b79b76339688
State: Peer in Cluster (Connected)
Hostname: node05
Uuid: e6027a77-1b9a-4d58-bb7e-e3eb13c8b3d8
State: Peer in Cluster (Connected)
Hostname: node06
Uuid: 85f56ce4-0a47-4934-bbe9-a5ebaabf3bc9
State: Peer in Cluster (Connected)
[root@node01 rv2]#
在node07上查看複製式卷是否能夠正常使用:
[root@node07 ~]# cd - /ds02 [root@node07 ds02]# ls -lh total 5.0K -rw-r--r-- 1 root root 3 Jul 5 23:04 10.file -rw-r--r-- 1 root root 2 Jul 5 23:04 1.file -rw-r--r-- 1 root root 2 Jul 5 23:04 2.file -rw-r--r-- 1 root root 2 Jul 5 23:04 3.file -rw-r--r-- 1 root root 2 Jul 5 23:04 4.file -rw-r--r-- 1 root root 2 Jul 5 23:04 5.file -rw-r--r-- 1 root root 2 Jul 5 23:04 6.file -rw-r--r-- 1 root root 2 Jul 5 23:04 7.file -rw-r--r-- 1 root root 2 Jul 5 23:04 8.file -rw-r--r-- 1 root root 2 Jul 5 23:04 9.file [root@node07 ds02]#
說明覆制式卷每一個節點數據確實徹底一致,任意丟失一個節點,數據都不會丟失;可是複製式卷空間會大打折扣:
每一個節點提供的空間爲10G; [root@node01 rv2]# df -Th|grep sdb /dev/sdb xfs 10G 33M 10G 1% /gluster/sdb [root@node01 rv2]# [root@node02 ~]# df -Th|grep sdb /dev/sdb xfs 10G 33M 10G 1% /gluster/sdb [root@node02 ~]# [root@node03 rv2]# df -Th|grep sdb /dev/sdb xfs 10G 33M 10G 1% /gluster/sdb [root@node03 rv2]# 使用空間只有10G
[root@node07 ds03]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 97G 1.6G 96G 2% /
devtmpfs devtmpfs 904M 0 904M 0% /dev
tmpfs tmpfs 913M 0 913M 0% /dev/shm
tmpfs tmpfs 913M 8.6M 904M 1% /run
tmpfs tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 125M 890M 13% /boot
tmpfs tmpfs 183M 0 183M 0% /run/user/0
node01:/dis_volume fuse.glusterfs 30G 98M 30G 1% /ds01
node01:/rep_volume fuse.glusterfs 10G 33M 10G 1% /ds02
4.5 建立條帶卷
4.5.1操做過程以下
[root@node01 ~]# gluster volume create str_volume stripe 3 node01:/gluster/sdb/sv3 node02:/gluster/sdb/sv3 node03:/gluster/sdb/sv3 volume create: str_volume: success: please start the volume to access data [root@node01 ~]# gluster volume info str_volume Volume Name: str_volume Type: Stripe Volume ID: 42375044-d0c8-4320-9659-ba85880cebe5 Status: Created Snapshot Count: 0 Number of Bricks: 1 x 3 = 3 Transport-type: tcp Bricks: Brick1: node01:/gluster/sdb/sv3 Brick2: node02:/gluster/sdb/sv3 Brick3: node03:/gluster/sdb/sv3 Options Reconfigured: transport.address-family: inet performance.readdir-ahead: on nfs.disable: on [root@node01 ~]# gluster volume start str_volume volume start: str_volume: success [root@node01 ~]#
條帶卷特性相似於咱們場景的RIAD0,文件被分紅數據塊以Round Robin方式分佈到全部節點上,訪問時根據位置信息肯定節點;
[root@node07 ~]# mount -t glusterfs node01:/str_volume /ds03
[root@node07 ~]# cd /ds03
[root@node07 ds03]# for i in `seq 10`;do echo $i >str_volume.$i;done
[root@node07 ds03]# ls -lh
total 5.0K
-rw-r--r-- 1 root root 2 Jul 7 05:36 str_volume.1
-rw-r--r-- 1 root root 3 Jul 7 05:36 str_volume.10
-rw-r--r-- 1 root root 2 Jul 7 05:36 str_volume.2
-rw-r--r-- 1 root root 2 Jul 7 05:36 str_volume.3
-rw-r--r-- 1 root root 2 Jul 7 05:36 str_volume.4
-rw-r--r-- 1 root root 2 Jul 7 05:36 str_volume.5
-rw-r--r-- 1 root root 2 Jul 7 05:36 str_volume.6
-rw-r--r-- 1 root root 2 Jul 7 05:36 str_volume.7
-rw-r--r-- 1 root root 2 Jul 7 05:36 str_volume.8
-rw-r--r-- 1 root root 2 Jul 7 05:36 str_volume.9
[root@node07 ds03]#
[root@node07 ds03]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 97G 1.6G 96G 2% /
devtmpfs devtmpfs 904M 0 904M 0% /dev
tmpfs tmpfs 913M 0 913M 0% /dev/shm
tmpfs tmpfs 913M 8.6M 904M 1% /run
tmpfs tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 125M 890M 13% /boot
tmpfs tmpfs 183M 0 183M 0% /run/user/0
node01:/dis_volume fuse.glusterfs 30G 98M 30G 1% /ds01
node01:/rep_volume fuse.glusterfs 10G 33M 10G 1% /ds02
node01:/str_volume fuse.glusterfs 30G 98M 30G 1% /ds03
[root@node07 ds03]#
數據分佈狀況:
[root@node01 sv3]# ls -lh total 80K -rw-r--r-- 2 root root 2 Jul 5 23:28 str_volume.1 -rw-r--r-- 2 root root 3 Jul 5 23:28 str_volume.10 -rw-r--r-- 2 root root 2 Jul 5 23:28 str_volume.2 -rw-r--r-- 2 root root 2 Jul 5 23:28 str_volume.3 -rw-r--r-- 2 root root 2 Jul 5 23:28 str_volume.4 -rw-r--r-- 2 root root 2 Jul 5 23:28 str_volume.5 -rw-r--r-- 2 root root 2 Jul 5 23:28 str_volume.6 -rw-r--r-- 2 root root 2 Jul 5 23:28 str_volume.7 -rw-r--r-- 2 root root 2 Jul 5 23:28 str_volume.8 -rw-r--r-- 2 root root 2 Jul 5 23:28 str_volume.9 [root@node01 sv3]# [root@node02 sv3]# ls -lh total 40K -rw-r--r-- 2 root root 0 Jul 7 05:36 str_volume.1 -rw-r--r-- 2 root root 0 Jul 7 05:36 str_volume.10 -rw-r--r-- 2 root root 0 Jul 7 05:36 str_volume.2 -rw-r--r-- 2 root root 0 Jul 7 05:36 str_volume.3 -rw-r--r-- 2 root root 0 Jul 7 05:36 str_volume.4 -rw-r--r-- 2 root root 0 Jul 7 05:36 str_volume.5 -rw-r--r-- 2 root root 0 Jul 7 05:36 str_volume.6 -rw-r--r-- 2 root root 0 Jul 7 05:36 str_volume.7 -rw-r--r-- 2 root root 0 Jul 7 05:36 str_volume.8 -rw-r--r-- 2 root root 0 Jul 7 05:36 str_volume.9 [root@node02 sv3]# [root@node03 sv3]# ls -lh total 40K -rw-r--r-- 2 root root 0 Jul 5 23:29 str_volume.1 -rw-r--r-- 2 root root 0 Jul 5 23:29 str_volume.10 -rw-r--r-- 2 root root 0 Jul 5 23:29 str_volume.2 -rw-r--r-- 2 root root 0 Jul 5 23:29 str_volume.3 -rw-r--r-- 2 root root 0 Jul 5 23:29 str_volume.4 -rw-r--r-- 2 root root 0 Jul 5 23:29 str_volume.5 -rw-r--r-- 2 root root 0 Jul 5 23:29 str_volume.6 -rw-r--r-- 2 root root 0 Jul 5 23:29 str_volume.7 -rw-r--r-- 2 root root 0 Jul 5 23:29 str_volume.8 -rw-r--r-- 2 root root 0 Jul 5 23:29 str_volume.9 [root@node03 sv3]#
一樣,演示節點node02宕機:
[root@node01 sv3]# gluster volume info str_volume
Volume Name: str_volume
Type: Stripe
Volume ID: 42375044-d0c8-4320-9659-ba85880cebe5
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 3 = 3
Transport-type: tcp
Bricks:
Brick1: node01:/gluster/sdb/sv3
Brick2: node02:/gluster/sdb/sv3
Brick3: node03:/gluster/sdb/sv3
Options Reconfigured:
transport.address-family: inet
performance.readdir-ahead: on
nfs.disable: on
[root@node01 sv3]# gluster peer status
Number of Peers: 5
Hostname: node02
Uuid: a6052b2f-7724-428b-a030-3372663c8896
State: Peer in Cluster (Disconnected)
Hostname: node03
Uuid: df99aea5-24aa-4176-8b45-ecea75bbb34a
State: Peer in Cluster (Connected)
Hostname: node04
Uuid: 6baedfed-7132-421d-8227-b79b76339688
State: Peer in Cluster (Connected)
Hostname: node05
Uuid: e6027a77-1b9a-4d58-bb7e-e3eb13c8b3d8
State: Peer in Cluster (Connected)
Hostname: node06
Uuid: 85f56ce4-0a47-4934-bbe9-a5ebaabf3bc9
State: Peer in Cluster (Connected)
[root@node01 sv3]#
再到node07節點掛在目錄查看:
[root@node07 ds03]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 97G 1.6G 96G 2% /
devtmpfs devtmpfs 904M 0 904M 0% /dev
tmpfs tmpfs 913M 0 913M 0% /dev/shm
tmpfs tmpfs 913M 8.6M 904M 1% /run
tmpfs tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 125M 890M 13% /boot
tmpfs tmpfs 183M 0 183M 0% /run/user/0
node01:/dis_volume fuse.glusterfs 20G 66M 20G 1% /ds01
node01:/rep_volume fuse.glusterfs 10G 33M 10G 1% /ds02
node01:/str_volume fuse.glusterfs 20G 66M 20G 1% /ds03
[root@node07 ds03]# ls -lh
total 0
[root@node07 ds03]# ls -a
[root@node07 ds03]#
發現數據已經不存在了,說明條帶卷沒有數據冗錯功能;只要任意一個節點宕機,數據就會丟失;