一文看懂GFS如何搭建
生活随笔
收集整理的這篇文章主要介紹了
一文看懂GFS如何搭建
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 一、服務端配置
- 1.環境
- 2.修改主機名
- 3.使用腳本對硬盤進行分區掛載
- 4.添加四個節點域名解析
- 5.安裝本地源GFS
- 6.創建卷
- 1.創建分布式卷
- 2.創建條帶卷
- 3.創建復制卷
- 4.創建分布式條帶卷
- 5.創建分布式復制卷
- 二、客戶端配置
- 1.安裝客戶端
- 2.驗證gluster文件系統
- 3.冗余(破壞)測試
- 三、Gluster的其他的維護命令
一、服務端配置
1.環境
- 每臺虛擬機需要添加4塊5G磁盤
2.修改主機名
hostnamectl set-hostname node1 suhostnamectl set-hostname node2 suhostnamectl set-hostname node3 suhostnamectl set-hostname node4 suhostnamectl set-hostname client su3.使用腳本對硬盤進行分區掛載
vim /opt/fdisk.sh#!/bin/bash #刷新磁盤 echo "- - -" >/sys/class/scsi_host/host0/scan echo "- - -" >/sys/class/scsi_host/host1/scan echo "- - -" >/sys/class/scsi_host/host2/scan ##grep出系統所帶磁盤 fdisk -l |grep '磁盤 /dev/sd[a-z]' echo "==================================================" PS3="chose which disk you want to create:"##選擇需要創建的磁盤編號 select VAR in `ls /dev/sd*|grep -o 'sd[b-z]'|uniq` quit docase $VAR insda)##本地磁盤就退出case語句fdisk -l /dev/sdabreak ;;sd[b-z])#create partitionsecho "n ##創建磁盤pw" | fdisk /dev/$VAR#make filesystem ##格式化mkfs.xfs -i size=512 /dev/${VAR}"1" &> /dev/null#mount the systemmkdir -p /data/${VAR}"1" &> /dev/null ###永久掛載echo -e "/dev/${VAR}"1" /data/${VAR}"1" xfs defaults 0 0\n" >> /etc/fstab ###使得掛載生效mount -a &> /dev/nullbreak ;;quit)break;;*)echo "wrong disk,please check again";;esac done>>>>>>wq- 交互時 依次輸入1、2、3、4
4.添加四個節點域名解析
vim /etc/hosts 192.168.3.11 node1 192.168.3.12 node2 192.168.3.13 node3 192.168.3.14 node45.安裝本地源GFS
- 四個節點相同操作
- 添加節點到存儲信任池中(在node1節點上操作)
6.創建卷
- 根據規劃創建如下卷
| dis-volume | 分布式卷 | node1(/data/sdb1)、node2(/data/sdb1) |
| stripe-volume | 條帶卷 | node1(/data/sdc1)、node2(/data/sdc1) |
| rep-volume | 復制卷 | node3(/data/sdb1)、node4(/data/sdb1) |
| dis-stripe | 分布式條帶卷 | node1(/data/sdd1)、node2(/data/sdd1)、node3(/data/sdd1)、node4(/data/sdd1) |
| dis-rep | 分布式復制卷 | node1(/data/sde1)、node2(/data/sde1)、node3(/data/sde1)、node4(/data/sde1) |
1.創建分布式卷
#創建分布式卷,沒有指定類型,默認創建的是分布式卷 gluster volume create dis-volume node1:/data/sdb1 node2:/data/sdb1 force #查看卷列表 gluster volume list #啟動新建分布式卷 gluster volume start dis-volume #查看創建分布式卷信息 gluster volume info dis-volume2.創建條帶卷
#指定類型為 stripe,數值為 2,且后面跟了 2 個 Brick Server,所以創建的是條帶卷 gluster volume create stripe-volume stripe 2 node1:/data/sdc1 node2:/data/sdc1 force#啟動新建條帶卷 gluster volume start stripe-volume #查看創建條帶卷信息 gluster volume info stripe-volume3.創建復制卷
#指定類型為 replica,數值為 2,且后面跟了 2 個 Brick Server,所以創建的是復制卷 gluster volume create rep-volume replica 2 node3:/data/sdb1 node4:/data/sdb1 force#啟動新建復制卷 gluster volume start rep-volume #查看創建復制卷信息 gluster volume info rep-volume4.創建分布式條帶卷
#指定類型為 stripe,數值為 2,而且后面跟了 4 個 Brick Server,是 2 的兩倍,所以創建的是分布式條帶卷 gluster volume create dis-stripe stripe 2 node1:/data/sdd1 node2:/data/sdd1 node3:/data/sdd1 node4:/data/sdd1 force#啟動新建分布式條帶卷 gluster volume start dis-stripe #查看創建分布式條帶卷信息 gluster volume info dis-stripe5.創建分布式復制卷
#指定類型為 replica,數值為 2,而且后面跟了 4 個 Brick Server,是 2 的兩倍,所以創建的是分布式復制卷 gluster volume create dis-rep replica 2 node1:/data/sde1 node2:/data/sde1 node3:/data/sde1 node4:/data/sde1 force#啟動新建分布式復制卷 gluster volume start dis-rep #查看創建分布式復制卷信息 gluster volume info dis-rep- 此時再去查看卷列表,應有五個卷
二、客戶端配置
- 客戶端的操作:在node1上創建五個卷后,在客戶端上把卷掛載在指定的五個目錄內,在目錄內寫入了五個文件,五個文件分別保存在五個目錄里面
1.安裝客戶端
cd /opt wget http://112.124.46.81/gfsrepo.zip //下載安裝包 unzip gfsrepo.zip //解壓cd /etc/yum.repos.d/ mkdir repo.bak //創建備份目錄 mv local.repo repos.bak/ //備份vim glfs.repo[glfs] name=glfs baseurl=file:///opt/gfsrepo gpgcheck=0 enabled=1>>>>>>>wqyum clean all && yum makecache yum install -y glusterfs glusterfs-fuse#創建掛載目錄 mkdir -p /test/{dis,stripe,rep,dis_stripe,dis_rep} ls /test#配置域名解析 echo "192.168.3.11 node1" >> /etc/hosts echo "192.168.3.12 node2" >> /etc/hosts echo "192.168.3.13 node3" >> /etc/hosts echo "192.168.3.14 node4" >> /etc/hosts#掛載 Gluster 文件系統 mount.glusterfs node1:dis-volume /test/dis mount.glusterfs node1:stripe-volume /test/stripe mount.glusterfs node1:rep-volume /test/rep mount.glusterfs node1:dis-stripe /test/dis_stripe mount.glusterfs node1:dis-rep /test/dis_rep-
df -Th查看掛載
-
卷中寫入文件,客戶端操作
2.驗證gluster文件系統
- gluster服務器上查看文件分布
3.冗余(破壞)測試
1.在客戶端查看文件 [root@client test]# cd /test/ [root@client test]# ll -h dis 總用量 200M -rw-r--r-- 1 root root 40M 11月 17 14:20 demo1.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo2.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo3.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo4.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo5.log2.把node2節點關閉(模擬宕機),再回到客戶端檢查,可以看到demo5沒了,所以可以得出分布式卷(node1/2)不具備冗余的特性 [root@node2 ~]# init 0[root@client opt]# cd /test [root@client test]# ll -h dis 總用量 160M -rw-r--r-- 1 root root 40M 11月 17 14:20 demo1.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo2.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo3.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo4.log3.且發現條帶卷(node1/2)數據為0,不具備冗余 [root@client test]# ll -h stripe/ 總用量 04.關閉node3,測試復制卷(node3/node4)的冗余性 [root@node3 ~]# init 0[root@client test]# ll -h rep/ 總用量 200M -rw-r--r-- 1 root root 40M 11月 17 14:20 demo1.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo2.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo3.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo4.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo5.log #可以看到數據仍然存在,不受影響5.查看分布式條帶卷(node1/2/3/4) [root@client test]# ll -h dis_stripe/ 總用量 0 #也并不具備冗余性6.查看分布式復制卷(node1/2/3/4) [root@client test]# ll -h dis_rep/ 總用量 200M -rw-r--r-- 1 root root 40M 11月 17 14:20 demo1.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo2.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo3.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo4.log -rw-r--r-- 1 root root 40M 11月 17 14:20 demo5.log結果證明:只要帶復制數據的相比而言,數據比較安全
三、Gluster的其他的維護命令
1.查看GlusterFS卷 gluster volume list2.查看所有卷的信息 gluster volume info3.查看所有卷的狀態 gluster volume status4.停止一個卷 gluster volume stop dis-stripe5.刪除一個卷 gluster volume delete dis-stripe #注意:刪除卷時,需要先停止卷,且信任池中不能有主機處于宕機狀態,否則不能成功刪除6.設置卷的訪問控制 gluster volume set dis-rep auth.allow 192.168.3.100 #僅拒絕,設置為IP地址為192.168.3.100的主機禁止訪問dis-rep(分布式復制卷)gluster volume set dis-rep auth.allow 192.168.3.* #僅允許,設置為192.168.3.0網段的所有IP地址都能訪問dis-rep(分布式復制卷)總結
以上是生活随笔為你收集整理的一文看懂GFS如何搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关闭vs实时调试
- 下一篇: html a3纸大小,a0-a3纸的尺寸