GlusterFS分布式存儲系統


GlusterFS分布式存儲系統

一,分布式文件系統理論基礎

1.1 分布式文件系統出現

  • 計算機通過文件系統管理,存儲數據,而現在數據信息爆炸的時代中人們可以獲取的數據成指數倍的增長,單純通過增加硬盤個數來擴展計算機文件系統的存儲容量的方式,已經不能滿足目前的需求。
  • 分布式文件系統可以有效解決數據的存儲和管理難題,將固定於某個地點的某個文件系統,擴展到任意多個地點/多個文件系統,眾多的節點組成一個文件系統網絡。每個節點可以分布在不同的地點,通過網絡進行節點間的通信和數據傳輸。人們在使用分布式文件系統時,無需關心數據是存儲在哪個節點上,或者是從哪個節點從獲取的,只需要像使用本地文件系統一樣管理和存儲文件系統中的數據。

1.2 典型代表NFS

NFS(Network File System)即網絡文件系統,它允許網絡中的計算機之間通過TCP/IP網絡共享資源。在NFS的應用中,本地NFS的客戶端應用可以透明地讀寫位於遠端NFS服務器上的文件,就像訪問本地文件一樣。NFS的優點如下:

(1)節約使用的磁盤空間

客戶端經常使用的數據可以集中存放在一台機器上,並使用NFS發布,那么網絡內部所有計算機可以通過網絡訪問,不必單獨存儲。

(2)節約硬件資源

NFS還可以共享軟驅,CDROM和ZIP等的存儲設備,減少整個網絡上的可移動設備的數量。

(3)用戶主目錄設定

對於特殊用戶,如管理員等,為了管理的需要,可能會經常登陸到網絡中所有的計算機,若每個客戶端,均保存這個用戶的主目錄很繁瑣,而且不能保證數據的一致性。實際上,經過NFS服務的設定,然后在客戶端指定這個用戶的主目錄位置,並自動掛載,就可以在任何計算機上使用用戶主目錄的文件。

1.3 面臨的問題

存儲空間不足,需要更大容量的存儲
直接用NFS掛載存儲,有一定風險,存在單點故障
某些場景不能滿足需求,大量的訪問磁盤IO是瓶頸

1.4 GlusterFS概述

  • GlusterFS是Scale-Out存儲解決方案Gluster的核心,它是一個開源的分布式文件系統,具有強大的橫向擴展能力,通過擴展能夠支持數PB存儲容量和處理數千客戶端。GlusterFS借助TCP/IP或InfiniBand RDMA網絡將物理分布的存儲資源聚集在一起,使用單一全局命名空間來管理數據。
  • GlusterFS支持運行在任何標准IP網絡上標准應用程序的標准客戶端,用戶可以在全局統一的命令空間中使用NFS/CIFS等標准協議來訪問應用程序。GlusterFS使得用戶可擺脫原有的獨立,高成本的封閉存儲系統,能夠利用普通廉價的存儲設備來部署可集中管理,橫向擴展,虛擬化的存儲池,存儲容量可擴展至TB/PB級。
  • 目前glusterfs已被redhat收購,它的官方網站是:http://www.gluster.org/

超高性能(64個節點時吞吐量也就是帶寬甚至達到32GB/s)

QQ截圖20180325192227.png-293.6kB

1.5 GlusterFS企業主要應用場景

1.png-285.3kB

2.png-263.6kB

理論和實踐上分析,GlusterFS目前主要適用大文件存儲場景,對於小文件尤其是海量小文件(小於1M),存儲效率和訪問性能都表現不佳。海量小文件LOSF問題是工業界和學術界公認的難題,GlusterFS作為通用的分布式文件系統,並沒有對小文件作額外的優化措施(小於1M),性能不好也是可以理解的。

  • Media

文檔,圖片,音頻,視頻

  • Shared storage

雲存儲,虛擬化存儲,HPC(高性能計算)

  • Big data

日志文件,RFID(射頻識別)數據

二,部署安裝

2.1 GlusterFS 安裝前的准備

  1. 電腦一台,內存>=4G,可用磁盤空間大於50G
  2. 安裝VMWARE Workstation虛擬機軟件
  3. 安裝好四台CentOS-6-x86_64(6.2-6.8都可以)的虛擬機
  4. 基本系統:1核CPU+1024M內存+10G硬盤
  5. 網絡選擇:網絡地址轉換(NAT)
  6. 關閉iptables和SELinux
  7. 預裝glusterfs軟件包
