1. 登入root用戶
sudo su root
2. 設置主機名
修改hostname文件,以及hosts文件添加如下設置,使集羣中的主機可以通過主機名進行訪問:
10.0.101.2 gfs1
10.0.101.191 gfs2
10.0.101.213 gfs3
10.0.101.61 gfs_cli
10.20.32.19 VM_32_19_centos
10.20.52.19 VM_52_19_centos
10.10.64.27 VM_64_27_centos
3. 查看防火牆狀態
systemctl status firewalld
* firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
處於關閉狀態,不做修改。
4. 下載安裝包
下載地址:http://buildlogs.centos.org/centos/6/storage/x86_64/gluster-3.8/
選擇glusterfs3.8版本,下載
glusterfs-libs-3.8.7-1.el6.x86_64.rpm glusterfs-3.8.7-1.el6.x86_64.rpm glusterfs-client-xlators-3.8.7-1.el6.x86_64.rpm glusterfs-fuse-3.8.7-1.el6.x86_64.rpm glusterfs-api-3.8.7-1.el6.x86_64.rpm glusterfs-cli-3.8.7-1.el6.x86_64.rpm userspace-rcu-0.7.16-2.el6.x86_64.rpm glusterfs-server-3.8.7-1.el6.x86_64.rpm glusterfs-geo-replication-3.8.7-1.el6.x86_64.rpm |
5. 查看linux系統是否存在glusterfs相關插件
rpm –qa | grep gluster
如果返回爲空,則無需任何操作,如果返回相關已經安裝的rpm包,先進行卸載,然後進行後續安裝。
6. 安裝glusterfs3.8
yum install nfs-utils
安裝腳本:
#!/bin/bash rpm -ivh glusterfs-libs-3.8.7-1.el6.x86_64.rpm \ glusterfs-3.8.7-1.el6.x86_64.rpm \ glusterfs-client-xlators-3.8.7-1.el6.x86_64.rpm \ glusterfs-fuse-3.8.7-1.el6.x86_64.rpm \ glusterfs-api-3.8.7-1.el6.x86_64.rpm \ glusterfs-cli-3.8.7-1.el6.x86_64.rpm \ userspace-rcu-0.7.16-2.el6.x86_64.rpm \ glusterfs-server-3.8.7-1.el6.x86_64.rpm \ glusterfs-geo-replication-3.8.7-1.el6.x86_64.rpm |
注意:根據環境作適當調整。
7. 啓動glusterd服務
/etc/init.d/glusterd start chkconfig glusterd on chkconfig glusterfsd on |
查看當前glusterd服務啓動狀態:
chkconfig --list | grep glusterd |
8. 配置gluster信任池
在gfs1上執行:
gluster peer probe gfs2 |
檢查加入可信任存儲池中的服務器狀態
命令:gluster peer status
[root@gfs1 soft]# gluster peer status Number of Peers: 1
Hostname: gfs2 Uuid: d0c78a12-95e4-4904-a7f9-5f28ec5a6213 State: Peer in Cluster (Connected) |
9. 創建兩副本模式
1)、創建兩副本
gluster volume create dfs-vm-2 replica 2 gfs1:/data/brick gfs2:/data/brick |
刪除dfs-vm-2
setfattr -x trusted.glusterfs.volume-id /data/brick setfattr -x trusted.gfid /data/brick rm -rf /data/brick/.glusterfs |
Es生產環境創建snapshot
/data/es_data/snapshot gluster volume create es-snapshot 10.10.36.36:/data/es_data/snapshot |
10. 創建三副本模式
1)、創建三副本
gluster volume create gfs_vm replica 3 gfs1:/data/brick gfs2:/data/brick gfs3:/data/brick |
查看創建的卷的信息
命令:gluster volume info
Volume Name: gfs_vm
Type: Replicate
Volume ID: b89cbb0a-a72c-4069-8abc-c68d2394dcbe
Status: Created
Snapshot Count: 0
Number of Bricks: 1 x 3 = 3
Transport-type: tcp
Bricks:
Brick1: gfs1:/data/brick
Brick2: gfs2:/data/brick
Brick3: gfs3:/data/brick
Options Reconfigured:
transport.address-family: inet
performance.readdir-ahead: on
nfs.disable: on
啓動volumes
gluster volume start gfs_vm |
volume start: gfs_vm: success
11. 配置客戶端
1.軟件準備:
glusterfs-libs-3.8.7-1.el6.x86_64.rpm glusterfs-3.8.7-1.el6.x86_64.rpm glusterfs-client-xlators-3.8.7-1.el6.x86_64.rpm glusterfs-fuse-3.8.7-1.el6.x86_64.rpm |
2.安裝rpm包腳本:
#!/bin/bash rpm -ivh glusterfs-libs-3.8.7-1.el6.x86_64.rpm \ glusterfs-3.8.7-1.el6.x86_64.rpm \ glusterfs-client-xlators-3.8.7-1.el6.x86_64.rpm \ glusterfs-fuse-3.8.7-1.el6.x86_64.rpm |
3.掛載gluster集羣設置:
mkdir /gfsdata mount.glusterfs gfs1:/gfs_vm /gfsdata |
4.使用df命令查看掛載結果:
[root@gfs4 soft]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 51605116 2327640 46656112 5% / /dev/vdb 41284928 290740 38897036 1% /data gfs1:/gfs_vm 41284864 182912 39004800 1% /gfsdata |
可以查看到gfs1:/gfs_vm 已經成功掛載到/gfsdata中去了。
5.測試
向/gfsdata寫入文件
vim test
輸入:hello glusterfs
在集羣gfs1 gfs2 gfs3的/data/brick目錄下均可以看到該文件存在。
12. 超時時間設置
當glusterfs集羣中某臺服務器斷線,判斷超時時間,該時間的設置關係到glusterfs掛載客戶端訪問速度。設置命令如下:
gluster volume set gfs_vm network.ping-timeout 10 |
腦裂測試
1. 高可用性測試
1)、情景一:glusterfs集羣存在一臺主機存活
gfs2、gfs3斷網情況下,glusterfs集羣只存在一臺主機:
此時可以保證正常的讀取操作,無法寫入文件。此時文件均處於read-only狀態。
這個是glusterfs默認機制導致的,當集羣中的機器少於50%時,客戶端便無法向集羣中寫入文件,此時文件處於只讀狀態。
2)、情景二:glusterfs集羣存在兩臺主機存活
僅gfs3斷網情況下:
echo “hello glusterfs” >> hello
在服務器gfs1、gfs2均可以看到該文件。
打開gfs3網絡設置,文件亦同步到gfs3服務器,無腦裂現象產生。
3)、在執行情景三的時候:每臺服務器執行
getfattr -m . -d -e hex hello
均返回:
trusted.afr.dirty=0x000000000000000000000000
此時集羣處於:INNOCENT 狀態,各個節點數據均正常。
情景三:來回切斷gfs1、gfs2、gfs3的網絡
僅gfs3斷網情況下:
echo “gfs3_stop” >> hello
在服務器gfs1、gfs2均可以看到該文件,程序正常,無腦裂現象產生。
此時:
gfs1:
trusted.afr.dirty=0x000000000000000000000000
trusted.afr.three-vm-client-2=0x000000010000000000000000
表明:gfs1認爲自己的正確的處於WISE狀態,gfs3的data是不正確的,需要進行同步。
gfs2:
trusted.afr.dirty=0x000000000000000000000000
trusted.afr.three-vm-client-2=0x000000010000000000000000
表明:gfs2認爲自己的正確的處於WISE狀態,gfs3的data是不正確的,需要進行同步。
斷開gfs2的網絡,打開gfs3的網絡:
此時會將gfs1的數據同步到gfs3中
gfs1:
trusted.afr.dirty=0x000000000000000000000000
trusted.afr.three-vm-client-2=0x000000000000000000000000
表明數據已經同步成功,認爲自己的gfs3的數據均爲有效數據。
gfs3:
trusted.afr.dirty=0x000000000000000000000000
然後在掛載的客戶端輸入:
echo “gfs2_stop”>>hello
此時:
gfs1:
trusted.afr.dirty=0x000000000000000000000000
trusted.afr.three-vm-client-1=0x000000010000000000000000
trusted.afr.three-vm-client-2=0x000000000000000000000000
此時gfs1認爲自己和gfs3的數據都是正確的,gfs2的數據需要進行同步。
gfs3:
trusted.afr.dirty=0x000000000000000000000000
trusted.afr.three-vm-client-1=0x000000010000000000000000
此時gfs3認爲自己的數據也是正確的,gfs2的數據需要同步。
斷開gfs1的網絡,打開gfs2的網絡:
在glusterfs掛載客戶端執行:cat hello
出現:hello: Input/output error,此時便出現腦裂的情況了。
gfs2:
trusted.afr.dirty=0x000000000000000000000000
trusted.afr.three-vm-client-2=0x000000010000000000000000
此時gfs2認爲自己是正確的處於WISE狀態,認爲gfs3是錯誤的,需要被同步。
gfs3:
trusted.afr.dirty=0x000000000000000000000000
trusted.afr.three-vm-client-1=0x000000010000000000000000
而gfs3的認爲自己也是正確的,處於WISE狀態,而gfs2的是錯誤的。
此時集羣中便存在兩個WISE節點,並且相互存在衝突,從而導致腦裂的產生。此時打開gfs1的網絡,腦裂的問題就解決了,因爲gfs1也處於WISE狀態,如果存在WISE副本,且沒有其他WISE副本或者其他WISE副本沒有衝突,這時候該副本就可以作爲source,並將該source同步至gfs1、gfs2。
13. 高可靠性
打開:
gluster volume set three-vm cluster.server-quorum-type server
gluster volume set all cluster.server-quorum-ratio 50%
1)、情景一:glusterfs集羣存在一臺主機存活
gfs2、gfs3斷網情況下,glusterfs集羣只存在一臺主機:
此時glusterfs掛載客戶端無法訪問glusterfs集羣,出現異常信息:
ls: cannot open directory .: Transport endpoint is not connected。
2)、情景二:glusterfs集羣存在兩臺主機存活
僅gfs3斷網情況下:
echo “hello glusterfs” >> hello
在服務器gfs1、gfs2均可以看到該文件。
3)、情景三測試同高可用性一致。
14. 設置自動腦裂修復
查看自動腦裂修復的幫助:
gluster volume set help|grep -A3 cluster.favorite-child-policy
執行自動修復命令:
gluster volume set gfs_vm2 cluster.favorite-child-policy mtime
默認值爲on,可設置值爲on/off
gluster volume set gfs_vm2 performance.flush-behind on
客戶端:Translator performance/writebehind
默認值爲1mb,可設置值524288 - 1073741824
現在設置值:512M
gluster volume set gfs_vm2 performance.write-behind-window-size 524288
服務端:Translator performance/io-threads
默認值爲16,可設置值爲0-65,當前設置值16
gluster volume set gfs_vm2 performance.io-thread-count 16
默認值爲32 MB,可設置值爲:[4194304 - 34359738368]
當前設置值:4G
gluster volume set gfs_vm2 performance.cache-size 4194304
writebehind 默認值爲1mb io-threads默認值爲16 cache-size爲32mb flush-behind默認值爲on
GEO-rep配置
gluster volume create strip-vm stripe 2 replica 2 gfs1:/data/strip_brick1 gfs2:/data/strip_brick1 gfs1:/data/strip_brick2 gfs2:/data/strip_brick2
gluster volume geo-replication strip-vm gfs3::strip_gep_rep create push-pem
gluster volume geo-replication strip-vm gfs3::strip_gep_rep start
gluster volume geo-replication strip-vm gfs3::strip_gep_rep stop [force]
gluster volume geo-replication strip-vm gfs3::strip_gep_rep resume force
Strip-vm調優參數
gluster volume set strip-vm performance.flush-behind on
gluster volume set strip-vm performance.write-behind-window-size 524288
gluster volume set strip-vm performance.io-thread-count 4
gluster volume set strip-vm performance.cache-size 4194304
mount.glusterfs gfs1:/strip-vm /data/strip_gfsdata