Centos7下GlusterFS分佈式存儲集羣環境部署記錄

 

以前已經簡單地對GlusterFS分佈式文件系統作了介紹,下面就該環境部署作一記錄:html

0)環境準備node

GlusterFS至少須要兩臺服務器搭建,服務器配置最好相同,每一個服務器兩塊磁盤,一塊是用於安裝系統,一塊是用於GlusterFS。

192.168.10.239    GlusterFS-master(主節點)    Centos7.4
192.168.10.212    GlusterFS-slave (從節點)    Centos7.4
192.168.10.213    Client          (客戶端)
----------------------------------------------------------------------------------------

因爲GlusterFS須要使用網絡,所以還必須事先根據環境設置防火牆規則,關閉SELinux。
這裏我將上面三臺服務器的防火牆和Selinux所有關閉
[root@GlusterFS-master ~]# setenforce 0
[root@GlusterFS-master ~]# getenforce 
[root@GlusterFS-master ~]# cat /etc/sysconfig/selinux |grep "SELINUX=disabled"
SELINUX=disabled

[root@GlusterFS-master ~]# systemctl stop firewalld
[root@GlusterFS-master ~]# systemctl disable firewalld
[root@GlusterFS-master ~]# firewall-cmd --state
not running

------------------------------------------------------------------------------------------
因爲GlusterFS並無服務器與元數據等概念,所以全部服務器的設置都相同。首先要作主機名的設置(若是操做時都用ip地址,不使用主機名,那麼就不須要作hosts綁定):
[root@GlusterFS-master ~]# hostnamectl --static set-hostname GlusterFS-master
[root@GlusterFS-master ~]# cat /etc/hostname
GlusterFS-master
[root@GlusterFS-master ~]# vim /etc/hosts
.....
192.168.10.239  GlusterFS-master
192.168.10.212  GlusterFS-slave

[root@GlusterFS-slave ~]# hostnamectl --static set-hostname GlusterFS-slave
[root@GlusterFS-slave ~]# cat /etc/hostname 
GlusterFS-slave
[root@GlusterFS-slave ~]# vim /etc/hosts
......
192.168.10.239  GlusterFS-master
192.168.10.212  GlusterFS-slave

------------------------------------------------------------------------------------------
時鐘同步
這個問題是集羣內部的時間很是重要,若是服務器間的時間有偏差,可能會給集羣間的通訊帶來麻煩,
進而致使集羣失效。這裏採用網絡同步時鐘的方法,確保兩臺服務器的時間一致(時區和時間都要標準、一致):
[root@GlusterFS-master ~]# yum install -y ntpdate
[root@GlusterFS-master ~]# ntpdate ntp1.aliyun.com 
[root@GlusterFS-master ~]# date

[root@GlusterFS-slave ~]# yum install -y ntpdate
[root@GlusterFS-slave ~]# ntpdate ntp1.aliyun.com
[root@GlusterFS-slave ~]# date

1)安裝依賴(在GlusterFS-master和GlusterFS-slave兩臺機器上都要操做)python

[root@GlusterFS-master ~]# yum install -y flex bison openssl openssl-devel acl libacl libacl-devel sqlite-devel libxml2-devel python-devel make cmake gcc gcc-c++ autoconf automake libtool unzip zip

2)安裝userspace-rcu-master和userspace-rcu-master(在GlusterFS-master和GlusterFS-slave兩臺機器上都要操做)linux

1)下載glusterfs-3.6.9.tar.gz和userspace-rcu-master.zip
百度雲盤下載地址:https://pan.baidu.com/s/1DyKxt0TnO3aNx59mVfJCZA
提取密碼:ywq8

將這兩個安裝包放到/usr/local/src目錄下
[root@GlusterFS-master ~]# cd /usr/local/src/
[root@GlusterFS-master src]# ll
total 6444
-rw-r--r--. 1 root root 6106554 Feb 29  2016 glusterfs-3.6.9.tar.gz
-rw-r--r--. 1 root root  490091 Apr  8 09:58 userspace-rcu-master.zip

2)安裝userspace-rcu-master
[root@GlusterFS-master src]# unzip /usr/local/src/userspace-rcu-master.zip -d /usr/local/
[root@GlusterFS-master src]# cd /usr/local/userspace-rcu-master/
[root@GlusterFS-master userspace-rcu-master]# ./bootstrap
[root@GlusterFS-master userspace-rcu-master]# ./configure
[root@GlusterFS-master userspace-rcu-master]# make && make install
[root@GlusterFS-master userspace-rcu-master]# ldconfig

3)安裝userspace-rcu-master
[root@GlusterFS-master userspace-rcu-master]# tar -zxvf /usr/local/src/glusterfs-3.6.9.tar.gz -C /usr/local/
[root@GlusterFS-master userspace-rcu-master]# cd /usr/local/glusterfs-3.6.9/
[root@GlusterFS-master glusterfs-3.6.9]# ./configure --prefix=/usr/local/glusterfs
[root@GlusterFS-master glusterfs-3.6.9]# make && make install