描述 IP 主機名 需求
Linux_node1 192.168.200.150 mystorage01 多添加兩塊各10G的sdb和sdc
Linux_node2 192.168.200.151 mystorage02 多添加兩塊各10G的sdb和sdc
Linux_node3 192.168.200.152 mystorage03 多添加兩塊各10G的sdb和sdc
Linux_node4 192.168.200.153 mystorage04 多添加兩塊各10G的sdb和sdc
Linux_node5 192.168.200.154 WebServerClinet
 
  1. #為了實驗的准確性,請盡量和我用一個版本的Linux操作系統
  2. #並用實驗給的rpm包作為yum源
  3. [root@localhost rpm]# cat /etc/redhat-release
  4. CentOS release 6.5 (Final)
  5. [root@localhost rpm]# uname -r
  6. 2.6.32-431.el6.x86_64
  7. [root@localhost rpm]# pwd
  8. /root/rpm
  9. [root@localhost rpm]# ls
  10. dbench-4.0-12.el6.x86_64.rpm libaio-0.3.107-10.el6.x86_64.rpm
  11. glusterfs-3.7.20-1.el6.x86_64.rpm libevent-1.4.13-4.el6.x86_64.rpm
  12. glusterfs-api-3.7.20-1.el6.x86_64.rpm libgssglue-0.1-11.el6.x86_64.rpm
  13. glusterfs-api-devel-3.7.20-1.el6.x86_64.rpm libntirpc-1.3.1-1.el6.x86_64.rpm
  14. glusterfs-cli-3.7.20-1.el6.x86_64.rpm libntirpc-devel-1.3.1-1.el6.x86_64.rpm
  15. glusterfs-client-xlators-3.7.20-1.el6.x86_64.rpm libtirpc-0.2.1-13.el6_9.x86_64.rpm
  16. glusterfs-coreutils-0.0.1-0.1.git0c86f7f.el6.x86_64.rpm nfs-utils-1.2.3-75.el6_9.x86_64.rpm
  17. glusterfs-coreutils-0.2.0-1.el6_37.x86_64.rpm nfs-utils-lib-1.1.5-13.el6.x86_64.rpm
  18. glusterfs-devel-3.7.20-1.el6.x86_64.rpm python-argparse-1.2.1-2.1.el6.noarch.rpm
  19. glusterfs-extra-xlators-3.7.20-1.el6.x86_64.rpm python-gluster-3.7.20-1.el6.noarch.rpm
  20. glusterfs-fuse-3.7.20-1.el6.x86_64.rpm pyxattr-0.5.0-1.el6.x86_64.rpm
  21. glusterfs-ganesha-3.7.20-1.el6.x86_64.rpm repodata
  22. glusterfs-geo-replication-3.7.20-1.el6.x86_64.rpm rpcbind-0.2.0-13.el6_9.1.x86_64.rpm
  23. glusterfs-libs-3.7.20-1.el6.x86_64.rpm rsync-3.0.6-12.el6.x86_64.rpm
  24. glusterfs-rdma-3.7.20-1.el6.x86_64.rpm userspace-rcu-0.7.16-2.el6.x86_64.rpm
  25. glusterfs-resource-agents-3.7.20-1.el6.noarch.rpm userspace-rcu-0.7.7-1.el6.x86_64.rpm
  26. glusterfs-server-3.7.20-1.el6.x86_64.rpm userspace-rcu-devel-0.7.16-2.el6.x86_64.rpm
  27. keyutils-1.4-5.el6.x86_64.rpm userspace-rcu-devel-0.7.7-1.el6.x86_64.rpm
  28. keyutils-libs-1.4-5.el6.x86_64.rpm
  29. [root@localhost rpm]# yum -y install glusterfs-server glusterfs-cli glusterfs-geo-replication

2.2 GlusterFS 安裝

2.2.1 修改主機名

2.2.2 添加hosts文件實現集群主機之間相互能夠解析

  1. [root@glusterfs01 ~]# cat /etc/hosts
  2. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  3. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  4. 192.168.200.150 glusterfs01
  5. 192.168.200.151 glusterfs02
  6. 192.168.200.152 glusterfs03
  7. 192.168.200.153 glusterfs04

2.2.3 關閉selinux和防火牆

  1. #關閉selinux
  2. sed -i 's#SELINUX=enforcing#SELINUX=disabled#' /etc/sysconfig/selinux
  3. #關閉iptables
  4. service iptables stop
  5. chkconfig iptables off

2.2.4 利用教程附帶的rpm軟件包組,充當本地定制化yum源

  1. yum -y install createrepo
  2. yum -y install glusterfs-server glusterfs-cli glusterfs-geo-replication

2.3 配置glusterfs

2.3.1 查看glusterfs版本信息

  1. [root@glusterfs01 ~]# which glusterfs
  2. /usr/sbin/glusterfs
  3. [root@glusterfs01 ~]# glusterfs -V
  4. glusterfs 3.7.20 built on Jan 30 2017 15:39:27
  5. Repository revision: git://git.gluster.com/glusterfs.git
  6. Copyright (c) 2006-2013 Red Hat, Inc. <http://www.redhat.com/>
  7. GlusterFS comes with ABSOLUTELY NO WARRANTY.
  8. It is licensed to you under your choice of the GNU Lesser
  9. General Public License, version 3 or any later version (LGPLv3
  10. or later), or the GNU General Public License, version 2 (GPLv2),
  11. in all cases as published by the Free Software Foundation.

2.3.2 啟動停止服務

  1. [root@glusterfs01 ~]# /etc/init.d/glusterd status #查看服務狀態
  2. glusterd (pid 906) is running...
  3. [root@glusterfs01 ~]# /etc/init.d/glusterd stop #停止
  4. Stopping glusterd: [ OK ]
  5. [root@glusterfs01 ~]# /etc/init.d/glusterd status
  6. glusterd is stopped
  7. [root@glusterfs01 ~]# /etc/init.d/glusterd start #啟動
  8. Starting glusterd: [ OK ]
  9. [root@glusterfs01 ~]# /etc/init.d/glusterd status
  10. glusterd (pid 1356) is running...
  11. [root@glusterfs01 ~]# chkconfig glusrerd on #添加開機啟動

2.3.3 存儲主機加入信任存儲池

虛擬機添加信任存儲池
特別提示:只需要讓一個虛擬機進行添加操作即可。但自己並不需要添加信任自己

  1. #確保所有的虛擬機的glusterd服務都處於開啟狀態,然后執行如下操作
  2. [root@glusterfs01 ~]# gluster peer probe glusterfs02
  3. peer probe: success.
  4. [root@glusterfs01 ~]# gluster peer probe glusterfs03
  5. peer probe: success.
  6. [root@glusterfs01 ~]# gluster peer probe glusterfs04
  7. peer probe: success.

2.3.4 查看虛擬機信任狀態添加結果

  1. [root@glusterfs01 ~]# gluster peer status
  2. Number of Peers: 3
  3. Hostname: glusterfs02
  4. Uuid: 0b52290d-96b0-4b9c-988d-44062735a8a8
  5. State: Peer in Cluster (Connected)
  6. Hostname: glusterfs03
  7. Uuid: c5dd23d5-c93c-427c-811b-3255da3c9691
  8. State: Peer in Cluster (Connected)
  9. Hostname: glusterfs04
  10. Uuid: a43ac51b-641c-4fc4-be56-f6873423b462
  11. State: Peer in Cluster (Connected)

