一文看懂GFS如何搭建
生活随笔
收集整理的這篇文章主要介紹了
一文看懂GFS如何搭建
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
文章目錄
- 一、服務(wù)端配置
- 1.環(huán)境
- 2.修改主機(jī)名
- 3.使用腳本對硬盤進(jìn)行分區(qū)掛載
- 4.添加四個節(jié)點(diǎn)域名解析
- 5.安裝本地源GFS
- 6.創(chuàng)建卷
- 1.創(chuàng)建分布式卷
- 2.創(chuàng)建條帶卷
- 3.創(chuàng)建復(fù)制卷
- 4.創(chuàng)建分布式條帶卷
- 5.創(chuàng)建分布式復(fù)制卷
- 二、客戶端配置
- 1.安裝客戶端
- 2.驗(yàn)證gluster文件系統(tǒng)
- 3.冗余(破壞)測試
- 三、Gluster的其他的維護(hù)命令
一、服務(wù)端配置
1.環(huán)境
- 每臺虛擬機(jī)需要添加4塊5G磁盤
2.修改主機(jī)名
hostnamectl set-hostname node1 suhostnamectl set-hostname node2 suhostnamectl set-hostname node3 suhostnamectl set-hostname node4 suhostnamectl set-hostname client su3.使用腳本對硬盤進(jìn)行分區(qū)掛載
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出系統(tǒng)所帶磁盤 fdisk -l |grep '磁盤 /dev/sd[a-z]' echo "==================================================" PS3="chose which disk you want to create:"##選擇需要創(chuàng)建的磁盤編號 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 ##創(chuàng)建磁盤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.添加四個節(jié)點(diǎn)域名解析
vim /etc/hosts 192.168.3.11 node1 192.168.3.12 node2 192.168.3.13 node3 192.168.3.14 node45.安裝本地源GFS
- 四個節(jié)點(diǎn)相同操作
- 添加節(jié)點(diǎn)到存儲信任池中(在node1節(jié)點(diǎn)上操作)
6.創(chuàng)建卷
- 根據(jù)規(guī)劃創(chuàng)建如下卷
| dis-volume | 分布式卷 | node1(/data/sdb1)、node2(/data/sdb1) |
| stripe-volume | 條帶卷 | node1(/data/sdc1)、node2(/data/sdc1) |
| rep-volume | 復(fù)制卷 | node3(/data/sdb1)、node4(/data/sdb1) |
| dis-stripe | 分布式條帶卷 | node1(/data/sdd1)、node2(/data/sdd1)、node3(/data/sdd1)、node4(/data/sdd1) |
| dis-rep | 分布式復(fù)制卷 | node1(/data/sde1)、node2(/data/sde1)、node3(/data/sde1)、node4(/data/sde1) |
1.創(chuàng)建分布式卷
#創(chuàng)建分布式卷,沒有指定類型,默認(rèn)創(chuàng)建的是分布式卷 gluster volume create dis-volume node1:/data/sdb1 node2:/data/sdb1 force #查看卷列表 gluster volume list #啟動新建分布式卷 gluster volume start dis-volume #查看創(chuàng)建分布式卷信息 gluster volume info dis-volume2.創(chuàng)建條帶卷
#指定類型為 stripe,數(shù)值為 2,且后面跟了 2 個 Brick Server,所以創(chuàng)建的是條帶卷 gluster volume create stripe-volume stripe 2 node1:/data/sdc1 node2:/data/sdc1 force#啟動新建條帶卷 gluster volume start stripe-volume #查看創(chuàng)建條帶卷信息 gluster volume info stripe-volume3.創(chuàng)建復(fù)制卷
#指定類型為 replica,數(shù)值為 2,且后面跟了 2 個 Brick Server,所以創(chuàng)建的是復(fù)制卷 gluster volume create rep-volume replica 2 node3:/data/sdb1 node4:/data/sdb1 force#啟動新建復(fù)制卷 gluster volume start rep-volume #查看創(chuàng)建復(fù)制卷信息 gluster volume info rep-volume4.創(chuàng)建分布式條帶卷
#指定類型為 stripe,數(shù)值為 2,而且后面跟了 4 個 Brick Server,是 2 的兩倍,所以創(chuàng)建的是分布式條帶卷 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 #查看創(chuàng)建分布式條帶卷信息 gluster volume info dis-stripe5.創(chuàng)建分布式復(fù)制卷
#指定類型為 replica,數(shù)值為 2,而且后面跟了 4 個 Brick Server,是 2 的兩倍,所以創(chuàng)建的是分布式復(fù)制卷 gluster volume create dis-rep replica 2 node1:/data/sde1 node2:/data/sde1 node3:/data/sde1 node4:/data/sde1 force#啟動新建分布式復(fù)制卷 gluster volume start dis-rep #查看創(chuàng)建分布式復(fù)制卷信息 gluster volume info dis-rep- 此時再去查看卷列表,應(yīng)有五個卷
二、客戶端配置
- 客戶端的操作:在node1上創(chuàng)建五個卷后,在客戶端上把卷掛載在指定的五個目錄內(nèi),在目錄內(nèi)寫入了五個文件,五個文件分別保存在五個目錄里面
1.安裝客戶端
cd /opt wget http://112.124.46.81/gfsrepo.zip //下載安裝包 unzip gfsrepo.zip //解壓cd /etc/yum.repos.d/ mkdir repo.bak //創(chuàng)建備份目錄 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#創(chuàng)建掛載目錄 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 文件系統(tǒng) 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.驗(yàn)證gluster文件系統(tǒng)
- gluster服務(wù)器上查看文件分布
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節(jié)點(diǎn)關(guān)閉(模擬宕機(jī)),再回到客戶端檢查,可以看到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.且發(fā)現(xiàn)條帶卷(node1/2)數(shù)據(jù)為0,不具備冗余 [root@client test]# ll -h stripe/ 總用量 04.關(guān)閉node3,測試復(fù)制卷(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 #可以看到數(shù)據(jù)仍然存在,不受影響5.查看分布式條帶卷(node1/2/3/4) [root@client test]# ll -h dis_stripe/ 總用量 0 #也并不具備冗余性6.查看分布式復(fù)制卷(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結(jié)果證明:只要帶復(fù)制數(shù)據(jù)的相比而言,數(shù)據(jù)比較安全
三、Gluster的其他的維護(hù)命令
1.查看GlusterFS卷 gluster volume list2.查看所有卷的信息 gluster volume info3.查看所有卷的狀態(tài) gluster volume status4.停止一個卷 gluster volume stop dis-stripe5.刪除一個卷 gluster volume delete dis-stripe #注意:刪除卷時,需要先停止卷,且信任池中不能有主機(jī)處于宕機(jī)狀態(tài),否則不能成功刪除6.設(shè)置卷的訪問控制 gluster volume set dis-rep auth.allow 192.168.3.100 #僅拒絕,設(shè)置為IP地址為192.168.3.100的主機(jī)禁止訪問dis-rep(分布式復(fù)制卷)gluster volume set dis-rep auth.allow 192.168.3.* #僅允許,設(shè)置為192.168.3.0網(wǎng)段的所有IP地址都能訪問dis-rep(分布式復(fù)制卷)總結(jié)
以上是生活随笔為你收集整理的一文看懂GFS如何搭建的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关闭vs实时调试
- 下一篇: html a3纸大小,a0-a3纸的尺寸