添加環境變量
[root@GlusterFS-master glusterfs-3.6.9]# vim /etc/profile       //在文件最底部添加以下內容
......
export GLUSTERFS_HOME=/usr/local/glusterfs
export PATH=$PATH:$GLUSTERFS_HOME/sbin

[root@GlusterFS-master glusterfs-3.6.9]# source /etc/profile

4)啓動glusterfs
[root@GlusterFS-master ~]# /usr/local/glusterfs/sbin/glusterd
[root@GlusterFS-master ~]# ps -ef|grep glusterd
root       852     1  0 10:14 ?        00:00:00 /usr/local/glusterfs/sbin/glusterd
root       984 26217  0 10:14 pts/1    00:00:00 grep --color=auto glusterd
[root@GlusterFS-master ~]# lsof -i:24007
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
glusterd 852 root    9u  IPv4 123605      0t0  TCP *:24007 (LISTEN)

3)創建GlusterFS分佈式存儲集羣(這裏選擇在GlusterFS-master上操做。其實在任意一個節點上操做均可以)c++

1)執行如下命令,將192.168.10.212(可使用ip地址,也可使用節點的主機名)節點加入到集羣,有多少個節點須要加入集羣,就執行多少個下面的命令:
[root@GlusterFS-master ~]# gluster peer probe 192.168.10.212
peer probe: success. 

2)查看集羣狀態:
[root@GlusterFS-master ~]# gluster peer status
Number of Peers: 1
Hostname: 192.168.10.212
Uuid: f8e69297-4690-488e-b765-c1c404810d6a
State: Peer in Cluster (Connected)

3)查看 volume 信息(因爲尚未建立volume因此顯示的是暫無信息):
[root@GlusterFS-master ~]# gluster volume info
No volumes present

4)建立數據存儲目錄(在GlusterFS-master和GlusterFS-slave節點上都要操做)
[root@GlusterFS-master ~]# mkdir -p /opt/gluster/data

5)建立複製卷 models,指定剛剛建立的目錄(replica 2代表存儲2個備份,即有多少個節點就存儲多少個備份;後面指定服務器的存儲目錄)。這裏選擇建立的是副本卷。
[root@GlusterFS-master ~]# gluster volume create models replica 2 192.168.10.239:/opt/gluster/data 192.168.10.212:/opt/gluster/data force

6)再次查看 volume 信息
[root@GlusterFS-master ~]# gluster volume info
 
Volume Name: models
Type: Replicate
Volume ID: f1945b0b-67d6-4202-9198-639244ab0a6a
Status: Created
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: 192.168.10.239:/opt/gluster/data
Brick2: 192.168.10.212:/opt/gluster/data

7)啓動 models
[root@GlusterFS-master ~]# gluster volume start models

8)gluster 性能調優
a)首先開啓指定volume的配額 
[root@GlusterFS-master ~]# gluster volume quota models enable

b)限制 models 總目錄最大使用 5GB 空間(5GB並不是絕對,須要根據實際硬盤大小配置) 
[root@GlusterFS-master ~]# gluster volume quota models limit-usage / 5GB

c)設置 cache 大小(128MB並不是絕對,須要根據實際硬盤大小配置)
[root@GlusterFS-master ~]# gluster volume set models performance.cache-size 128MB

d)開啓異步,後臺操做 
[root@GlusterFS-master ~]# gluster volume set models performance.flush-behind on

e)設置 io 線程 32 
[root@GlusterFS-master ~]# gluster volume set models performance.io-thread-count 32

f)設置 回寫 (寫數據時間,先寫入緩存內,再寫入硬盤) 
[root@GlusterFS-master ~]# gluster volume set models performance.write-behind on

g)查看調優以後的volume信息
[root@GlusterFS-master ~]# gluster volume info
 
Volume Name: models
Type: Replicate
Volume ID: f1945b0b-67d6-4202-9198-639244ab0a6a
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: 192.168.10.239:/opt/gluster/data
Brick2: 192.168.10.212:/opt/gluster/data
Options Reconfigured:
performance.write-behind: on
performance.io-thread-count: 32
performance.flush-behind: on
performance.cache-size: 128MB
features.quota: on

4)部署客戶端並掛載GlusterFS文件系統的bricks(存儲單元)(在Client機器上操做)sql

到目前爲止,GlusterFS分佈式存儲集羣的大部分工做已經作完了,接下來就是掛載一個目錄,而後經過對這個掛載目錄操做,
實現數據同步至文件系統,而後寫文件測試下。