同學們可以查看每台虛擬機的信任狀態,他們此時彼此都應該已經互有信任記錄了

2.3.5 配置前的准備工作

  1. #鏈接光盤源,安裝xfs支持包(Centos7已經不再需要安裝)
  2. #所有都要裝
  3. yum -y install xfsprogs

在企業里我們還需要分區然后才能進行格式化。但是我們這里就省略了,我們直接格式化每台虛擬機的那塊10G硬盤

  1. [root@glusterfs01 ~]# mkfs.ext4 /dev/sdb
  2. mke2fs 1.41.12 (17-May-2010)
  3. /dev/sdb is entire device, not just one partition!
  4. Proceed anyway? (y,n) y
  5. Filesystem label=
  6. OS type: Linux
  7. Block size=4096 (log=2)
  8. Fragment size=4096 (log=2)
  9. Stride=0 blocks, Stripe width=0 blocks
  10. 655360 inodes, 2621440 blocks
  11. 131072 blocks (5.00%) reserved for the super user
  12. First data block=0
  13. Maximum filesystem blocks=2684354560
  14. 80 block groups
  15. 32768 blocks per group, 32768 fragments per group
  16. 8192 inodes per group
  17. Superblock backups stored on blocks:
  18. 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
  19. Writing inode tables: done
  20. Creating journal (32768 blocks): done
  21. Writing superblocks and filesystem accounting information: done
  22. This filesystem will be automatically checked every 28 mounts or
  23. 180 days, whichever comes first. Use tune2fs -c or -i to override.

在四台機器上執行mkdir -p /gluster/brick1 建立掛在塊設備的目錄
掛載磁盤到文件系統(4台都做,步驟相同)

  1. [root@glusterfs01 ~]# mkdir -p /gluster/brick1
  2. [root@glusterfs01 ~]# mount /dev/sdb /gluster/brick1
  3. [root@glusterfs01 ~]# df -h
  4. Filesystem Size Used Avail Use% Mounted on
  5. /dev/mapper/VolGroup-lv_root 18G 1.1G 16G 7% /
  6. tmpfs 491M 0 491M 0% /dev/shm
  7. /dev/sda1 485M 33M 427M 8% /boot
  8. /dev/sr0 4.2G 4.2G 0 100% /media/cdrom
  9. /dev/sdb 9.9G 151M 9.2G 2% /gluster/brick1

繼續重復以上步驟,將第二塊磁盤sdc格式化,並掛載到每台虛擬機的/gluster/brick2上

4台虛擬機加入開機自動掛載

  1. [root@glusterfs01 ~]# echo "mount /dev/sdb /gluster/brick1" >> /etc/rc.local
  2. [root@glusterfs01 ~]# echo "mount /dev/sdc /gluster/brick2" >> /etc/rc.local
  3. [root@glusterfs01 ~]# tail -2 /etc/rc.local
  4. mount /dev/sdb /gluster/brick1
  5. mount /dev/sdc /gluster/brick2

2.3.6 創建volume分布式卷

  • 基本卷:
    • 分布式卷(Distributed):
    • 復制卷(Replicated):
    • 條帶式卷(Striped):
  • 復合卷:
    • 分布式復制卷(Distributed Replicated):
    • 分布式條帶卷(Distributed Striped):
    • 復制條帶卷(Replicated Striped):
    • 分布式復制條帶卷(Distributed Replicated Striped):
  1. #創建分布式卷(在glusterfs01上操作)
  2. [root@glusterfs01 ~]# gluster volume create gs1 glusterfs01:/gluster/brick1 glusterfs02:/gluster/brick1 force
  3. volume create: gs1: success: please start the volume to access data
  4. #啟動創建的卷(在glusterfs01上操作)
  5. [root@glusterfs01 ~]# gluster volume start gs1
  6. volume start: gs1: success
  7. #然后我們發現4台虛擬機都能看到如下信息(在任意虛擬機上操作)
  8. [root@glusterfs04 ~]# gluster volume info
  9. Volume Name: gs1 #卷名
  10. Type: Distribute #分布式
  11. Volume ID: 0f0adf7a-3b8f-4016-ac72-83f633e90fac #ID號
  12. Status: Started #啟動狀態
  13. Number of Bricks: 2 #一共兩個塊設備
  14. Transport-type: tcp #tcp的連接方式
  15. Bricks: #塊信息
  16. Brick1: glusterfs01:/gluster/brick1
  17. Brick2: glusterfs02:/gluster/brick1
  18. Options Reconfigured:
  19. performance.readdir-ahead: on

2.3.7 volume的兩種掛載方式

(1)以glusterfs方式掛載

  1. #掛載卷到目錄(在glusterfs01上操作)
  2. [root@glusterfs01 ~]# mount -t glusterfs 127.0.0.1:/gs1 /mnt #將本地的分布式卷gs01掛載到/mnt目錄下
  3. [root@glusterfs01 ~]# df -h
  4. Filesystem Size Used Avail Use% Mounted on
  5. /dev/mapper/VolGroup-lv_root 18G 1.1G 16G 7% /
  6. tmpfs 491M 0 491M 0% /dev/shm
  7. /dev/sda1 485M 33M 427M 8% /boot
  8. /dev/sr0 4.2G 4.2G 0 100% /media/cdrom
  9. /dev/sdb 9.9G 151M 9.2G 2% /gluster/brick1
  10. 127.0.0.1:/gs1 20G 302M 19G 2% /mnt #掛載成功,我們看到磁盤空間已經整合
  11. #在掛載好的/mnt目錄里創建實驗文件(在glusterfs01上操作)
  12. [root@glusterfs01 ~]# touch /mnt/{1..5}
  13. [root@glusterfs01 ~]# ls /mnt
  14. 1 2 3 4 5
  15. #在其他虛擬機上掛載分布式卷gs1,查看同步掛載結果
  16. [root@glusterfs02 rpm]# mount -t glusterfs 127.0.0.1:/gs1 /mnt
  17. [root@glusterfs02 rpm]# ls /mnt
  18. 1 2 3 4 5
  19. [root@glusterfs03 rpm]# mount -t glusterfs 127.0.0.1:/gs1 /mnt
  20. [root@glusterfs03 rpm]# ls /mnt
  21. 1 2 3 4 5
  22. [root@glusterfs04 ~]# mount -t glusterfs 127.0.0.1:/gs1 /mnt
  23. [root@glusterfs04 ~]# ls /mnt
  24. 1 2 3 4 5

