Linux实战教学笔记52:GlusterFS分布式存储系统
一,分布式文件系統(tǒng)理論基礎(chǔ)
1.1 分布式文件系統(tǒng)出現(xiàn)
- 計算機通過文件系統(tǒng)管理,存儲數(shù)據(jù),而現(xiàn)在數(shù)據(jù)信息爆炸的時代中人們可以獲取的數(shù)據(jù)成指數(shù)倍的增長,單純通過增加硬盤個數(shù)來擴展計算機文件系統(tǒng)的存儲容量的方式,已經(jīng)不能滿足目前的需求。
- 分布式文件系統(tǒng)可以有效解決數(shù)據(jù)的存儲和管理難題,將固定于某個地點的某個文件系統(tǒng),擴展到任意多個地點/多個文件系統(tǒng),眾多的節(jié)點組成一個文件系統(tǒng)網(wǎng)絡(luò)。每個節(jié)點可以分布在不同的地點,通過網(wǎng)絡(luò)進行節(jié)點間的通信和數(shù)據(jù)傳輸。人們在使用分布式文件系統(tǒng)時,無需關(guān)心數(shù)據(jù)是存儲在哪個節(jié)點上,或者是從哪個節(jié)點從獲取的,只需要像使用本地文件系統(tǒng)一樣管理和存儲文件系統(tǒng)中的數(shù)據(jù)。
1.2 典型代表NFS
NFS(Network File System)即網(wǎng)絡(luò)文件系統(tǒng),它允許網(wǎng)絡(luò)中的計算機之間通過TCP/IP網(wǎng)絡(luò)共享資源。在NFS的應(yīng)用中,本地NFS的客戶端應(yīng)用可以透明地讀寫位于遠端NFS服務(wù)器上的文件,就像訪問本地文件一樣。NFS的優(yōu)點如下:
(1)節(jié)約使用的磁盤空間
客戶端經(jīng)常使用的數(shù)據(jù)可以集中存放在一臺機器上,并使用NFS發(fā)布,那么網(wǎng)絡(luò)內(nèi)部所有計算機可以通過網(wǎng)絡(luò)訪問,不必單獨存儲。
(2)節(jié)約硬件資源
NFS還可以共享軟驅(qū),CDROM和ZIP等的存儲設(shè)備,減少整個網(wǎng)絡(luò)上的可移動設(shè)備的數(shù)量。
(3)用戶主目錄設(shè)定
對于特殊用戶,如管理員等,為了管理的需要,可能會經(jīng)常登陸到網(wǎng)絡(luò)中所有的計算機,若每個客戶端,均保存這個用戶的主目錄很繁瑣,而且不能保證數(shù)據(jù)的一致性。實際上,經(jīng)過NFS服務(wù)的設(shè)定,然后在客戶端指定這個用戶的主目錄位置,并自動掛載,就可以在任何計算機上使用用戶主目錄的文件。
1.3 面臨的問題
存儲空間不足,需要更大容量的存儲
直接用NFS掛載存儲,有一定風險,存在單點故障
某些場景不能滿足需求,大量的訪問磁盤IO是瓶頸
1.4 GlusterFS概述
- GlusterFS是Scale-Out存儲解決方案Gluster的核心,它是一個開源的分布式文件系統(tǒng),具有強大的橫向擴展能力,通過擴展能夠支持數(shù)PB存儲容量和處理數(shù)千客戶端。GlusterFS借助TCP/IP或InfiniBand RDMA網(wǎng)絡(luò)將物理分布的存儲資源聚集在一起,使用單一全局命名空間來管理數(shù)據(jù)。
- GlusterFS支持運行在任何標準IP網(wǎng)絡(luò)上標準應(yīng)用程序的標準客戶端,用戶可以在全局統(tǒng)一的命令空間中使用NFS/CIFS等標準協(xié)議來訪問應(yīng)用程序。GlusterFS使得用戶可擺脫原有的獨立,高成本的封閉存儲系統(tǒng),能夠利用普通廉價的存儲設(shè)備來部署可集中管理,橫向擴展,虛擬化的存儲池,存儲容量可擴展至TB/PB級。
- 目前glusterfs已被redhat收購,它的官方網(wǎng)站是:http://www.gluster.org/
超高性能(64個節(jié)點時吞吐量也就是帶寬甚至達到32GB/s)
1.5 GlusterFS企業(yè)主要應(yīng)用場景
理論和實踐上分析,GlusterFS目前主要適用大文件存儲場景,對于小文件尤其是海量小文件(小于1M),存儲效率和訪問性能都表現(xiàn)不佳。海量小文件LOSF問題是工業(yè)界和學術(shù)界公認的難題,GlusterFS作為通用的分布式文件系統(tǒng),并沒有對小文件作額外的優(yōu)化措施(小于1M),性能不好也是可以理解的。
- [x] Media
文檔,圖片,音頻,視頻
- [x] Shared storage
云存儲,虛擬化存儲,HPC(高性能計算)
- [x] Big data
日志文件,RFID(射頻識別)數(shù)據(jù)
二,部署安裝
2.1 GlusterFS 安裝前的準備
| Linux_node1 | 192.168.200.150 | mystorage01 |
| Linux_node2 | 192.168.200.151 | mystorage02 |
| Linux_node3 | 192.168.200.152 | mystorage03 |
| Linux_node4 | 192.168.200.153 | mystorage04 |
| Linux_node5 | 192.168.200.154 | WebServerClinet |
2.2 GlusterFS 安裝
2.2.1 修改主機名
略
2.2.2 添加hosts文件實現(xiàn)集群主機之間相互能夠解析
[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 glusterfs042.2.3 關(guān)閉selinux和防火墻
#關(guān)閉selinux sed -i 's#SELINUX=enforcing#SELINUX=disabled#' /etc/sysconfig/selinux #關(guān)閉iptables service iptables stop chkconfig iptables off2.2.4 利用教程附帶的rpm軟件包組,充當本地定制化yum源
yum -y install createrepo yum -y install glusterfs-server glusterfs-cli glusterfs-geo-replication2.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 啟動停止服務(wù)
[root@glusterfs01 ~]# /etc/init.d/glusterd status #查看服務(wù)狀態(tài) 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 存儲主機加入信任存儲池
虛擬機添加信任存儲池
特別提示:只需要讓一個虛擬機進行添加操作即可。但自己并不需要添加信任自己
2.3.4 查看虛擬機信任狀態(tài)添加結(jié)果
[root@glusterfs01 ~]# gluster peer status Number of Peers: 3Hostname: 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)同學們可以查看每臺虛擬機的信任狀態(tài),他們此時彼此都應(yīng)該已經(jīng)互有信任記錄了
2.3.5 配置前的準備工作
在企業(yè)里我們還需要分區(qū)然后才能進行格式化。但是我們這里就省略了,我們直接格式化每臺虛擬機的那塊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.在四臺機器上執(zhí)行mkdir -p /gluster/brick1 建立掛在塊設(shè)備的目錄
掛載磁盤到文件系統(tǒng)(4臺都做,步驟相同)
繼續(xù)重復以上步驟,將第二塊磁盤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/brick22.3.6 創(chuàng)建volume分布式卷
- [x] 基本卷:
- 分布式卷(Distributed):
- 復制卷(Replicated):
- 條帶式卷(Striped):
- [x] 復合卷:
- 分布式復制卷(Distributed Replicated):
- 分布式條帶卷(Distributed Striped):
- 復制條帶卷(Replicated Striped):
- 分布式復制條帶卷(Distributed Replicated Striped):
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 #掛載成功,我們看到磁盤空間已經(jīng)整合 #在掛載好的/mnt目錄里創(chuàng)建實驗文件(在glusterfs01上操作) [root@glusterfs01 ~]# touch /mnt/{1..5} [root@glusterfs01 ~]# ls /mnt 1 2 3 4 5 #在其他虛擬機上掛載分布式卷gs1,查看同步掛載結(jié)果 [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上執(zhí)行如下操作 [root@glusterfs01 ~]# gluster volume status #查看分布式卷的狀態(tài) 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 #出現(xiàn)具體的端口就表明開啟了 NFS Server on glusterfs03 2049 0 Y 2608 Task Status of Volume gs1 ------------------------------------------------------------------------------ There are no active volume tasks以上結(jié)果是是什么原因呢?
如果NFS Server的掛載端口顯示N/A表示未開啟掛載功能,這是由于要先進行nfs掛載是需要裝兩個nfs的軟件包的rpcbind和nfs-utils
當然就算系統(tǒng)裝了這兩個軟件包,那么我們也需要開啟rpcbind服務(wù),然后在重啟glusterfs服務(wù)才能夠進行nfs掛載的操作。
現(xiàn)在我們就來開啟glusterfs01的nfs掛載功能,如下:
接下來,我們嘗試在準備好的第五臺虛擬機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 #根據(jù)提示我們加上-o nolock參數(shù) [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 #創(chuàng)建文件測試 [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 #數(shù)據(jù)已經(jīng)同步2.3.8 創(chuàng)建分布式復制卷
#在任意一臺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: success2.3.9 創(chuàng)建分布式條帶卷
[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三,進行卷的數(shù)據(jù)寫入測試
在WebServer服務(wù)器掛載創(chuàng)建的三種類型卷gs1,gs2,gs3,進行數(shù)據(jù)寫入測試
3.1 分布式卷gs1的數(shù)據(jù)寫入測試
#在WebServer上進行數(shù)據(jù)寫入操作 [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上進行查看(看看數(shù)據(jù)到底寫入了哪個盤) [root@glusterfs01 ~]# ls /gluster/brick1 1 5 7 8 9 [root@glusterfs02 ~]# ls /gluster/brick1 10 2 3 4 6結(jié)論:分布式卷的數(shù)據(jù)存儲方式是將數(shù)據(jù)平均寫入到每個整合的磁盤中,類似于raid0,寫入速度快,但這樣磁盤一旦損壞沒有糾錯能力。
3.2 分布式復制卷gs2的數(shù)據(jù)寫入測試
#在WebServer上進行數(shù)據(jù)寫入操作 [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上進行查看(看看數(shù)據(jù)到底寫入了哪個盤) [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結(jié)論:分布式復制卷的數(shù)據(jù)存儲方式為,每個整合的磁盤中都寫入同樣的數(shù)據(jù)內(nèi)容,類似于raid1,數(shù)據(jù)非常安全,讀取性能高,占磁盤容量。
3.3 分布式條帶卷gs3的數(shù)據(jù)寫入測試
結(jié)論:我們發(fā)現(xiàn)分布式條帶卷,是將數(shù)據(jù)的容量平均分配到了每個整合的磁盤節(jié)點上。大幅提高大文件的并發(fā)讀訪問。
四,存儲卷中brick塊設(shè)備的擴容
4.1 分布式復制卷的擴容
[root@glusterfs01 ~]# gluster volume add-brick gs2 replica 2 glusterfs03:/gluster/brick2 glusterfs04:/gluster/brick2 force #添加兩個塊設(shè)備 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 #已經(jīng)擴容 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特別提示:
對分布式復制卷和分布式條帶卷進行擴容時,要特別注意,如果創(chuàng)建卷之初的時候選擇的是replica 2 或者stripe 2。那么擴容時,就必須一次性擴容兩個或兩個的倍數(shù)的塊設(shè)備。
例如你給一個分布式復制卷的replica為2,你在增加bricks的時候數(shù)量必須為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 #已經(jīng)擴容我們再次寫入數(shù)據(jù)
#在WebServer上進行數(shù)據(jù)寫入操作 [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上查看數(shù)據(jù)存到哪里去了 [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的塊設(shè)備就在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進行寫入測試,我們發(fā)現(xiàn)數(shù)據(jù)并沒有被寫入到新加入的塊設(shè)備中,這是為甚什么?
這是因為,為了數(shù)據(jù)的安全,新擴容塊設(shè)備的卷,默認必須先做一次磁盤平衡(塊設(shè)備同步),如此才能正常開始使用。
4.3 進行磁盤存儲的平衡
注意:平衡布局是很有必要的,因為布局結(jié)構(gòu)是靜態(tài)的,當新的bricks加入現(xiàn)有卷,新創(chuàng)建的文件會分布到舊的bricks中,所以需要平衡布局結(jié)構(gòu),使新加入的bricks生效。布局平衡只是使新布局生效,并不會在新的布局移動老的數(shù)據(jù),如果你想在新布局生效后,重新平衡卷中的數(shù)據(jù),還需要對卷中的數(shù)據(jù)進行平衡。
#對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塊設(shè)備磁盤平衡結(jié)果 [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執(zhí)行磁盤存儲平衡以后,我們發(fā)現(xiàn)數(shù)據(jù)被復制成了4份在4個塊設(shè)備中。
五,存儲卷的縮減與刪除
(1)對存儲卷中的brick進行縮減
注意:你可能想在線縮小卷的大小,例如:當硬件損壞或者網(wǎng)絡(luò)故障的時候,你可能想在卷中移除相關(guān)的bricks。注意,當你移除bricks的時候,你在gluster的掛載點將不能繼續(xù)訪問是數(shù)據(jù),只有配置文件中的信息移除后你才能繼續(xù)訪問bricks的數(shù)據(jù)。當移除分布式復制卷或者分布式條帶卷的時候,移除的bricks數(shù)目必須是replica或者stripe的倍數(shù)。例如:一個分布式條帶卷的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的倍數(shù) [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 #我們發(fā)現(xiàn)gs2的卷已經(jīng)被移除 [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 #查看卷信息,發(fā)現(xiàn)gs1已經(jīng)沒了 [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特別提示:
無論是縮減卷還是刪除卷,并不會是清除卷中的數(shù)據(jù)。數(shù)據(jù)仍舊會保存在對應(yīng)磁盤上。
六,構(gòu)建企業(yè)級分布式存儲
6.1 硬件要求
一般選擇2U的機型,磁盤STAT盤4T,如果I/O要求比較高,可以采購SSD固態(tài)硬盤。為了充分保證系統(tǒng)的穩(wěn)定性和性能,要求所有g(shù)lusterfs服務(wù)器硬件配置盡量一致,尤其是硬盤數(shù)量和大小。機器的RAID卡需要帶電池,緩存越大,性能越好。一般情況下,建議做RAID10,如果出于空間要求考慮,需要做RAID5,建議最好能有1-2塊硬盤的熱備盤。
6.2 系統(tǒng)要求和分區(qū)劃分
系統(tǒng)要求使用CentOS6.x,安裝完成后升級到最新版本,安裝的時候,不要使用LVM,建議/boot分區(qū)200M,根分區(qū)100G,swap分區(qū)和內(nèi)存一樣大小,剩余空間給gluster使用,劃分單獨的硬盤空間。系統(tǒng)安裝軟件沒有特殊要求,建議除了開發(fā)工具和基本的管理軟件,其他軟件一律不裝。
6.3 網(wǎng)絡(luò)環(huán)境
網(wǎng)絡(luò)要求全部千兆環(huán)境,gluster服務(wù)器至少有2塊網(wǎng)卡,1塊網(wǎng)卡綁定供gluster使用,剩余一塊分配管理網(wǎng)絡(luò)ip,用于系統(tǒng)管理。如果有條件購買萬兆交換機,服務(wù)器配置萬兆網(wǎng)卡,存儲性能會更好。網(wǎng)絡(luò)方面如果安全性要求高,可以多網(wǎng)卡綁定。
6.4 服務(wù)器擺放分布
服務(wù)器主備機器要放在不同的機柜,連接不同的交換機,即使一個機柜出現(xiàn)問題,還有一份數(shù)據(jù)正常訪問。
6.5 構(gòu)建高性能,高可用存儲
一般在企業(yè)中,采用的是分布式復制卷,因為有數(shù)據(jù)備份,數(shù)據(jù)相對安全,分布式條帶卷目前對glusterfs來說沒有完全成熟,存在一定的是數(shù)據(jù)安全風險。
6.5.1 開啟防火墻端口
一般在企業(yè)應(yīng)用中Linux防火墻是打開的,開通服務(wù)器之間訪問的端口
iptables -I INPUT -p tcp --dport 24007:24011 -j ACCEPT iptables -I INPUT -p tcp --dport 49152:49162 -j ACCEPT [root@glusterfs01 ~]6.5.2 Glusterfs文件系統(tǒng)優(yōu)化
| Auth.allow | IP訪問授權(quán) | *(allow all) | IP地址 |
| Cluster.min-free-disk | 剩余磁盤空間閾值 | 10% | 百分比 |
| Cluster.stripe-block-size | 條帶大小 | 128KB | 字節(jié) |
| Network.frame-timeout | 請求等待時間 | 1800s | 0-1800 |
| Network.ping-timeout | 客戶端等待時間 | 42s | 0-42 |
| Nfs.disabled | 關(guān)閉NFS服務(wù) | Off | Off|on |
| Performance.io-thread-count | IO線程數(shù) | 16 | 0-65 |
| Performance.cache-refresh-timeout | 緩存校驗周期 | 1s | 0-61 |
| Performance.cache-size | 讀緩存大小 | 32MB | 字節(jié) |
Performance.quick-read:優(yōu)化讀取小文件的性能
Performance.read-ahead:用預讀的方式提高讀取的性能,有利于應(yīng)用頻繁持續(xù)性的訪問文件,當應(yīng)用完成當前數(shù)據(jù)塊讀取的時候,下一個數(shù)據(jù)塊就已經(jīng)準備好了。
Performance.write-behind:寫入數(shù)據(jù)時,先寫入緩存內(nèi),再寫入硬盤內(nèi),以提高寫入的性能。
Performance.io-cache:緩存已經(jīng)被讀過的。
調(diào)整方法:
Glusster volume set <卷> <參數(shù)>
[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 #設(shè)置預緩存優(yōu)化 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 #已經(jīng)添加上了 performance.readdir-ahead: on [root@glusterfs01 ~]# gluster volume set gs2 performance.cache-size 256MB #設(shè)置讀緩存大小 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 #已經(jīng)添加上了 performance.read-ahead: on performance.readdir-ahead: on6.5.3 監(jiān)控及日常維護
使用Zabbix自帶模板即可。Cpu,內(nèi)存,主機存活,磁盤空間,主機運行時間,系統(tǒng)load。日常情況要查看服務(wù)器的監(jiān)控值,遇到報警要及時處理。
七 生產(chǎn)環(huán)境遇到常見故障處理
7.1 硬盤故障
因為底層做了raid配置,有硬件故障,直接更換硬盤,會自動同步數(shù)據(jù)。(raid5)
7.2 一臺主機故障
一臺節(jié)點故障的情況包括以下類型:
1,物理故障
2,同時有多塊硬盤故障,造成是數(shù)據(jù)丟失
3,系統(tǒng)損壞不可修復
解決方法:
找一臺完全一樣的機器,至少要保證硬盤數(shù)量和大小一致,安裝系統(tǒng),配置和故障機同樣的ip,安裝gluster軟件,保證配置一樣,在其他健康的節(jié)點上執(zhí)行命令gluster peer status,查看故障服務(wù)器的uuid
#例如: [root@glusterfs03 ~]# gluster peer status Number of Peers: 3Hostname: 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在新機器掛載目錄上執(zhí)行磁盤故障的操作(任意節(jié)點)
[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就會自動開始同步,但是同步的時候會影響整個系統(tǒng)的性能
可以查看狀態(tài)
轉(zhuǎn)載于:https://www.cnblogs.com/skyhu365/p/10652878.html
總結(jié)
以上是生活随笔為你收集整理的Linux实战教学笔记52:GlusterFS分布式存储系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 远程桌面时提示凭证不工作怎么办 远程桌面
- 下一篇: linux 其他常用命令