注意一點:
客戶端掛載的glusterfs存儲裏寫入的數據都是保存到各節點服務器的存儲目錄下。
若是節點機故障或其存儲目錄發生損壞,可是其備份節點正常,則客戶端掛載點下的數據就不會損失。
但若是發生故障的節點沒有備份節點或者備份節點都發生了故障,則客戶端掛載點下的數據就損失了。
若是建立的是分佈式卷(即Hash卷,沒有備份節點),則若是有一個節點掛了,那麼客戶端的掛載點下的數據就會損失一部分。
 
1)安裝gluster-client
[root@Client ~]# yum install -y glusterfs glusterfs-fuse
 
2)創建掛載點目錄
[root@Client ~]# mkdir -p /opt/gfsmount
 
3)掛載GlusterFS
[root@Client ~]# mount -t glusterfs 192.168.10.239:models /opt/gfsmount/
 
4)檢查掛載狀況
[root@Client ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   38G  4.3G   33G  12% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.6M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/vda1               1014M  143M  872M  15% /boot
/dev/mapper/centos-home   19G   33M   19G   1% /home
tmpfs                    380M     0  380M   0% /run/user/0
overlay                   38G  4.3G   33G  12% /var/lib/docker/overlay2/9904ac8cbcba967de3262dc0d5e230c64ad3c1c53b588048e263767d36df8c1a/merged
shm                       64M     0   64M   0% /var/lib/docker/containers/222ec7f21b2495591613e0d1061e4405cd57f99ffaf41dbba1a98c350cd70f60/mounts/shm
192.168.10.239:models     38G  3.9G   34G  11% /opt/gfsmount
 
5)測試。分別建立30M、300M的兩個大文件,發現速度很快。
[root@Client ~]# time dd if=/dev/zero of=/opt/gfsmount/kevin bs=30M count=1
1+0 records in
1+0 records out
31457280 bytes (31 MB) copied, 0.140109 s, 225 MB/s
 
real    0m0.152s
user    0m0.001s
sys 0m0.036s
 
[root@Client ~]# time dd if=/dev/zero of=/opt/gfsmount/grace bs=300M count=1
1+0 records in
1+0 records out
314572800 bytes (315 MB) copied, 1.07577 s, 292 MB/s
 
real    0m1.106s
user    0m0.001s
sys 0m0.351s
 
[root@Client ~]# cd /opt/gfsmount/
[root@Client gfsmount]# du -sh *
300M    grace
30M     kevin
[root@Client gfsmount]# mkdir test
[root@Client gfsmount]# ll
total 337924
-rw-r--r--. 1 root root 314572800 Apr  7 22:41 grace
-rw-r--r--. 1 root root  31457280 Apr  7 22:41 kevin
drwxr-xr-x. 2 root root      4096 Apr  7 22:43 test
 
6)查看集羣存儲狀況(在GlusterFS-master和GlusterFS-slave節點上操做)
[root@GlusterFS-master ~]# cd /opt/gluster/data/
[root@GlusterFS-master data]# ll
total 337920
-rw-r--r--. 2 root root 314572800 Apr  8 10:41 grace
-rw-r--r--. 2 root root  31457280 Apr  8 10:41 kevin
drwxr-xr-x. 2 root root         6 Apr  8 10:43 test
 
[root@GlusterFS-slave ~]# cd /opt/gluster/data/
[root@GlusterFS-slave data]# ll
total 337920
-rw-r--r--. 2 root root 314572800 Apr  7 22:41 grace
-rw-r--r--. 2 root root  31457280 Apr  7 22:41 kevin
drwxr-xr-x. 2 root root         6 Apr  7 22:43 test

備註:查看得知gluster服務器的每一個節點上都有備份,符合上面步驟,即:建立複製卷 models指定剛剛建立的目錄replica 2代表存儲2個備份docker

5)GlusterFS相關命令bootstrap

1)查看GlusterFS中全部的volume
[root@GlusterFS-master ~]# gluster volume list
models
 
2)啓動磁盤。好比啓動名字爲 models 的磁盤
[root@GlusterFS-master ~]# gluster volume start models
 
3)中止磁盤。好比中止名字爲 models 的磁盤
[root@GlusterFS-master ~]# gluster volume stop models
 
4)刪除磁盤。好比刪除名字爲 models 的磁盤
[root@GlusterFS-master ~]# gluster volume delete models
 
5)驗證GlusterFS集羣。可使用下面三個命令
[root@GlusterFS-master ~]# gluster peer status 
Number of Peers: 1
 
Hostname: 192.168.10.212
Uuid: f8e69297-4690-488e-b765-c1c404810d6a
State: Peer in Cluster (Connected)
 
[root@GlusterFS-master ~]# gluster pool list 
UUID                    Hostname        State
f8e69297-4690-488e-b765-c1c404810d6a    192.168.10.212  Connected
5dfd40e2-096b-40b5-bee3-003b57a39007    localhost       Connected
 