(2)以NFS方式進行掛載

在掛載之前我們先來看一下如何打開glusterfs的NFS掛載方式

  1. #在glusterfs01上執行如下操作
  2. [root@glusterfs01 ~]# gluster volume status #查看分布式卷的狀態
  3. Status of volume: gs1
  4. Gluster process TCP Port RDMA Port Online Pid
  5. ------------------------------------------------------------------------------
  6. Brick glusterfs01:/gluster/brick1 49152 0 Y 1911
  7. Brick glusterfs02:/gluster/brick1 49152 0 Y 1695
  8. NFS Server on localhost N/A N/A N N/A #本地分布式卷NFS掛載未開啟
  9. NFS Server on glusterfs04 2049 0 Y 2679
  10. NFS Server on glusterfs02 2049 0 Y 2600 #出現具體的端口就表明開啟了
  11. NFS Server on glusterfs03 2049 0 Y 2608
  12. Task Status of Volume gs1
  13. ------------------------------------------------------------------------------
  14. There are no active volume tasks

以上結果是是什么原因呢?
如果NFS Server的掛載端口顯示N/A表示未開啟掛載功能,這是由於要先進行nfs掛載是需要裝兩個nfs的軟件包的rpcbind和nfs-utils
當然就算系統裝了這兩個軟件包,那么我們也需要開啟rpcbind服務,然后在重啟glusterfs服務才能夠進行nfs掛載的操作。
現在我們就來開啟glusterfs01的nfs掛載功能,如下:

  1. #在glusterfs01上執行如下操作
  2. [root@glusterfs01 ~]# rpm -qa nfs-utils #查看是否安裝nfs-utils
  3. nfs-utils-1.2.3-75.el6_9.x86_64
  4. [root@glusterfs01 ~]# rpm -qa rpcbind #查看是否安裝rpcbind
  5. rpcbind-0.2.0-13.el6_9.1.x86_64
  6. [root@glusterfs01 ~]# /etc/init.d/rpcbind status #查看rpcbind服務狀態
  7. rpcbind is stopped
  8. [root@glusterfs01 ~]# /etc/init.d/rpcbind start #開啟rpcbind服務
  9. Starting rpcbind: [ OK ]
  10. [root@glusterfs01 ~]# /etc/init.d/glusterd stop #停止glusterd服務
  11. Stopping glusterd: [ OK ]
  12. [root@glusterfs01 ~]# /etc/init.d/glusterd start #開啟glusterd服務
  13. Starting glusterd: [ OK ]
  14. root@glusterfs01 ~]# gluster volume status #這里需要等幾秒再查看,就會發現nfs掛載方式開啟了
  15. Status of volume: gs1
  16. Gluster process TCP Port RDMA Port Online Pid
  17. ------------------------------------------------------------------------------
  18. Brick glusterfs01:/gluster/brick1 49152 0 Y 1911
  19. Brick glusterfs02:/gluster/brick1 49152 0 Y 1695
  20. NFS Server on localhost 2049 0 Y 2984 #已經開啟
  21. NFS Server on glusterfs04 2049 0 Y 2679
  22. NFS Server on glusterfs03 2049 0 Y 2608
  23. NFS Server on glusterfs02 2049 0 Y 2600
  24. Task Status of Volume gs1
  25. ------------------------------------------------------------------------------
  26. There are no active volume tasks

接下來,我們嘗試在准備好的第五台虛擬機WebServer上進行nfs方式的掛載

  1. #在Webserver上進行如下操作
  2. [root@WebServer ~]# rpm -qa nfs-utils #查看nfs-utils是否安裝
  3. nfs-utils-1.2.3-39.el6.x86_64
  4. [root@WebServer ~]# mount -t nfs 192.168.200.150:/gs1 /mnt #以nfs方式遠程掛載分布式卷
  5. mount.nfs: rpc.statd is not running but is required for remote locking.
  6. mount.nfs: Either use '-o nolock' to keep locks local, or start statd.
  7. mount.nfs: an incorrect mount option was specified #根據提示我們加上-o nolock參數
  8. [root@WebServer ~]# mount -o nolock -t nfs 192.168.200.150:/gs1 /mnt
  9. [root@WebServer ~]# ls /mnt #掛載成功
  10. 1 2 3 4 5 6 666 sss yunjisuan
  11. [root@WebServer ~]# touch /mnt/benet #創建文件測試
  12. [root@WebServer ~]# ls /mnt
  13. 1 2 3 4 5 6 666 benet sss yunjisuan
  14. #在glusterfs任意虛擬機上進行如下操作
  15. [root@glusterfs04 ~]# mount -t glusterfs 127.0.0.1:/gs1 /mnt
  16. [root@glusterfs04 ~]# ls /mnt
  17. 1 2 3 4 5 6 666 benet sss yunjisuan #數據已經同步

2.3.8 創建分布式復制卷

  1. #在任意一台gluster虛擬機上進行如下操作
  2. [root@glusterfs01 ~]# gluster volume create gs2 replica 2 glusterfs03:/gluster/brick1 glusterfs04:/gluster/brick1 force
  3. volume create: gs2: success: please start the volume to access data
  4. [root@glusterfs01 ~]# gluster volume info gs2
  5. Volume Name: gs2
  6. Type: Replicate #復制卷
  7. Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
  8. Status: Created
  9. Number of Bricks: 1 x 2 = 2
  10. Transport-type: tcp
  11. Bricks:
  12. Brick1: glusterfs03:/gluster/brick1
  13. Brick2: glusterfs04:/gluster/brick1
  14. Options Reconfigured:
  15. performance.readdir-ahead: on
  16. [root@glusterfs01 ~]# gluster volume start gs2 #啟動卷
  17. volume start: gs2: success

