在Centos上安裝使用GlusterFS

        最近接觸了下GlusterFS,所以就想着在自己的筆記本上的虛擬機裏安裝個測試環境。起初想要從https://github.com/gluster/glusterfs/ 上下載一個build然後編譯安裝, 但是試了很多次,在make時總是失敗,折騰了兩天後,徹底死心了...


1. 先介紹下我的實驗環境,由於筆記本配置不是很高,所以我就只開了兩個CentOS7的虛擬機,網絡選擇NAT,以確保能夠連接到外網,都做server,其中一臺還要兼做client,沒有單獨的client端。還有兩個server要能夠相互解析hostname,而我這裏又沒有DNS服務器,所以要把下面的兩行信息加入到/etc/hosts文件裏。

      192.168.133.145      node01.lab.example.com

      192.168.133.135      node02.lab.exampe.com


2. 下載安裝yum源頭,非特殊說明,以下操作步驟在兩臺server上均要執行,貼出的命令以node01爲例

[root@node01 ~]# wget -P /etc/yum.repos.d/ http://download.gluster.org/pub/gluster/glusterfs/LATEST/CentOS/glusterfs-epel.repo


3. 安裝glusterfs的主要組件:

[root@node01 ~]# yum install -y glusterfs glusterfs-server glusterfs-fuse

[root@node01 ~]# rpm -qa | grep gluster
glusterfs-fuse-3.11.1-1.el7.x86_64
glusterfs-3.11.1-1.el7.x86_64
glusterfs-cli-3.11.1-1.el7.x86_64
glusterfs-server-3.11.1-1.el7.x86_64
glusterfs-client-xlators-3.11.1-1.el7.x86_64
glusterfs-api-3.11.1-1.el7.x86_64
glusterfs-libs-3.11.1-1.el7.x86_64


4. 啓動glusterfs service,並設置爲開機自啓動

[root@node01 ~]# systemctl start glusterd
[root@node01 ~]# systemctl enable glusterd
Created symlink from /etc/systemd/system/multi-user.target.wants/glusterd.service to /usr/lib/systemd/system/glusterd.service.

至此,glusterfs已經成功安裝到兩臺server上了,接下來做一些簡單使用測試


5. 創建trust storage pool(信任存儲池?不知道這個翻譯準不準確,暫且這樣用吧)

1)如果開啓了firewall或者iptables服務,我們需要先放開相應的服務,以firewall爲例:

[root@node01 ~]# firewall-cmd --add-service=glusterfs

[root@node01 ~]# firewall-cmd --runtime-to-permanent   

2)在node01上創建信任池,也可以在node02上執行,總之只需在一臺服務器上執行以下命令即可:

[root@node01 ~]# gluster peer probe node02.lab.example.com

[root@node01 ~]# gluster peer status
Number of Peers: 1

Hostname: node02.lab.example.com
Uuid: 707099ff-5c39-467e-950c-9fef9ca7f701
State: Peer in Cluster (Connected)
[root@node01 ~]# gluster pool list
UUID                                    Hostname                State
707099ff-5c39-467e-950c-9fef9ca7f701    node02.lab.example.com  Connected
2be7bf8f-fba4-4b3f-a510-31d99c7c9ccf    localhost               Connected
[root@node01 ~]#


6. 創建Volume以便進行掛載測試,glusterfs上可以創建多種類型的volume,例如簡單點的distributed volume, replicated volume,複雜點的dispersed volume,當然也可以創建複合volume,如distributed-replicated volume.今次我們先來個簡單的,創建一個2副本的replicated volume.

---我這裏使用的是瘦邏輯卷做的底層存儲,所以開始前先把瘦邏輯卷做出來:

[root@node01 ~]# pvs
  PV         VG        Fmt  Attr PSize  PFree
  /dev/sdb   vg_bricks lvm2 a--  20.00g 17.99g
[root@node01 ~]# vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vg_bricks   1   2   0 wz--n- 20.00g 17.99g
[root@node01 ~]# lvs
  LV       VG        Attr       LSize  Pool  Origin Data%  Meta%  Move Log Cpy%Sync Convert
  pool1    vg_bricks twi-aotz--  2.00g              0.55   1.17                           
  thinvol1 vg_bricks Vwi-a-tz--  2.00g pool1        0.55                                  
[root@node01 ~]#


---格式化邏輯卷並進行掛載,在格式化時注意要加參數-i size=512,這個是glusterfs需要的

[root@node01 ~]# mkfs -t xfs -i size=512 /dev/mapper/vg_bricks-thinvol1

[root@node01 ~]# mkdir /bricks/thinvol1/

[root@node01 ~]# mount /dev/mapper/vg_bricks-thinvol1 /bricks/thinvol1/

建議將掛載步驟寫入到/etc/fstab裏,以確保實現開機自動掛載


glusterfs是基於brick的,而且我們的brick不能是mount point,所以還要創建一個brick目錄在掛載目錄下

[root@node01 ~]# mkdir /bricks/thinvol1/brick/

如果開啓了selinux,還需要配置安全上下文

[root@node01 ~]# chcon -R -t glusterd_brick_t /bricks/thinvol1/


7. Create and start volume

準備工作到此可以告一段落了,現在我們可以創建volume了

[root@node01 ~]# gluster volume create RepVol replica 2 \
> node01.lab.example.com:/bricks/thinvol1/brick \
> node02.lab.example.com:/bricks/thinvol1/brick

創建完後,volume還不能立即使用,我們還需要start volume

[root@node01 ~]# gluster volume start RepVol

[root@node01 ~]# gluster volume info RepVol
 
Volume Name: RepVol
Type: Replicate
Volume ID: 2ae04508-a5ec-47f6-a436-e3a87ee39ced
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node01.lab.example.com:/bricks/thinvol1/brick
Brick2: node02.lab.example.com:/bricks/thinvol1/brick

...


8. 在Client端使用Volume,這裏我們假設我們的node02是一個Client節點

Glusterfs支持的掛載類型根據掛載方式不同可以分爲以下三類:

1)Native mount,需要安裝glusterfs-fuse,本身支持高可用

2)NFS 方便簡單,在創建完 volume後,glusterfs會自動啓動一個nfs共享進程,server端只需在firewall中打開nfs相關的access即可,無需其他配置

firewall-cmd --add-service=nfs

firewall-cmd --add-service=rpc-bind

3)Samba 配置較上面兩種類型稍顯複雜,但也有優點,就是可以支持Windows掛載,這裏我們不做詳細介紹了

---使用Native mount掛載gluster volume 到node02節點的/test目錄下

[root@node02 glusterfs]# mount -t glusterfs node02.lab.example.com:RepVol /test/
[root@node02 glusterfs]# df -h | grep test
node02.lab.example.com:RepVol   2.0G   33M  2.0G   2% /test


[root@node02 ~]# cd /test
[root@node02 test]# touch file{1..100}.txt

[root@node02 test]# ls -l /test/ | grep -v total | wc -l
100


分別在node01 和node02 上驗證下,發現在兩個節點的brick裏面都存在100個測試文件:

[root@node01 ~]# ls -l /bricks/thinvol1/brick/ | grep -v total | wc -l
100

[root@node02 test]# ls -l /bricks/thinvol1/brick/ | grep -v total | wc -l
100

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章