[root@GlusterFS-master ~]# gluster volume status
Status of volume: models
Gluster process                     Port    Online  Pid
------------------------------------------------------------------------------
Brick 192.168.10.239:/opt/gluster/data          49152   Y   1055
Brick 192.168.10.212:/opt/gluster/data          49152   Y   32586
NFS Server on localhost                 N/A N   N/A
Self-heal Daemon on localhost               N/A Y   1074
Quota Daemon on localhost               N/A Y   1108
NFS Server on 192.168.10.212                N/A N   N/A
Self-heal Daemon on 192.168.10.212          N/A Y   32605
Quota Daemon on 192.168.10.212              N/A Y   32614
  
Task Status of Volume models
------------------------------------------------------------------------------
There are no active volume tasks
 
 
6)將節點移出GlusterFS集羣,能夠批量移除。以下將glusterfs3和glusterfs4兩個節點移除集羣。
若是是副本卷,移除的節點須要時replica的整數倍。
默認狀況下節點是移除不了的,可使用force強制移除(不建議強制移除節點)。
前提是移除的節點上的brick要移除。
[root@GlusterFS-master ~]# gluster peer detach glusterfs3 glusterfs4  force
或者經過gluster命令的交互模式進行操做:
[root@GlusterFS-master ~]# gluster
gluster> peer detach glusterfs3 glusterfs4  force
 
7)卷擴容(因爲副本數設置爲2,至少要添加2(四、六、8..)臺機器)。
須要特別注意:若是複製卷或者條帶卷,每次添加的Brick節點數必須是replica或者stripe的整數倍。
好比添加glusterfs三、glusterfs4兩個節點,並將這兩個節點的卷(即)合併,合併後的卷名稱爲glusterfs_data。
[root@GlusterFS-master ~]# gluster peer probe glusterfs3   
[root@GlusterFS-master ~]# gluster peer probe glusterfs4   
[root@GlusterFS-master ~]# gluster volume add-brick glusterfs_data glusterfs3:/opt/gluster/data glusterfs4:/opt/gluster/data force
 
8)從新均衡卷(glusterfs_data爲卷名)
[root@GlusterFS-master ~]# gluster volume rebalance glusterfs_data start 
[root@GlusterFS-master ~]# gluster volume rebalance glusterfs_data status 
[root@GlusterFS-master ~]# gluster volume rebalance glusterfs_data stop 
 
均衡卷的前提是至少有兩個brick存儲單元(即至少3個節點集羣)。
上面的例子中,models卷中只有一個brick存儲單元,故不能進行均衡卷操做:
[root@GlusterFS-master ~]# gluster volume list
models
[root@GlusterFS-master ~]# gluster volume rebalance models start
volume rebalance: models: failed: Volume models is not a distribute volume or contains only 1 brick.
Not performing rebalance
[root@GlusterFS-master ~]#
 
9)收縮卷(收縮卷前gluster須要先移動數據到其餘位置)(gv0爲卷名)。注意,若是是複製卷或者條帶卷,則每次移除的Brick數必須是replica或者stripe的整數倍。
[root@GlusterFS-master ~]# gluster volume remove-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs4:/data/brick1/gv0 start      //開始遷移  
[root@GlusterFS-master ~]# gluster volume remove-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs4:/data/brick1/gv0 status     //查看遷移狀態  
[root@GlusterFS-master ~]# gluster volume remove-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs4:/data/brick1/gv0 commit     //遷移完成後提交  
 
10)遷移卷
 
#將glusterfs3的數據遷移到glusterfs5,先將glusterfs5加入集羣
[root@GlusterFS-master ~]# gluster peer probe glusterfs5  
 
#開始遷移
[root@GlusterFS-master ~]# gluster volume replace-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs5:/data/brick1/gv0 start 
 
#查看遷移狀態 
[root@GlusterFS-master ~]# gluster volume replace-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs5:/data/brick1/gv0 status
 
#數據遷移完畢後提交  
[root@GlusterFS-master ~]# gluster volume replace-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs5:/data/brick1/gv0 commit   
 
#若是機器glusterfs3出現故障已經不能運行,執行強制提交  
[root@GlusterFS-master ~]# gluster volume replace-brick gv0 glusterfs3:/data/brick1/gv0 glusterfs5:/data/brick1/gv0 commit force
 
#同步整個卷  
[root@GlusterFS-master ~]# gluster volume heal gfs full
 
11)受權訪問。以下受權192.168網段的客戶機能訪問此glusterfs存儲卷。
[root@GlusterFS-master ~]# gluster volume set gfs auth.allow 192.168.*

6)總結幾點vim

如上操做後,GlusterFS的分佈式存儲集羣環境已經搭建完成。這裏總結幾點以下:
1)若是Glusterfs節點機器重啓,那麼重啓後:
   a)glusterFS服務須要啓動
   b)磁盤models(即存儲卷)須要啓動
   c)目錄/opt/gfsmount/須要從新掛載
   d)掛載完目錄/opt/gfsmount/須要從新進入