2.3.9 創建分布式條帶卷

  1. [root@glusterfs01 ~]# gluster volume create gs3 stripe 2 glusterfs01:/gluster/brick2 glusterfs02:/gluster/brick2 force
  2. volume create: gs3: success: please start the volume to access data
  3. [root@glusterfs01 ~]# gluster volume info gs3
  4. Volume Name: gs3
  5. Type: Stripe #條帶卷
  6. Volume ID: 6d2e27c7-f5a1-4473-9df8-a7261851a2ed
  7. Status: Created
  8. Number of Bricks: 1 x 2 = 2
  9. Transport-type: tcp
  10. Bricks:
  11. Brick1: glusterfs01:/gluster/brick2
  12. Brick2: glusterfs02:/gluster/brick2
  13. Options Reconfigured:
  14. performance.readdir-ahead: on
  15. [root@glusterfs01 ~]# gluster volume start gs3 #啟動卷
  16. volume start: gs3: success

三,進行卷的數據寫入測試

在WebServer服務器掛載創建的三種類型卷gs1,gs2,gs3,進行數據寫入測試

3.1 分布式卷gs1的數據寫入測試

  1. #在WebServer上進行數據寫入操作
  2. [root@WebServer ~]# mount -o nolock -t nfs 192.168.200.150:/gs1 /mnt
  3. [root@WebServer ~]# df -h
  4. Filesystem Size Used Avail Use% Mounted on
  5. /dev/mapper/VolGroup-lv_root 18G 1014M 16G 7% /
  6. tmpfs 491M 0 491M 0% /dev/shm
  7. /dev/sda1 485M 33M 427M 8% /boot
  8. /dev/sr0 4.2G 4.2G 0 100% /media/cdrom
  9. 192.168.200.150:/gs1 20G 301M 19G 2% /mnt
  10. [root@WebServer ~]# touch /mnt/{1..10}
  11. [root@WebServer ~]# ls /mnt/
  12. 1 10 2 3 4 5 6 7 8 9
  13. #在glusterfs01和glusterfs02上進行查看(看看數據到底寫入了哪個盤)
  14. [root@glusterfs01 ~]# ls /gluster/brick1
  15. 1 5 7 8 9
  16. [root@glusterfs02 ~]# ls /gluster/brick1
  17. 10 2 3 4 6

結論:分布式卷的數據存儲方式是將數據平均寫入到每個整合的磁盤中,類似於raid0,寫入速度快,但這樣磁盤一旦損壞沒有糾錯能力。

3.2 分布式復制卷gs2的數據寫入測試

  1. #在WebServer上進行數據寫入操作
  2. [root@WebServer ~]# mount -o nolock -t nfs 192.168.200.150:/gs2 /mnt
  3. [root@WebServer ~]# df -h
  4. Filesystem Size Used Avail Use% Mounted on
  5. /dev/mapper/VolGroup-lv_root 18G 1014M 16G 7% /
  6. tmpfs 491M 0 491M 0% /dev/shm
  7. /dev/sda1 485M 33M 427M 8% /boot
  8. /dev/sr0 4.2G 4.2G 0 100% /media/cdrom
  9. 192.168.200.150:/gs2 9.9G 151M 9.2G 2% /mnt #可用容量減半
  10. [root@WebServer ~]# ls /mnt
  11. lost+found
  12. [root@WebServer ~]# touch /mnt/{1..10}
  13. [root@WebServer ~]# ls /mnt
  14. 1 10 2 3 4 5 6 7 8 9 lost+found
  15. #在glusterfs03和glusterfs04上進行查看(看看數據到底寫入了哪個盤)
  16. [root@glusterfs03 ~]# ls /gluster/brick1
  17. 1 10 2 3 4 5 6 7 8 9 lost+found
  18. [root@glusterfs04 ~]# ls /gluster/brick1
  19. 1 10 2 3 4 5 6 7 8 9 lost+found

結論:分布式復制卷的數據存儲方式為,每個整合的磁盤中都寫入同樣的數據內容,類似於raid1,數據非常安全,讀取性能高,占磁盤容量。

3.3 分布式條帶卷gs3的數據寫入測試

  1. #在WebServer上進行數據寫入操作
  2. [root@WebServer ~]# umount /mnt
  3. [root@WebServer ~]# mount -o nolock -t nfs 192.168.200.150:/gs3 /mnt
  4. [root@WebServer ~]# df -h
  5. Filesystem Size Used Avail Use% Mounted on
  6. /dev/mapper/VolGroup-lv_root 18G 1014M 16G 7% /
  7. tmpfs 491M 0 491M 0% /dev/shm
  8. /dev/sda1 485M 33M 427M 8% /boot
  9. /dev/sr0 4.2G 4.2G 0 100% /media/cdrom
  10. 192.168.200.150:/gs3 20G 301M 19G 2% /mnt
  11. [root@WebServer ~]# dd if=/dev/zero of=/root/test bs=1024 count=262144 #創建大小為256M的文件
  12. 262144+0 records in
  13. 262144+0 records out
  14. 268435456 bytes (268 MB) copied, 1.81006 s, 148 MB/s
  15. [root@WebServer ~]# du -sh test
  16. 256M test
  17. [root@WebServer ~]# cp test /mnt/ #復制到/mnt目錄下
  18. [root@WebServer ~]# ls /mnt
  19. test
  20. [root@WebServer ~]# du -sh /mnt/test #查看大小為256M
  21. 256M /mnt/test
  22. #在glusterfs01和glusterfs02上進行查看(看看數據到底是怎么存的)
  23. [root@glusterfs01 ~]# du -sh /gluster/brick2/test
  24. 129M /gluster/brick2/test
  25. [root@glusterfs02 ~]# du -sh /gluster/brick2/test
  26. 129M /gluster/brick2/test

