centos7下的glusterfs的安裝與使用
環境說明:
兩台虛擬主機,IP分別為192.168.1.222和192.168.1.233,分別裝上glusterfs。
一、下載glusterfs源碼包
|
1
|
https://download.gluster.org/pub/gluster/glusterfs/3.6/
|
如:glusterfs-3.6.9.tar.gz
二、編譯安裝
安裝必要的依賴
|
1
|
> yum install flex bison openssl openssl-devel acl libacl libacl-devel sqlite-devel libxml2-devel python-devel |
安裝liburcu
|
1
|
https://github.com/urcu/userspace-rcu
|
|
1
2
3
4
5
6
7
|
> yum install autoconf automake libtool> unzip userspace-rcu-master.zip> cd userspace-rcu-master> ./bootstrap> ./configure> make && make install> ldconfig |
解壓並編譯安裝
|
1
2
3
4
|
> tar xf glusterfs-3.6.9.tar.gz> cd glusterfs-3.6.9> ./configure --prefix=/data/glusterfs> make && make install |
添加環境變量
|
1
2
|
> echo 'export PATH=/data/glusterfs/sbin:$PATH' >> /etc/profile
> source /etc/profile |
三、使用glusterfs
分別啟動兩台主機上的glusterfs
|
1
|
> /data/glusterfs/sbin/glusterd |
在222主機上配置可信池
|
1
|
> gluster peer probe 192.168.1.233 |
如果出現如下問題:
peer probe: failed: Probe returned with unknown errno 107
請查看防火牆是否關閉
查看可信池
|
1
|
> gluster peer status |
要使用gluster必須要創建卷,卷有三種類型:
1、分布式卷,把數據寫在不同的brick上。
在兩台主機上分別創建exp1和exp2目錄
|
1
2
|
> mkdir -p /data/exp1
> mkdir -p /data/exp2
|
創建分布式卷,exp-volume為卷名,可自定義
|
1
|
> gluster volume create exp-volume 192.168.1.222:/data/exp1 192.168.1.233:/data/exp2
|
查看卷信息
|
1
|
> gluster volume info |
查看卷狀態
|
1
|
> gluster volume status |
2、複製卷
在兩台主機上分別創建exp3和exp4目錄
|
1
2
|
> mkdir -p /data/exp3
> mkdir -p /data/exp4
|
創建複製卷,複製兩份,以tcp協議傳輸
注意brick數量與replica指定數相等
|
1
|
> gluster volume create rep-volume replica 2 transport tcp 192.168.1.222:/data/exp3 192.168.1.233:/data/exp4 |
3、條帶卷,把一個文件分開存,像條帶一樣
在兩台主機上分別創建exp5和exp6目錄
|
1
2
|
> mkdir -p /data/exp5
> mkdir -p /data/exp6
|
創建條帶卷
注意brick的數量與stripe指定數量相等
|
1
|
> gluster volume create str-volume stripe 2 transport tcp 192.168.1.222:/data/exp5 192.168.1.233:/data/exp6 |
分別啟動我們上麵創建的三種卷
|
1
2
3
|
> gluster volume start exp-volume
> gluster volume start rep-volume> gluster volume start str-volume |
安裝gluster-clinet
|
1
|
> yum install glusterfs-client |
掛載卷
|
1
2
3
4
|
> mkdir /mnt/m1 /mnt/m2 /mnt/m3
> mount.glusterfs 192.168.1.222:/exp-volume /mnt/m1
> mount.glusterfs 192.168.1.222:/rep-volume /mnt/m2> mount.glusterfs 192.168.1.222:/str-volume /mnt/m3 |
我們創建幾個文件寫到/mnt/m1下
|
1
2
3
|
> echo '1' >> /mnt/m1/test1.txt
> echo '2' >> /mnt/m1/test2.txt
> echo '3' >> /mnt/m1/test3.txt
|
上麵三個文件分別放在了222和233主機下的exp1和exp2目錄。
我們創建文件到複製卷/mnt/m2下
|
1
|
> echo 'rep' >> /mnt/m2/rep.txt
|
rep.txt文件同時會存在222和233主機下的exp3和exp4目錄下。
我們創建文件到條帶卷/mnt/m3下
|
1
|
> echo '123456789' >> /mnt/m3/str.txt
|
str.txt文件會被折分成多個小文件保存在222和233主機下的exp5和exp6目錄下。
三、分布式複製卷的創建與使用
分別在222和233主機上創建
|
1
|
> mkdir -p /data/t1 /data/t2
|
文件存放與這裏的服務器順序有關係
注意brick必須為replica指定數量K的N倍,brick以K個為一組,形成N個複製卷
|
1
2
3
4
5
|
> gluster volume create t-volume replica 2 transport tcp \192.168.1.222:/data/t1 \192.168.1.233:/data/t1 \192.168.1.222:/data/t2 \192.168.1.233:/data/t2 |
啟動卷
|
1
|
> gluster volume start t-volume |
掛載卷
|
1
2
|
> mkdir /mnt/m4
> mount.glusterfs 192.168.1.222:/t-volume /mnt/m4 |
創建文件測試
|
1
2
3
4
|
> echo '1' >> /mnt/m4/1.txt
> echo '1' >> /mnt/m4/2.txt
> echo '1' >> /mnt/m4/3.txt
> echo '1' >> /mnt/m4/4.txt
|
四、卷的設置
啟用卷的配額
|
1
|
> gluster volume quota exp-volume enable
|
關閉卷的配額
|
1
|
> gluster volume quota exp-volume disable
|
設置配額大小,以係統掛載目錄為根目錄,即/mnt/m1/data
|
1
|
> gluster volume quota exp-volume limit-usage /data 10GB
|
查看卷的配額列表
|
1
|
> gluster volume quota exp-volume list
|
增加brick
|
1
|
> gluster volume add-brick exp-volume 192.168.1.222:/data/exp8
|
重新均衡一下卷,上麵增加的卷才生效
|
1
|
> gluster volume rebalance exp-volume start
|
刪除brick
|
1
2
|
> gluster volume remove-brick exp-volume 192.168.1.222:/data/exp8 force
> gluster volume rebalance exp-volume start
|
最後更新:2017-06-30 11:03:24