2)注意:
兩個分區掛到同一個分區,第一個掛的那個不是被覆蓋,而是被暫時隱藏。好比:
先掛載的"mount /dev/sda1 /opt/gfsmount/",接着又掛載的"mount /dev/sda2 /opt/gfsmount/",
那麼/dev/sda1內的就暫時被隱藏,只要"umount /dev/sda2",把第二個分區卸載了,
在"cd /opt/gfsmount/"就能夠看到掛的第一個分區的內容了。

3)gluster的端口
glusterd進程的端口號是24007
glusterfsd進程的端口號是49153

4)建立的六種存儲卷
---------------建立複製卷---------------
語法:gluster volume create NEW-VOLNAME [replica COUNT] [transport tcp | rdma | tcp, rdma] NEW-BRICK
示例
[root@GlusterFS-master ~]# gluster volume create test-volume replica 2 transport tcp server1:/exp1/brick server2:/exp2/brick

---------------建立條帶卷---------------
語法:gluster volume create NEW-VOLNAME [stripe COUNT] [transport tcp | rdma | tcp, rdma] NEW-BRICK...
示例:
[root@GlusterFS-master ~]# gluster volume create test-volume stripe 2 transport tcp server1:/exp1/brick server2:/exp2/brick

---------------建立分佈式卷(即Hash哈希卷)---------------
語法:gluster volume create NEW-VOLNAME [transport tcp | rdma | tcp, rdma] NEW-BRICK
示例1
[root@GlusterFS-master ~]# gluster volume create test-volume server1:/exp1/brick server2:/exp2/brick
示例2
[root@GlusterFS-master ~]# gluster volume create test-volume transport rdma server1:/exp1/brick server2:/exp2/brick server3:/exp3/brick server4:/exp4/brick

---------------分佈式複製卷---------------
語法:gluster volume create NEW-VOLNAME [replica COUNT] [transport tcp | rdma | tcp, rdma] NEW-BRICK...
示例: 
[root@GlusterFS-master ~]# gluster volume create test-volume replica 2 transport tcp server1:/exp1/brick server2:/exp2/brick server3:/exp3/brick server4:/exp4/brick

---------------分佈式條帶卷---------------
語法:gluster volume create NEW-VOLNAME [stripe COUNT] [transport tcp | rdma | tcp, rdma] NEW-BRICK...
示例:
[root@GlusterFS-master ~]# gluster volume create test-volume stripe 2 transport tcp server1:/exp1/brick server2:/exp2/brick server3:/exp3/brick server4:/exp4/brick

---------------條帶複製卷---------------
語法:gluster volume create NEW-VOLNAME [stripe COUNT] [replica COUNT] [transport tcp | rdma | tcp, rdma] NEW-BRICK...
示例:
[root@GlusterFS-master ~]# gluster volume create test-volume stripe 2 replica 2 transport tcp server1:/exp1/brick server2:/exp2/brick server3:/exp3/brick server4:/exp4/brick


5)查看卷
[root@GlusterFS-master ~]# gluster volume list              //列出集羣中的全部卷*/
[root@GlusterFS-master ~]# gluster volume info [all]        //查看集羣中的卷信息*/
[root@GlusterFS-master ~]# gluster volume status [all]      //查看集羣中的卷狀態*/

6)Brick管理
這裏以一個例子來講明:把192.168.10.151:/mnt/brick0 替換爲192.168.10.151:/mnt/brick2

6.1)開始替換
[root@GlusterFS-slave ~]# gluster volume replace-brick test-volume 192.168.10.151:/mnt/brick0 192.168.10.152:/mnt/brick2 start
異常信息:volume replace-brick: failed: /data/share2 or a prefix of it is already part of a volume 

說明 /mnt/brick2 曾經是一個Brick。具體解決方法
[root@GlusterFS-slave ~]# rm -rf /mnt/brick2/.glusterfs

[root@GlusterFS-slave ~]# setfattr -x trusted.glusterfs.volume-id /mnt/brick2
[root@GlusterFS-slave ~]# setfattr -x trusted.gfid  /mnt/brick2

//如上,執行replcace-brick卷替換啓動命令,使用start啓動命令後,開始將原始Brick的數據遷移到即將須要替換的Brick上。

6.2)查看是否替換完
[root@GlusterFS-slave ~]# gluster volume replace-brick test-volume 192.168.10.151:/mnt/brick0 192.168.10.152:/mnt/brick2 status

6.3)在數據遷移的過程當中,能夠執行abort命令終止Brick替換。
[root@GlusterFS-slave ~]# gluster volume replace-brick test-volume 192.168.10.151:/mnt/brick0 192.168.10.152:/mnt/brick2 abort