結論:我們發現分布式條帶卷,是將數據的容量平均分配到了每個整合的磁盤節點上。大幅提高大文件的並發讀訪問。

四,存儲卷中brick塊設備的擴容

4.1 分布式復制卷的擴容

  1. [root@glusterfs01 ~]# gluster volume add-brick gs2 replica 2 glusterfs03:/gluster/brick2 glusterfs04:/gluster/brick2 force #添加兩個塊設備
  2. volume add-brick: success
  3. [root@glusterfs01 ~]# gluster volume info gs2
  4. Volume Name: gs2
  5. Type: Distributed-Replicate
  6. Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
  7. Status: Started
  8. Number of Bricks: 2 x 2 = 4 #已經擴容
  9. Transport-type: tcp
  10. Bricks:
  11. Brick1: glusterfs03:/gluster/brick1
  12. Brick2: glusterfs04:/gluster/brick1
  13. Brick3: glusterfs03:/gluster/brick2
  14. Brick4: glusterfs04:/gluster/brick2
  15. Options Reconfigured:
  16. performance.readdir-ahead: on

特別提示:
對分布式復制卷和分布式條帶卷進行擴容時,要特別注意,如果創建卷之初的時候選擇的是replica 2 或者stripe 2。那么擴容時,就必須一次性擴容兩個或兩個的倍數的塊設備。
例如你給一個分布式復制卷的replica為2,你在增加bricks的時候數量必須為2,4,6,8等。

4.2 查看擴容后的容量並進行寫入測試

  1. #在WebServer上掛載gs2並查看掛載目錄的容量
  2. [root@WebServer ~]# umount /mnt
  3. [root@WebServer ~]# mount -o nolock -t nfs 192.168.200.150:/gs2 /mnt
  4. [root@WebServer ~]# df -h
  5. Filesystem Size Used Avail Use% Mounted on
  6. /dev/mapper/VolGroup-lv_root 18G 1.3G 16G 8% /
  7. tmpfs 491M 0 491M 0% /dev/shm
  8. /dev/sda1 485M 33M 427M 8% /boot
  9. /dev/sr0 4.2G 4.2G 0 100% /media/cdrom
  10. 192.168.200.150:/gs2 20G 301M 19G 2% /mnt #已經擴容

再次寫入數據

  1. #在WebServer上進行數據寫入操作
  2. [root@WebServer ~]# touch /mnt/{11..20}
  3. [root@WebServer ~]# ls /mnt
  4. 1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9 lost+found
  5. #在glusterfs03和glusterfs04上查看數據存到哪里去了
  6. [root@glusterfs03 ~]# gluster volume info gs2
  7. Volume Name: gs2
  8. Type: Distributed-Replicate
  9. Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
  10. Status: Started
  11. Number of Bricks: 2 x 2 = 4
  12. Transport-type: tcp
  13. Bricks:
  14. Brick1: glusterfs03:/gluster/brick1 #組成gs2的塊設備就在03和04上
  15. Brick2: glusterfs04:/gluster/brick1
  16. Brick3: glusterfs03:/gluster/brick2
  17. Brick4: glusterfs04:/gluster/brick2
  18. Options Reconfigured:
  19. performance.readdir-ahead: on
  20. [root@glusterfs03 ~]# ls /gluster/brick1
  21. 1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9 lost+found
  22. [root@glusterfs03 ~]# ls /gluster/brick2
  23. lost+found #什么都沒有
  24. [root@glusterfs04 ~]# ls /gluster/brick1
  25. 1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9 lost+found
  26. [root@glusterfs04 ~]# ls /gluster/brick2
  27. lost+found #還是什么都沒有

通過對擴容的gs2進行寫入測試,我們發現數據並沒有被寫入到新加入的塊設備中,這是為甚什么?
這是因為,為了數據的安全,新擴容塊設備的卷,默認必須先做一次磁盤平衡(塊設備同步),如此才能正常開始使用。

4.3 進行磁盤存儲的平衡

注意:平衡布局是很有必要的,因為布局結構是靜態的,當新的bricks加入現有卷,新創建的文件會分布到舊的bricks中,所以需要平衡布局結構,使新加入的bricks生效。布局平衡只是使新布局生效,並不會在新的布局移動老的數據,如果你想在新布局生效后,重新平衡卷中的數據,還需要對卷中的數據進行平衡。

  1. #對gs2進行磁盤存儲平衡
  2. [root@glusterfs01 ~]# gluster volume rebalance gs2 start
  3. volume rebalance: gs2: success: Rebalance on gs2 has been started successfully. Use rebalance status command to check status of the rebalance process.
  4. ID: 0024338c-84df-4edb-b68c-107415a27506
  5. #檢查gs2塊設備磁盤平衡結果
  6. [root@glusterfs03 ~]# ls /gluster/brick1
  7. 10 12 14 15 16 17 2 3 4 6 lost+found
  8. [root@glusterfs03 ~]# ls /gluster/brick2
  9. 1 11 13 18 19 20 5 7 8 9 lost+found
  10. [root@glusterfs04 ~]# ls /gluster/brick1
  11. 10 12 14 15 16 17 2 3 4 6 lost+found
  12. [root@glusterfs04 ~]# ls /gluster/brick2
  13. 1 11 13 18 19 20 5 7 8 9 lost+found

執行磁盤存儲平衡以后,我們發現數據被復制成了4份在4個塊設備中。

五,存儲卷的縮減與刪除

(1)對存儲卷中的brick進行縮減

