一,分布式文件系統理論基礎
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)
1.5 GlusterFS企業主要應用場景
理論和實踐上分析,GlusterFS目前主要適用大文件存儲場景,對於小文件尤其是海量小文件(小於1M),存儲效率和訪問性能都表現不佳。海量小文件LOSF問題是工業界和學術界公認的難題,GlusterFS作為通用的分布式文件系統,並沒有對小文件作額外的優化措施(小於1M),性能不好也是可以理解的。
- Media
文檔,圖片,音頻,視頻
- Shared storage
雲存儲,虛擬化存儲,HPC(高性能計算)
- Big data
日志文件,RFID(射頻識別)數據
二,部署安裝
2.1 GlusterFS 安裝前的准備
- 電腦一台,內存>=4G,可用磁盤空間大於50G
- 安裝VMWARE Workstation虛擬機軟件
- 安裝好四台CentOS-6-x86_64(6.2-6.8都可以)的虛擬機
- 基本系統:1核CPU+1024M內存+10G硬盤
- 網絡選擇:網絡地址轉換(NAT)
- 關閉iptables和SELinux
- 預裝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 | 無 |
#為了實驗的准確性,請盡量和我用一個版本的Linux操作系統
#並用實驗給的rpm包作為yum源
[root@localhost rpm]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@localhost rpm]# uname -r
2.6.32-431.el6.x86_64
[root@localhost rpm]# pwd
/root/rpm
[root@localhost rpm]# ls
dbench-4.0-12.el6.x86_64.rpm libaio-0.3.107-10.el6.x86_64.rpm
glusterfs-3.7.20-1.el6.x86_64.rpm libevent-1.4.13-4.el6.x86_64.rpm
glusterfs-api-3.7.20-1.el6.x86_64.rpm libgssglue-0.1-11.el6.x86_64.rpm
glusterfs-api-devel-3.7.20-1.el6.x86_64.rpm libntirpc-1.3.1-1.el6.x86_64.rpm
glusterfs-cli-3.7.20-1.el6.x86_64.rpm libntirpc-devel-1.3.1-1.el6.x86_64.rpm
glusterfs-client-xlators-3.7.20-1.el6.x86_64.rpm libtirpc-0.2.1-13.el6_9.x86_64.rpm
glusterfs-coreutils-0.0.1-0.1.git0c86f7f.el6.x86_64.rpm nfs-utils-1.2.3-75.el6_9.x86_64.rpm
glusterfs-coreutils-0.2.0-1.el6_37.x86_64.rpm nfs-utils-lib-1.1.5-13.el6.x86_64.rpm
glusterfs-devel-3.7.20-1.el6.x86_64.rpm python-argparse-1.2.1-2.1.el6.noarch.rpm
glusterfs-extra-xlators-3.7.20-1.el6.x86_64.rpm python-gluster-3.7.20-1.el6.noarch.rpm
glusterfs-fuse-3.7.20-1.el6.x86_64.rpm pyxattr-0.5.0-1.el6.x86_64.rpm
glusterfs-ganesha-3.7.20-1.el6.x86_64.rpm repodata
glusterfs-geo-replication-3.7.20-1.el6.x86_64.rpm rpcbind-0.2.0-13.el6_9.1.x86_64.rpm
glusterfs-libs-3.7.20-1.el6.x86_64.rpm rsync-3.0.6-12.el6.x86_64.rpm
glusterfs-rdma-3.7.20-1.el6.x86_64.rpm userspace-rcu-0.7.16-2.el6.x86_64.rpm
glusterfs-resource-agents-3.7.20-1.el6.noarch.rpm userspace-rcu-0.7.7-1.el6.x86_64.rpm
glusterfs-server-3.7.20-1.el6.x86_64.rpm userspace-rcu-devel-0.7.16-2.el6.x86_64.rpm
keyutils-1.4-5.el6.x86_64.rpm userspace-rcu-devel-0.7.7-1.el6.x86_64.rpm
keyutils-libs-1.4-5.el6.x86_64.rpm
[root@localhost rpm]# yum -y install glusterfs-server glusterfs-cli glusterfs-geo-replication
2.2 GlusterFS 安裝
2.2.1 修改主機名
2.2.2 添加hosts文件實現集群主機之間相互能夠解析
[root@glusterfs01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.150 glusterfs01
192.168.200.151 glusterfs02
192.168.200.152 glusterfs03
192.168.200.153 glusterfs04
2.2.3 關閉selinux和防火牆
#關閉selinux
sed -i 's#SELINUX=enforcing#SELINUX=disabled#' /etc/sysconfig/selinux
#關閉iptables
service iptables stop
chkconfig iptables off
2.2.4 利用教程附帶的rpm軟件包組,充當本地定制化yum源
yum -y install createrepo
yum -y install glusterfs-server glusterfs-cli glusterfs-geo-replication
2.3 配置glusterfs
2.3.1 查看glusterfs版本信息
[root@glusterfs01 ~]# which glusterfs
/usr/sbin/glusterfs
[root@glusterfs01 ~]# glusterfs -V
glusterfs 3.7.20 built on Jan 30 2017 15:39:27
Repository revision: git://git.gluster.com/glusterfs.git
Copyright (c) 2006-2013 Red Hat, Inc. <http://www.redhat.com/>
GlusterFS comes with ABSOLUTELY NO WARRANTY.
It is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3
or later), or the GNU General Public License, version 2 (GPLv2),
in all cases as published by the Free Software Foundation.
2.3.2 啟動停止服務
[root@glusterfs01 ~]# /etc/init.d/glusterd status #查看服務狀態
glusterd (pid 906) is running...
[root@glusterfs01 ~]# /etc/init.d/glusterd stop #停止
Stopping glusterd: [ OK ]
[root@glusterfs01 ~]# /etc/init.d/glusterd status
glusterd is stopped
[root@glusterfs01 ~]# /etc/init.d/glusterd start #啟動
Starting glusterd: [ OK ]
[root@glusterfs01 ~]# /etc/init.d/glusterd status
glusterd (pid 1356) is running...
[root@glusterfs01 ~]# chkconfig glusrerd on #添加開機啟動
2.3.3 存儲主機加入信任存儲池
虛擬機添加信任存儲池
特別提示:只需要讓一個虛擬機進行添加操作即可。但自己並不需要添加信任自己
#確保所有的虛擬機的glusterd服務都處於開啟狀態,然后執行如下操作
[root@glusterfs01 ~]# gluster peer probe glusterfs02
peer probe: success.
[root@glusterfs01 ~]# gluster peer probe glusterfs03
peer probe: success.
[root@glusterfs01 ~]# gluster peer probe glusterfs04
peer probe: success.
2.3.4 查看虛擬機信任狀態添加結果
[root@glusterfs01 ~]# gluster peer status
Number of Peers: 3
Hostname: glusterfs02
Uuid: 0b52290d-96b0-4b9c-988d-44062735a8a8
State: Peer in Cluster (Connected)
Hostname: glusterfs03
Uuid: c5dd23d5-c93c-427c-811b-3255da3c9691
State: Peer in Cluster (Connected)
Hostname: glusterfs04
Uuid: a43ac51b-641c-4fc4-be56-f6873423b462
State: Peer in Cluster (Connected)
同學們可以查看每台虛擬機的信任狀態,他們此時彼此都應該已經互有信任記錄了
2.3.5 配置前的准備工作
#鏈接光盤源,安裝xfs支持包(Centos7已經不再需要安裝)
#所有都要裝
yum -y install xfsprogs
在企業里我們還需要分區然后才能進行格式化。但是我們這里就省略了,我們直接格式化每台虛擬機的那塊10G硬盤
[root@glusterfs01 ~]# mkfs.ext4 /dev/sdb
mke2fs 1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
在四台機器上執行mkdir -p /gluster/brick1 建立掛在塊設備的目錄
掛載磁盤到文件系統(4台都做,步驟相同)
[root@glusterfs01 ~]# mkdir -p /gluster/brick1
[root@glusterfs01 ~]# mount /dev/sdb /gluster/brick1
[root@glusterfs01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 1.1G 16G 7% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/sr0 4.2G 4.2G 0 100% /media/cdrom
/dev/sdb 9.9G 151M 9.2G 2% /gluster/brick1
繼續重復以上步驟,將第二塊磁盤sdc格式化,並掛載到每台虛擬機的/gluster/brick2上
4台虛擬機加入開機自動掛載
[root@glusterfs01 ~]# echo "mount /dev/sdb /gluster/brick1" >> /etc/rc.local
[root@glusterfs01 ~]# echo "mount /dev/sdc /gluster/brick2" >> /etc/rc.local
[root@glusterfs01 ~]# tail -2 /etc/rc.local
mount /dev/sdb /gluster/brick1
mount /dev/sdc /gluster/brick2
2.3.6 創建volume分布式卷
- 基本卷:
- 分布式卷(Distributed):
- 復制卷(Replicated):
- 條帶式卷(Striped):
- 復合卷:
- 分布式復制卷(Distributed Replicated):
- 分布式條帶卷(Distributed Striped):
- 復制條帶卷(Replicated Striped):
- 分布式復制條帶卷(Distributed Replicated Striped):
#創建分布式卷(在glusterfs01上操作)
[root@glusterfs01 ~]# gluster volume create gs1 glusterfs01:/gluster/brick1 glusterfs02:/gluster/brick1 force
volume create: gs1: success: please start the volume to access data
#啟動創建的卷(在glusterfs01上操作)
[root@glusterfs01 ~]# gluster volume start gs1
volume start: gs1: success
#然后我們發現4台虛擬機都能看到如下信息(在任意虛擬機上操作)
[root@glusterfs04 ~]# gluster volume info
Volume Name: gs1 #卷名
Type: Distribute #分布式
Volume ID: 0f0adf7a-3b8f-4016-ac72-83f633e90fac #ID號
Status: Started #啟動狀態
Number of Bricks: 2 #一共兩個塊設備
Transport-type: tcp #tcp的連接方式
Bricks: #塊信息
Brick1: glusterfs01:/gluster/brick1
Brick2: glusterfs02:/gluster/brick1
Options Reconfigured:
performance.readdir-ahead: on
2.3.7 volume的兩種掛載方式
(1)以glusterfs方式掛載
#掛載卷到目錄(在glusterfs01上操作)
[root@glusterfs01 ~]# mount -t glusterfs 127.0.0.1:/gs1 /mnt #將本地的分布式卷gs01掛載到/mnt目錄下
[root@glusterfs01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 1.1G 16G 7% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/sr0 4.2G 4.2G 0 100% /media/cdrom
/dev/sdb 9.9G 151M 9.2G 2% /gluster/brick1
127.0.0.1:/gs1 20G 302M 19G 2% /mnt #掛載成功,我們看到磁盤空間已經整合
#在掛載好的/mnt目錄里創建實驗文件(在glusterfs01上操作)
[root@glusterfs01 ~]# touch /mnt/{1..5}
[root@glusterfs01 ~]# ls /mnt
1 2 3 4 5
#在其他虛擬機上掛載分布式卷gs1,查看同步掛載結果
[root@glusterfs02 rpm]# mount -t glusterfs 127.0.0.1:/gs1 /mnt
[root@glusterfs02 rpm]# ls /mnt
1 2 3 4 5
[root@glusterfs03 rpm]# mount -t glusterfs 127.0.0.1:/gs1 /mnt
[root@glusterfs03 rpm]# ls /mnt
1 2 3 4 5
[root@glusterfs04 ~]# mount -t glusterfs 127.0.0.1:/gs1 /mnt
[root@glusterfs04 ~]# ls /mnt
1 2 3 4 5
(2)以NFS方式進行掛載
在掛載之前我們先來看一下如何打開glusterfs的NFS掛載方式
#在glusterfs01上執行如下操作
[root@glusterfs01 ~]# gluster volume status #查看分布式卷的狀態
Status of volume: gs1
Gluster process TCP Port RDMA Port Online Pid
------------------------------------------------------------------------------
Brick glusterfs01:/gluster/brick1 49152 0 Y 1911
Brick glusterfs02:/gluster/brick1 49152 0 Y 1695
NFS Server on localhost N/A N/A N N/A #本地分布式卷NFS掛載未開啟
NFS Server on glusterfs04 2049 0 Y 2679
NFS Server on glusterfs02 2049 0 Y 2600 #出現具體的端口就表明開啟了
NFS Server on glusterfs03 2049 0 Y 2608
Task Status of Volume gs1
------------------------------------------------------------------------------
There are no active volume tasks
以上結果是是什么原因呢?
如果NFS Server的掛載端口顯示N/A表示未開啟掛載功能,這是由於要先進行nfs掛載是需要裝兩個nfs的軟件包的rpcbind和nfs-utils
當然就算系統裝了這兩個軟件包,那么我們也需要開啟rpcbind服務,然后在重啟glusterfs服務才能夠進行nfs掛載的操作。
現在我們就來開啟glusterfs01的nfs掛載功能,如下:
#在glusterfs01上執行如下操作
[root@glusterfs01 ~]# rpm -qa nfs-utils #查看是否安裝nfs-utils
nfs-utils-1.2.3-75.el6_9.x86_64
[root@glusterfs01 ~]# rpm -qa rpcbind #查看是否安裝rpcbind
rpcbind-0.2.0-13.el6_9.1.x86_64
[root@glusterfs01 ~]# /etc/init.d/rpcbind status #查看rpcbind服務狀態
rpcbind is stopped
[root@glusterfs01 ~]# /etc/init.d/rpcbind start #開啟rpcbind服務
Starting rpcbind: [ OK ]
[root@glusterfs01 ~]# /etc/init.d/glusterd stop #停止glusterd服務
Stopping glusterd: [ OK ]
[root@glusterfs01 ~]# /etc/init.d/glusterd start #開啟glusterd服務
Starting glusterd: [ OK ]
root@glusterfs01 ~]# gluster volume status #這里需要等幾秒再查看,就會發現nfs掛載方式開啟了
Status of volume: gs1
Gluster process TCP Port RDMA Port Online Pid
------------------------------------------------------------------------------
Brick glusterfs01:/gluster/brick1 49152 0 Y 1911
Brick glusterfs02:/gluster/brick1 49152 0 Y 1695
NFS Server on localhost 2049 0 Y 2984 #已經開啟
NFS Server on glusterfs04 2049 0 Y 2679
NFS Server on glusterfs03 2049 0 Y 2608
NFS Server on glusterfs02 2049 0 Y 2600
Task Status of Volume gs1
------------------------------------------------------------------------------
There are no active volume tasks
接下來,我們嘗試在准備好的第五台虛擬機WebServer上進行nfs方式的掛載
#在Webserver上進行如下操作
[root@WebServer ~]# rpm -qa nfs-utils #查看nfs-utils是否安裝
nfs-utils-1.2.3-39.el6.x86_64
[root@WebServer ~]# mount -t nfs 192.168.200.150:/gs1 /mnt #以nfs方式遠程掛載分布式卷
mount.nfs: rpc.statd is not running but is required for remote locking.
mount.nfs: Either use '-o nolock' to keep locks local, or start statd.
mount.nfs: an incorrect mount option was specified #根據提示我們加上-o nolock參數
[root@WebServer ~]# mount -o nolock -t nfs 192.168.200.150:/gs1 /mnt
[root@WebServer ~]# ls /mnt #掛載成功
1 2 3 4 5 6 666 sss yunjisuan
[root@WebServer ~]# touch /mnt/benet #創建文件測試
[root@WebServer ~]# ls /mnt
1 2 3 4 5 6 666 benet sss yunjisuan
#在glusterfs任意虛擬機上進行如下操作
[root@glusterfs04 ~]# mount -t glusterfs 127.0.0.1:/gs1 /mnt
[root@glusterfs04 ~]# ls /mnt
1 2 3 4 5 6 666 benet sss yunjisuan #數據已經同步
2.3.8 創建分布式復制卷
#在任意一台gluster虛擬機上進行如下操作
[root@glusterfs01 ~]# gluster volume create gs2 replica 2 glusterfs03:/gluster/brick1 glusterfs04:/gluster/brick1 force
volume create: gs2: success: please start the volume to access data
[root@glusterfs01 ~]# gluster volume info gs2
Volume Name: gs2
Type: Replicate #復制卷
Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
Status: Created
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: glusterfs03:/gluster/brick1
Brick2: glusterfs04:/gluster/brick1
Options Reconfigured:
performance.readdir-ahead: on
[root@glusterfs01 ~]# gluster volume start gs2 #啟動卷
volume start: gs2: success
2.3.9 創建分布式條帶卷
[root@glusterfs01 ~]# gluster volume create gs3 stripe 2 glusterfs01:/gluster/brick2 glusterfs02:/gluster/brick2 force
volume create: gs3: success: please start the volume to access data
[root@glusterfs01 ~]# gluster volume info gs3
Volume Name: gs3
Type: Stripe #條帶卷
Volume ID: 6d2e27c7-f5a1-4473-9df8-a7261851a2ed
Status: Created
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: glusterfs01:/gluster/brick2
Brick2: glusterfs02:/gluster/brick2
Options Reconfigured:
performance.readdir-ahead: on
[root@glusterfs01 ~]# gluster volume start gs3 #啟動卷
volume start: gs3: success
三,進行卷的數據寫入測試
在WebServer服務器掛載創建的三種類型卷gs1,gs2,gs3,進行數據寫入測試
3.1 分布式卷gs1的數據寫入測試
#在WebServer上進行數據寫入操作
[root@WebServer ~]# mount -o nolock -t nfs 192.168.200.150:/gs1 /mnt
[root@WebServer ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 1014M 16G 7% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/sr0 4.2G 4.2G 0 100% /media/cdrom
192.168.200.150:/gs1 20G 301M 19G 2% /mnt
[root@WebServer ~]# touch /mnt/{1..10}
[root@WebServer ~]# ls /mnt/
1 10 2 3 4 5 6 7 8 9
#在glusterfs01和glusterfs02上進行查看(看看數據到底寫入了哪個盤)
[root@glusterfs01 ~]# ls /gluster/brick1
1 5 7 8 9
[root@glusterfs02 ~]# ls /gluster/brick1
10 2 3 4 6
結論:分布式卷的數據存儲方式是將數據平均寫入到每個整合的磁盤中,類似於raid0,寫入速度快,但這樣磁盤一旦損壞沒有糾錯能力。
3.2 分布式復制卷gs2的數據寫入測試
#在WebServer上進行數據寫入操作
[root@WebServer ~]# mount -o nolock -t nfs 192.168.200.150:/gs2 /mnt
[root@WebServer ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 1014M 16G 7% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/sr0 4.2G 4.2G 0 100% /media/cdrom
192.168.200.150:/gs2 9.9G 151M 9.2G 2% /mnt #可用容量減半
[root@WebServer ~]# ls /mnt
lost+found
[root@WebServer ~]# touch /mnt/{1..10}
[root@WebServer ~]# ls /mnt
1 10 2 3 4 5 6 7 8 9 lost+found
#在glusterfs03和glusterfs04上進行查看(看看數據到底寫入了哪個盤)
[root@glusterfs03 ~]# ls /gluster/brick1
1 10 2 3 4 5 6 7 8 9 lost+found
[root@glusterfs04 ~]# ls /gluster/brick1
1 10 2 3 4 5 6 7 8 9 lost+found
結論:分布式復制卷的數據存儲方式為,每個整合的磁盤中都寫入同樣的數據內容,類似於raid1,數據非常安全,讀取性能高,占磁盤容量。
3.3 分布式條帶卷gs3的數據寫入測試
#在WebServer上進行數據寫入操作
[root@WebServer ~]# umount /mnt
[root@WebServer ~]# mount -o nolock -t nfs 192.168.200.150:/gs3 /mnt
[root@WebServer ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 1014M 16G 7% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/sr0 4.2G 4.2G 0 100% /media/cdrom
192.168.200.150:/gs3 20G 301M 19G 2% /mnt
[root@WebServer ~]# dd if=/dev/zero of=/root/test bs=1024 count=262144 #創建大小為256M的文件
262144+0 records in
262144+0 records out
268435456 bytes (268 MB) copied, 1.81006 s, 148 MB/s
[root@WebServer ~]# du -sh test
256M test
[root@WebServer ~]# cp test /mnt/ #復制到/mnt目錄下
[root@WebServer ~]# ls /mnt
test
[root@WebServer ~]# du -sh /mnt/test #查看大小為256M
256M /mnt/test
#在glusterfs01和glusterfs02上進行查看(看看數據到底是怎么存的)
[root@glusterfs01 ~]# du -sh /gluster/brick2/test
129M /gluster/brick2/test
[root@glusterfs02 ~]# du -sh /gluster/brick2/test
129M /gluster/brick2/test
結論:我們發現分布式條帶卷,是將數據的容量平均分配到了每個整合的磁盤節點上。大幅提高大文件的並發讀訪問。
四,存儲卷中brick塊設備的擴容
4.1 分布式復制卷的擴容
[root@glusterfs01 ~]# gluster volume add-brick gs2 replica 2 glusterfs03:/gluster/brick2 glusterfs04:/gluster/brick2 force #添加兩個塊設備
volume add-brick: success
[root@glusterfs01 ~]# gluster volume info gs2
Volume Name: gs2
Type: Distributed-Replicate
Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
Status: Started
Number of Bricks: 2 x 2 = 4 #已經擴容
Transport-type: tcp
Bricks:
Brick1: glusterfs03:/gluster/brick1
Brick2: glusterfs04:/gluster/brick1
Brick3: glusterfs03:/gluster/brick2
Brick4: glusterfs04:/gluster/brick2
Options Reconfigured:
performance.readdir-ahead: on
特別提示:
對分布式復制卷和分布式條帶卷進行擴容時,要特別注意,如果創建卷之初的時候選擇的是replica 2 或者stripe 2。那么擴容時,就必須一次性擴容兩個或兩個的倍數的塊設備。
例如你給一個分布式復制卷的replica為2,你在增加bricks的時候數量必須為2,4,6,8等。
4.2 查看擴容后的容量並進行寫入測試
#在WebServer上掛載gs2並查看掛載目錄的容量
[root@WebServer ~]# umount /mnt
[root@WebServer ~]# mount -o nolock -t nfs 192.168.200.150:/gs2 /mnt
[root@WebServer ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 1.3G 16G 8% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/sr0 4.2G 4.2G 0 100% /media/cdrom
192.168.200.150:/gs2 20G 301M 19G 2% /mnt #已經擴容
再次寫入數據
#在WebServer上進行數據寫入操作
[root@WebServer ~]# touch /mnt/{11..20}
[root@WebServer ~]# ls /mnt
1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9 lost+found
#在glusterfs03和glusterfs04上查看數據存到哪里去了
[root@glusterfs03 ~]# gluster volume info gs2
Volume Name: gs2
Type: Distributed-Replicate
Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
Status: Started
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: glusterfs03:/gluster/brick1 #組成gs2的塊設備就在03和04上
Brick2: glusterfs04:/gluster/brick1
Brick3: glusterfs03:/gluster/brick2
Brick4: glusterfs04:/gluster/brick2
Options Reconfigured:
performance.readdir-ahead: on
[root@glusterfs03 ~]# ls /gluster/brick1
1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9 lost+found
[root@glusterfs03 ~]# ls /gluster/brick2
lost+found #什么都沒有
[root@glusterfs04 ~]# ls /gluster/brick1
1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9 lost+found
[root@glusterfs04 ~]# ls /gluster/brick2
lost+found #還是什么都沒有
通過對擴容的gs2進行寫入測試,我們發現數據並沒有被寫入到新加入的塊設備中,這是為甚什么?
這是因為,為了數據的安全,新擴容塊設備的卷,默認必須先做一次磁盤平衡(塊設備同步),如此才能正常開始使用。
4.3 進行磁盤存儲的平衡
注意:平衡布局是很有必要的,因為布局結構是靜態的,當新的bricks加入現有卷,新創建的文件會分布到舊的bricks中,所以需要平衡布局結構,使新加入的bricks生效。布局平衡只是使新布局生效,並不會在新的布局移動老的數據,如果你想在新布局生效后,重新平衡卷中的數據,還需要對卷中的數據進行平衡。
#對gs2進行磁盤存儲平衡
[root@glusterfs01 ~]# gluster volume rebalance gs2 start
volume rebalance: gs2: success: Rebalance on gs2 has been started successfully. Use rebalance status command to check status of the rebalance process.
ID: 0024338c-84df-4edb-b68c-107415a27506
#檢查gs2塊設備磁盤平衡結果
[root@glusterfs03 ~]# ls /gluster/brick1
10 12 14 15 16 17 2 3 4 6 lost+found
[root@glusterfs03 ~]# ls /gluster/brick2
1 11 13 18 19 20 5 7 8 9 lost+found
[root@glusterfs04 ~]# ls /gluster/brick1
10 12 14 15 16 17 2 3 4 6 lost+found
[root@glusterfs04 ~]# ls /gluster/brick2
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等。
#先停止卷gs2
[root@glusterfs01 ~]# gluster volume stop gs2
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: gs2: success
#然后移除卷,因為是復制卷且replica為2,因此每次移除必須是2的倍數
[root@glusterfs01 ~]# gluster volume remove-brick gs2 replica 2 glusterfs03:/gluster/brick2 glusterfs04:/gluster/brick2 force
Removing brick(s) can result in data loss. Do you want to Continue? (y/n) y
volume remove-brick commit force: success
#我們發現gs2的卷已經被移除
[root@glusterfs01 ~]# gluster volume info gs2
Volume Name: gs2
Type: Replicate
Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
Status: Stopped
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: glusterfs03:/gluster/brick1
Brick2: glusterfs04:/gluster/brick1
Options Reconfigured:
performance.readdir-ahead: on
#重新啟動卷gs2
[root@glusterfs01 ~]# gluster volume start gs2
volume start: gs2: success
(2)對存儲卷進行刪除
#停止卷gs1
[root@glusterfs01 ~]# gluster volume stop gs1
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: gs1: success
#刪除卷gs1
[root@glusterfs01 ~]# gluster volume delete gs1
Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
volume delete: gs1: success
#查看卷信息,發現gs1已經沒了
[root@glusterfs01 ~]# gluster volume info
Volume Name: gs2
Type: Replicate
Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: glusterfs03:/gluster/brick1
Brick2: glusterfs04:/gluster/brick1
Options Reconfigured:
performance.readdir-ahead: on
Volume Name: gs3
Type: Stripe
Volume ID: 6d2e27c7-f5a1-4473-9df8-a7261851a2ed
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: glusterfs01:/gluster/brick2
Brick2: glusterfs02:/gluster/brick2
Options Reconfigured:
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 服務器擺放分布
服務器主備機器要放在不同的機櫃,連接不同的交換機,即使一個機櫃出現問題,還有一份數據正常訪問。
6.5 構建高性能,高可用存儲
一般在企業中,采用的是分布式復制卷,因為有數據備份,數據相對安全,分布式條帶卷目前對glusterfs來說沒有完全成熟,存在一定的是數據安全風險。
6.5.1 開啟防火牆端口
一般在企業應用中Linux防火牆是打開的,開通服務器之間訪問的端口
iptables -I INPUT -p tcp --dport 24007:24011 -j ACCEPT
iptables -I INPUT -p tcp --dport 49152:49162 -j ACCEPT
[root@glusterfs01 ~]# cat /etc/glusterfs/glusterd.vol
volume management
type mgmt/glusterd
option working-directory /var/lib/glusterd
option transport-type socket,rdma
option transport.socket.keepalive-time 10
option transport.socket.keepalive-interval 2
option transport.socket.read-fail-log off
option ping-timeout 0
option event-threads 1
# 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 <卷> <參數>
[root@glusterfs01 ~]# gluster volume info gs2
Volume Name: gs2
Type: Replicate
Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: glusterfs03:/gluster/brick1
Brick2: glusterfs04:/gluster/brick1
Options Reconfigured:
performance.readdir-ahead: on
[root@glusterfs01 ~]# gluster volume set gs2 performance.read-ahead on #設置預緩存優化
volume set: success
[root@glusterfs01 ~]# gluster volume info gs2
Volume Name: gs2
Type: Replicate
Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: glusterfs03:/gluster/brick1
Brick2: glusterfs04:/gluster/brick1
Options Reconfigured:
performance.read-ahead: on #已經添加上了
performance.readdir-ahead: on
[root@glusterfs01 ~]# gluster volume set gs2 performance.cache-size 256MB #設置讀緩存大小
volume set: success
[root@glusterfs01 ~]# gluster volume info gs2
Volume Name: gs2
Type: Replicate
Volume ID: c76fe8fd-71a7-4395-9dd2-ef1dc85163b8
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: glusterfs03:/gluster/brick1
Brick2: glusterfs04:/gluster/brick1
Options Reconfigured:
performance.cache-size: 256MB #已經添加上了
performance.read-ahead: on
performance.readdir-ahead: on
6.5.3 監控及日常維護
使用Zabbix自帶模板即可。Cpu,內存,主機存活,磁盤空間,主機運行時間,系統load。日常情況要查看服務器的監控值,遇到報警要及時處理。
#以下命令在復制卷的場景下才會有
#gluster volume status gs2 查看節點NFS是否在線
(開沒開端口)
#gluster volume heal gs2 full 啟動完全修復
#gluster volume heal gs2 info 查看需要修復的文件
#gluster volume heal gs2 info healed 查看修復成功的文件
#gluster volume heal gs2 info heal-failed 查看修復失敗文件
#gluster volume heal gs2 info split-brain 查看腦裂的文件
#gluster volume quota gs2 enable --激活quota功能
#gluster volume quota gs2 disable --關閉quota功能
#gluster volume quota gs2 limit-usage /data 10GB --/gs2/data 目錄限制
#gluster volume quota gs2 list --quota 信息列表
#gluster volume quota gs2 list /data --限制目錄的quota信息
#gluster volume set gs2 features.quota-timeout 5 --設置信息的超時事實上時間
#gluster volume quota gs2 remove /data -刪除某個目錄的quota設置
備注:
1)quota 功能,主要是對掛載點下的某個目錄進行空間限額。如:/mnt/glusterfs/data目錄,而不是對組成卷組的空間進行限制
七 生產環境遇到常見故障處理
7.1 硬盤故障
因為底層做了raid配置,有硬件故障,直接更換硬盤,會自動同步數據。(raid5)
7.2 一台主機故障
一台節點故障的情況包括以下類型:
1,物理故障
2,同時有多塊硬盤故障,造成是數據丟失
3,系統損壞不可修復
解決方法:
找一台完全一樣的機器,至少要保證硬盤數量和大小一致,安裝系統,配置和故障機同樣的ip,安裝gluster軟件,保證配置一樣,在其他健康的節點上執行命令gluster peer status,查看故障服務器的uuid
#例如:
[root@glusterfs03 ~]# gluster peer status
Number of Peers: 3
Hostname: glusterfs02
Uuid: 0b52290d-96b0-4b9c-988d-44062735a8a8
State: Peer in Cluster (Connected)
Hostname: glusterfs04
Uuid: a43ac51b-641c-4fc4-be56-f6873423b462
State: Peer in Cluster (Connected)
Hostname: glusterfs01
Uuid: 198f2c7c-1104-4671-8989-b430b77540e9
State: Peer in Cluster (Connected)
[root@glusterfs03 ~]#
修改新加機器的/var/lib/glusterd/glusterd.info和故障機器的一樣
[root@glusterfs04 ~]# cat /var/lib/glusterd/glusterd.info
UUID=a43ac51b-641c-4fc4-be56-f6873423b462
operating-version=30712
在新機器掛載目錄上執行磁盤故障的操作(任意節點)
[root@glusterfs04 ~]# gluster volume heal gs2 full
Launching heal operation to perform full self heal on volume gs2 has been successful
Use heal info commands to check status
就會自動開始同步,但是同步的時候會影響整個系統的性能
可以查看狀態
[root@glusterfs04 ~]# gluster volume heal gs2 info
Brick glusterfs03:/gluster/brick1
Status: Connected
Number of entries: 0
Brick glusterfs04:/gluster/brick1
Status: Connected
Number of entries: 0