6.4)在數據遷移結束以後,執行commit命令結束任務,則進行Brick替換。使用volume info命令能夠查看到Brick已經被替換。
[root@GlusterFS-slave ~]# gluster volume replace-brick test-volume 192.168.10.151:/mnt/brick0 192.168.10.152:/mnt/brick2 commit
此時再往 /sf/data/vs/gfs/rep2上添加數據的話,數據會同步到 192.168.10.152:/mnt/brick0和192.168.10.152:/mnt/brick2上。而不會同步到
192.168.10.151:/mnt/brick0 上。 

7)收縮卷
先將數據遷移到其它可用的Brick,遷移結束後纔將該Brick移除:
[root@GlusterFS-slave ~]# gluster volume remove-brick <VOLNAME> <BRICK> start
 
在執行了start以後,可使用status命令查看移除進度:
[root@GlusterFS-slave ~]# gluster volume remove-brick <VOLNAME> <BRICK> status
 
不進行數據遷移,直接刪除該Brick:
[root@GlusterFS-slave ~]# gluster volume remove-brick <VOLNAME> <BRICK> commit
 
注意,若是是複製卷或者條帶卷,則每次移除的Brick數必須是replica或者stripe的整數倍。

8)遷移卷
使用start命令開始進行遷移:
[root@GlusterFS-slave ~]# gluster volume replace-brick <VOLNAME> <BRICK> <NEW-BRICK> start

在數據遷移過程當中,可使用pause命令暫停遷移:
[root@GlusterFS-slave ~]# gluster volume replace-brick <VOLNAME> <BRICK> <NEW-BRICK> pause
 
在數據遷移過程當中,可使用abort命令終止遷移:
[root@GlusterFS-slave ~]# gluster volume replace-brick <VOLNAME> <BRICK> <NEW-BRICK> abort
 
在數據遷移過程當中,可使用status命令查看遷移進度:
[root@GlusterFS-slave ~]# gluster volume replace-brick <VOLNAME> <BRICK> <NEW-BRICK> status
 
在數據遷移結束後,執行commit命令來進行Brick替換:
[root@GlusterFS-slave ~]# gluster volume replace-brick <VOLNAME> <BRICK> <NEW-BRICK> commit

7)幾個問題centos

1)從新添加一個曾經交付的brick,報錯:
異常信息:volume replace-brick: failed: /data/share2 or a prefix of it is already part of a volume

說明 /mnt/brick2 曾經是一個Brick。具體解決方法 
[root@GlusterFS-slave ~]# rm -rf /mnt/brick2/.glusterfs
[root@GlusterFS-slave ~]# setfattr -x trusted.glusterfs.volume-id /mnt/brick2  // 移除目錄的擴展屬性
[root@GlusterFS-slave ~]# setfattr -x trusted.gfid  /mnt/brick2

2)在glusterfs掛載點上,操做,出現:傳輸端點還沒有鏈接
經過 volume info 查看正常。
[root@GlusterFS-slave ~]# ls
ls: 沒法打開目錄.: 傳輸端點還沒有鏈接
[root@GlusterFS-slave ~]# df
文件系統             1K-塊      已用      可用 已用% 掛載點
/dev/mapper/vg_vclassftydc-lv_root
                      13286512   3914004   8674552  32% /
tmpfs                  2013148         4   2013144   1% /dev/shm
/dev/sda1               487652     31759    426197   7% /boot
/dev/mapper/vg_vclassftydc-lv_var
                      20511356    496752  18949644   3% /var
/dev/mapper/ssd-ssd   20836352   9829584  11006768  48% /mnt/787fe74d9bef93c17a7aa195a05245b3
/dev/mapper/defaultlocal-defaultlocal
                      25567232  10059680  15507552  40% /mnt/ab796251092bf7c1d7657e728940927b
df: "/mnt/glusterfs-mnt": 傳輸端點還沒有鏈接
[root@GlusterFS-slave ~]# cd ..
-bash: cd: ..: 傳輸端點還沒有鏈接
[root@GlusterFS-slave ~]# 

緣由:glusterfs的掛載目錄已經umount了。 
掛載glusterfs後,一段時間發現被umount,掛載日誌以下: 
[2017-06-28 05:45:51.861186] I [dht-layout.c:726:dht_layout_dir_mismatch] 0-test-vol2-dht: / - disk layout missing
[2017-06-28 05:45:51.861332] I [dht-common.c:623:dht_revalidate_cbk] 0-test-vol2-dht: mismatching layouts for /
[2017-06-28 05:46:02.499449] I [dht-layout.c:726:dht_layout_dir_mismatch] 0-test-vol2-dht: / - disk layout missing
[2017-06-28 05:46:02.499520] I [dht-common.c:623:dht_revalidate_cbk] 0-test-vol2-dht: mismatching layouts for /
[2017-06-28 05:46:05.701259] I [fuse-bridge.c:4628:fuse_thread_proc] 0-fuse: unmounting /mnt/glusterfs-mnt/
[2017-06-28 05:46:05.701898] W [glusterfsd.c:1002:cleanup_and_exit] (-->/lib64/libc.so.6(clone+0x6d) [0x7f09e546090d] (-->/lib64/libpthread.so.0(+0x7851) [0x7f09e5aff851] (-->/usr/sbin/glusterfs(glusterfs_sigwaiter+0xcd) [0x40533d]))) 0-: received signum (15), shutting down
[2017-06-28 05:46:05.701911] I [fuse-bridge.c:5260:fini] 0-fuse: Unmounting '/mnt/glusterfs-mnt/'.