注意:你可能想在線縮小卷的大小,例如:當硬件損壞或者網絡故障的時候,你可能想在卷中移除相關的bricks。注意,當你移除bricks的時候,你在gluster的掛載點將不能繼續訪問是數據,只有配置文件中的信息移除后你才能繼續訪問bricks的數據。當移除分布式復制卷或者分布式條帶卷的時候,移除的bricks數目必須是replica或者stripe的倍數。例如:一個分布式條帶卷的stripe是2,當你移除bricks的時候必須是2,4,6,8等。

  1. #先停止卷gs2
  2. [root@glusterfs01 ~]# gluster volume stop gs2
  3. Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
  4. volume stop: gs2: success
  5. #然后移除卷,因為是復制卷且replica為2,因此每次移除必須是2的倍數
  6. [root@glusterfs01 ~]# gluster volume remove-brick gs2 replica 2 glusterfs03:/gluster/brick2 glusterfs04:/gluster/brick2 force
  7. Removing brick(s) can result in data loss. Do you want to Continue? (y/n) y
  8. volume remove-brick commit force: success
  9. #我們發現gs2的卷已經被移除
  10. [root@glusterfs01 ~]# gluster volume info gs2
  11. Volume Name: gs2
  12. Type: Replicate
  13. Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
  14. Status: Stopped
  15. Number of Bricks: 1 x 2 = 2
  16. Transport-type: tcp
  17. Bricks:
  18. Brick1: glusterfs03:/gluster/brick1
  19. Brick2: glusterfs04:/gluster/brick1
  20. Options Reconfigured:
  21. performance.readdir-ahead: on
  22. #重新啟動卷gs2
  23. [root@glusterfs01 ~]# gluster volume start gs2
  24. volume start: gs2: success

(2)對存儲卷進行刪除

  1. #停止卷gs1
  2. [root@glusterfs01 ~]# gluster volume stop gs1
  3. Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
  4. volume stop: gs1: success
  5. #刪除卷gs1
  6. [root@glusterfs01 ~]# gluster volume delete gs1
  7. Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
  8. volume delete: gs1: success
  9. #查看卷信息,發現gs1已經沒了
  10. [root@glusterfs01 ~]# gluster volume info
  11. Volume Name: gs2
  12. Type: Replicate
  13. Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
  14. Status: Started
  15. Number of Bricks: 1 x 2 = 2
  16. Transport-type: tcp
  17. Bricks:
  18. Brick1: glusterfs03:/gluster/brick1
  19. Brick2: glusterfs04:/gluster/brick1
  20. Options Reconfigured:
  21. performance.readdir-ahead: on
  22. Volume Name: gs3
  23. Type: Stripe
  24. Volume ID: 6d2e27c7-f5a1-4473-9df8-a7261851a2ed
  25. Status: Started
  26. Number of Bricks: 1 x 2 = 2
  27. Transport-type: tcp
  28. Bricks:
  29. Brick1: glusterfs01:/gluster/brick2
  30. Brick2: glusterfs02:/gluster/brick2
  31. Options Reconfigured:
  32. performance.readdir-ahead: on

特別提示:
無論是縮減卷還是刪除卷,並不會是清除卷中的數據。數據仍舊會保存在對應磁盤上。

六,構建企業級分布式存儲

6.1 硬件要求

一般選擇2U的機型,磁盤STAT盤4T,如果I/O要求比較高,可以采購SSD固態硬盤。為了充分保證系統的穩定性和性能,要求所有glusterfs服務器硬件配置盡量一致,尤其是硬盤數量和大小。機器的RAID卡需要帶電池,緩存越大,性能越好。一般情況下,建議做RAID10,如果出於空間要求考慮,需要做RAID5,建議最好能有1-2塊硬盤的熱備盤。

6.2 系統要求和分區划分

系統要求使用CentOS6.x,安裝完成后升級到最新版本,安裝的時候,不要使用LVM,建議/boot分區200M,根分區100G,swap分區和內存一樣大小,剩余空間給gluster使用,划分單獨的硬盤空間。系統安裝軟件沒有特殊要求,建議除了開發工具和基本的管理軟件,其他軟件一律不裝。

6.3 網絡環境

網絡要求全部千兆環境,gluster服務器至少有2塊網卡,1塊網卡綁定供gluster使用,剩余一塊分配管理網絡ip,用於系統管理。如果有條件購買萬兆交換機,服務器配置萬兆網卡,存儲性能會更好。網絡方面如果安全性要求高,可以多網卡綁定。

6.4 服務器擺放分布

服務器主備機器要放在不同的機櫃,連接不同的交換機,即使一個機櫃出現問題,還有一份數據正常訪問。

QQ截圖20180320231222.png-260.7kB

QQ截圖20180320231352.png-200.6kB

6.5 構建高性能,高可用存儲

一般在企業中,采用的是分布式復制卷,因為有數據備份,數據相對安全,分布式條帶卷目前對glusterfs來說沒有完全成熟,存在一定的是數據安全風險。

6.5.1 開啟防火牆端口

一般在企業應用中Linux防火牆是打開的,開通服務器之間訪問的端口

  1. iptables -I INPUT -p tcp --dport 24007:24011 -j ACCEPT
  2. iptables -I INPUT -p tcp --dport 49152:49162 -j ACCEPT
  1. [root@glusterfs01 ~]# cat /etc/glusterfs/glusterd.vol
  2. volume management
  3. type mgmt/glusterd
  4. option working-directory /var/lib/glusterd
  5. option transport-type socket,rdma
  6. option transport.socket.keepalive-time 10
  7. option transport.socket.keepalive-interval 2
  8. option transport.socket.read-fail-log off
  9. option ping-timeout 0
  10. option event-threads 1
  11. # option base-port 49152 #默認端口可以在這里改,因為這個端口可能會和企業里的kvm端口沖突

6.5.2 Glusterfs文件系統優化

參數項目 說明 缺省值 合法值
Auth.allow IP訪問授權 *(allow all) IP地址
Cluster.min-free-disk 剩余磁盤空間閾值 10% 百分比
Cluster.stripe-block-size 條帶大小 128KB 字節
Network.frame-timeout 請求等待時間 1800s 0-1800
Network.ping-timeout 客戶端等待時間 42s 0-42
Nfs.disabled 關閉NFS服務 Off Off|on
Performance.io-thread-count IO線程數 16 0-65
Performance.cache-refresh-timeout 緩存校驗周期 1s 0-61
Performance.cache-size 讀緩存大小 32MB 字節