3)恢復節點配置信息
故障現象: 其中一個節點配置信息不正確
故障模擬:刪除server2部分配置信息,配置信息位置:/var/lib/glusterd/
修復方法:觸發自修復:經過Gluster工具同步配置信息
[root@GlusterFS-slave ~]# gluster volume sync server1 all

4)複製卷數據不一致
故障現象: 雙副本卷數據出現不一致
故障模擬: 刪除其中一個brick數據
修復方法:從新mount一下

5)複製卷的目錄刪除了
修復方法:先替換brick
[root@GlusterFS-slave ~]# gluster volume replace-brick bbs_img 10.20.0.201:/brick1/share2 10.20.0.201:/brick1/share start
[root@GlusterFS-slave ~]# gluster volume replace-brick bbs_img 10.20.0.201:/brick1/share2 10.20.0.201:/brick1/share commit

還原的時候注意會報錯
解決辦法
[root@GlusterFS-slave ~]# rm -rf /data/share2/.glusterfs
[root@GlusterFS-slave ~]# setfattr -x  trusted.glusterfs.volume-id /data/share2
[root@GlusterFS-slave ~]# setfattr -x trusted.gfid /data/share2

6)移除brick出現以下問題
[root@GlusterFS-slave ~]# volume remove-brick test_vol01 192.168.10.186:/mnt/63ef41a63399e6640a3c4abefa725497 192.168.10.186:/mnt/ad242fbe177ba330a0ea75a9d23fc936 force
Removing brick(s) can result in data loss. Do you want to Continue? (y/n) y
volume remove-brick commit force: failed: One or more nodes do not support the required op-version. Cluster op-version must atleast be 30600.
緣由:節點版本不一致形成的

7)gluster 掛載點沒法使用,沒法umount
[root@GlusterFS-slave ~]# umount /mnt/d1f561a32ac1bf17cf183f36baac34d4
umount: /mnt/d1f561a32ac1bf17cf183f36baac34d4: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
緣由:有一個glusterfs  進程正在使用。經過ps 查看 參數中有mount的,kill掉後,便可umount操做。

===========================添加節點操做===========================

上面案例只是用到了兩個節點機,在實際生產環境中,可能用到的節點會更多。下面簡單說下追加節點的操做:
因爲上面建立的是副本卷,新增長的節點數必須是replica的整數倍,故新增長的節點數至少是兩個。

這裏新增長兩個節點機的信息以下:
192.168.10.204  GlusterFS-slave2
192.168.10.220  GlusterFS-slave3

1)首先在四個幾點機器的/etc/hosts裏面作好hosts綁定
192.168.10.239  GlusterFS-master
192.168.10.212  GlusterFS-slave
192.168.10.204  GlusterFS-slave2
192.168.10.220  GlusterFS-slave3

2)關閉防火牆,以及同步好系統時間

3)安裝上面的操做步驟在新增長的兩個節點機上安裝安裝userspace-rcu-master和userspace-rcu-master

4)在新增長的兩個節點機上建立存儲目錄
# mkdir -p /opt/gluster/data

5)創建GlusterFS集羣(在GlusterFS-master機器上操做)
[root@GlusterFS-master ~]# gluster peer probe 192.168.10.204
[root@GlusterFS-master ~]# gluster peer probe 192.168.10.220
---------------------------------------------------------------------
若是出現下面報錯:
peer probe: failed: Probe returned with unknown errno 107
產生緣由:
目標服務器上的防火牆是否關閉?、glusterd是否啓動運行?可否ping的通?
---------------------------------------------------------------------

[root@GlusterFS-master ~]# gluster peer status         //在每一個節點機上均可以執行這個查看命令
Number of Peers: 3

Hostname: 192.168.10.212
Uuid: f8e69297-4690-488e-b765-c1c404810d6a
State: Peer in Cluster (Connected)

Hostname: 192.168.10.204
Uuid: a989394c-f64a-40c3-8bc5-820f623952c4
State: Peer in Cluster (Connected)

Hostname: 192.168.10.220
Uuid: dd99743a-285b-4aed-b3d6-e860f9efd965
State: Peer in Cluster (Connected)

[root@GlusterFS-master ~]# gluster volume info        //在每一個節點機上均可以執行這個查看命令
 
Volume Name: models
Type: Replicate
Volume ID: f1945b0b-67d6-4202-9198-639244ab0a6a
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: 192.168.10.239:/opt/gluster/data
Brick2: 192.168.10.212:/opt/gluster/data
Options Reconfigured:
performance.write-behind: on
performance.io-thread-count: 32
performance.flush-behind: on
performance.cache-size: 128MB
features.quota: on


6)卷擴容(即將新添加的兩個節點的brick添加到上面的models磁盤裏)

首先將Client客戶機上以前的glusterfs掛載卸載掉
[root@Client ~]# umount /opt/gfsmount

而後將GlusterFS-master節點上的models關閉
[root@GlusterFS-master ~]# gluster volume stop models
[root@GlusterFS-master ~]# gluster volume status models

而後執行卷擴容操做
[root@GlusterFS-master ~]# gluster volume add-brick models 192.168.10.204:/opt/gluster/data 192.168.10.220:/opt/gluster/data force

查看volume 信息,發現新節點已經加入進去了
[root@GlusterFS-master ~]# gluster volume info
Volume Name: models
Type: Distributed-Replicate
Volume ID: f1945b0b-67d6-4202-9198-639244ab0a6a
Status: Stopped
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: 192.168.10.239:/opt/gluster/data
Brick2: 192.168.10.212:/opt/gluster/data
Brick3: 192.168.10.204:/opt/gluster/data
Brick4: 192.168.10.220:/opt/gluster/data
Options Reconfigured:
performance.write-behind: on
performance.io-thread-count: 32
performance.flush-behind: on
performance.cache-size: 128MB
features.quota: on

而後在GlusterFS-master從新啓動models磁盤
[root@GlusterFS-master ~]# gluster volume start models
volume start: models: success
[root@GlusterFS-master ~]# gluster volume status models
Status of volume: models
Gluster process           Port  Online  Pid
------------------------------------------------------------------------------
Brick 192.168.10.239:/opt/gluster/data      49152 Y 5405
Brick 192.168.10.212:/opt/gluster/data      49152 Y 2665
Brick 192.168.10.204:/opt/gluster/data      49152 Y 8788
Brick 192.168.10.220:/opt/gluster/data      49152 Y 12117
NFS Server on localhost         N/A N N/A
Self-heal Daemon on localhost       N/A Y 5426
Quota Daemon on localhost       N/A Y 5431
NFS Server on 192.168.10.212        N/A N N/A
Self-heal Daemon on 192.168.10.212      N/A Y 2684
Quota Daemon on 192.168.10.212        N/A Y 2691
NFS Server on 192.168.10.204        N/A N N/A
Self-heal Daemon on 192.168.10.204      N/A Y 8807
Quota Daemon on 192.168.10.204        N/A Y 8814
NFS Server on 192.168.10.220        N/A N N/A
Self-heal Daemon on 192.168.10.220      N/A Y 12136
Quota Daemon on 192.168.10.220        N/A Y 12143
 
Task Status of Volume models
------------------------------------------------------------------------------
There are no active volume tasks


接着在Client客戶機從新掛載glusterfs
[root@Client ~]# mount -t glusterfs 192.168.10.239:models /opt/gfsmount/
[root@Client ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
.......
192.168.10.239:models     75G  6.0G   69G   8% /opt/gfsmount

而後進行從新均衡。均衡卷的前提是至少有兩個brick存儲單元(即至少3個節點集羣)。
[root@GlusterFS-master data]# gluster volume rebalance models start 
volume rebalance: models: success: Initiated rebalance on volume models.
Execute "gluster volume rebalance <volume-name> status" to check status.
ID: 2ff550ae-043d-457a-8af6-873d9f4ce7ee

最後再Client機器上進行測試:
注意:
1)新添加到models卷裏的節點的存儲目錄裏不會有以前其餘節點的數據,只會有新寫入的數據。
2)因爲上面建立副本卷的時候,指定的副本是2個(即replica 2),因此新寫入的數據只會均衡地寫入到其中的兩個節點的存儲目錄下,不會四個節點的存儲目錄都寫入的。

在客戶機上作測試,發現:
1)在glusterfs掛載目錄裏建立的文件,只會同步到其中的兩個節點上。若是是小文件,會明顯固定同步到兩個節點上;若是是大文件,每次會同步到不一樣的兩個節點上。
2)在glusterfs掛載目錄裏建立的目錄,會同步到全部的節點上。可是在該目錄下建立文件,只會同步到其中的兩個節點上。若是是小文件,會明顯固定同步到兩個節點上;
   若是是大文件,每次會同步到不一樣的兩個節點上。

也能夠在GlusterFS-master上執行"從新均衡卷"的操做。均衡卷執行後,首先會將全部節點的存儲目錄數據保持一致(以最多數據的那個節點爲準,進行同步一致)。而後從新測試數據,測試的效果跟上面描述的同樣。
[root@GlusterFS-master data]# gluster volume rebalance models start
相關文章
相關標籤/搜索