Performance.quick-read:優化讀取小文件的性能
Performance.read-ahead:用預讀的方式提高讀取的性能,有利於應用頻繁持續性的訪問文件,當應用完成當前數據塊讀取的時候,下一個數據塊就已經准備好了。
Performance.write-behind:寫入數據時,先寫入緩存內,再寫入硬盤內,以提高寫入的性能。
Performance.io-cache:緩存已經被讀過的。

調整方法:

Glusster volume set <卷> <參數>

  1. [root@glusterfs01 ~]# gluster volume info gs2
  2. Volume Name: gs2
  3. Type: Replicate
  4. Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
  5. Status: Started
  6. Number of Bricks: 1 x 2 = 2
  7. Transport-type: tcp
  8. Bricks:
  9. Brick1: glusterfs03:/gluster/brick1
  10. Brick2: glusterfs04:/gluster/brick1
  11. Options Reconfigured:
  12. performance.readdir-ahead: on
  13. [root@glusterfs01 ~]# gluster volume set gs2 performance.read-ahead on #設置預緩存優化
  14. volume set: success
  15. [root@glusterfs01 ~]# gluster volume info gs2
  16. Volume Name: gs2
  17. Type: Replicate
  18. Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
  19. Status: Started
  20. Number of Bricks: 1 x 2 = 2
  21. Transport-type: tcp
  22. Bricks:
  23. Brick1: glusterfs03:/gluster/brick1
  24. Brick2: glusterfs04:/gluster/brick1
  25. Options Reconfigured:
  26. performance.read-ahead: on #已經添加上了
  27. performance.readdir-ahead: on
  28. [root@glusterfs01 ~]# gluster volume set gs2 performance.cache-size 256MB #設置讀緩存大小
  29. volume set: success
  30. [root@glusterfs01 ~]# gluster volume info gs2
  31. Volume Name: gs2
  32. Type: Replicate
  33. Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
  34. Status: Started
  35. Number of Bricks: 1 x 2 = 2
  36. Transport-type: tcp
  37. Bricks:
  38. Brick1: glusterfs03:/gluster/brick1
  39. Brick2: glusterfs04:/gluster/brick1
  40. Options Reconfigured:
  41. performance.cache-size: 256MB #已經添加上了
  42. performance.read-ahead: on
  43. performance.readdir-ahead: on

6.5.3 監控及日常維護

使用Zabbix自帶模板即可。Cpu,內存,主機存活,磁盤空間,主機運行時間,系統load。日常情況要查看服務器的監控值,遇到報警要及時處理。

  1. #以下命令在復制卷的場景下才會有
  2. #gluster volume status gs2 查看節點NFS是否在線
  3. (開沒開端口)
  4. #gluster volume heal gs2 full 啟動完全修復
  5. #gluster volume heal gs2 info 查看需要修復的文件
  6. #gluster volume heal gs2 info healed 查看修復成功的文件
  7. #gluster volume heal gs2 info heal-failed 查看修復失敗文件
  8. #gluster volume heal gs2 info split-brain 查看腦裂的文件
  9. #gluster volume quota gs2 enable --激活quota功能
  10. #gluster volume quota gs2 disable --關閉quota功能
  11. #gluster volume quota gs2 limit-usage /data 10GB --/gs2/data 目錄限制
  12. #gluster volume quota gs2 list --quota 信息列表
  13. #gluster volume quota gs2 list /data --限制目錄的quota信息
  14. #gluster volume set gs2 features.quota-timeout 5 --設置信息的超時事實上時間
  15. #gluster volume quota gs2 remove /data -刪除某個目錄的quota設置
  16. 備注:
  17. 1quota 功能,主要是對掛載點下的某個目錄進行空間限額。如:/mnt/glusterfs/data目錄,而不是對組成卷組的空間進行限制

七 生產環境遇到常見故障處理

7.1 硬盤故障

因為底層做了raid配置,有硬件故障,直接更換硬盤,會自動同步數據。(raid5)

7.2 一台主機故障

一台節點故障的情況包括以下類型:

1,物理故障
2,同時有多塊硬盤故障,造成是數據丟失
3,系統損壞不可修復

解決方法:

找一台完全一樣的機器,至少要保證硬盤數量大小一致,安裝系統,配置和故障機同樣的ip,安裝gluster軟件,保證配置一樣,在其他健康的節點上執行命令gluster peer status,查看故障服務器的uuid

  1. #例如:
  2. [root@glusterfs03 ~]# gluster peer status
  3. Number of Peers: 3
  4. Hostname: glusterfs02
  5. Uuid: 0b52290d-96b0-4b9c-988d-44062735a8a8
  6. State: Peer in Cluster (Connected)
  7. Hostname: glusterfs04
  8. Uuid: a43ac51b-641c-4fc4-be56-f6873423b462
  9. State: Peer in Cluster (Connected)
  10. Hostname: glusterfs01
  11. Uuid: 198f2c7c-1104-4671-8989-b430b77540e9
  12. State: Peer in Cluster (Connected)
  13. [root@glusterfs03 ~]#

修改新加機器的/var/lib/glusterd/glusterd.info和故障機器的一樣

  1. [root@glusterfs04 ~]# cat /var/lib/glusterd/glusterd.info
  2. UUID=a43ac51b-641c-4fc4-be56-f6873423b462
  3. operating-version=30712

在新機器掛載目錄上執行磁盤故障的操作(任意節點)

  1. [root@glusterfs04 ~]# gluster volume heal gs2 full
  2. Launching heal operation to perform full self heal on volume gs2 has been successful
  3. Use heal info commands to check status

就會自動開始同步,但是同步的時候會影響整個系統的性能
可以查看狀態

  1. [root@glusterfs04 ~]# gluster volume heal gs2 info
  2. Brick glusterfs03:/gluster/brick1
  3. Status: Connected
  4. Number of entries: 0
  5. Brick glusterfs04:/gluster/brick1
  6. Status: Connected
  7. Number of entries: 0
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM