最小化安裝的CentOS 7.5
內存大于1GB
關閉selinux,防火墻端口放行(port:24007,111)(測試建議關閉firewalld)
一、環(huán)境部署
所有軟件包離線安裝,原因是yum安裝的不能很好的控制版,用到的軟件包統(tǒng)一放到/gfs目錄,包已整理好
——————————————分割線——————————————
Matlab R2017b的Linux版下載地址可從以下信息的得到下載:
點擊這個http://www.linuxidc.com/Linux/2013-12/93755.htm 鏈接關注 Linux公社官方微信,關注后回復數(shù)字158712。即可得到網(wǎng)友的分享密碼。
如果取消關注Linux公社公眾號,即使再次關注,也將無法提供本服務!
鏈接: https://pan.baidu.com/s/1eSSX46yaGBUoEmCqjeAeqw 密碼:獲得見上面的方法,地址失效請在下面留言。
——————————————分割線——————————————
-
測試用的磁盤分配以及服務器架構圖
- basic代表服務器本來使用的磁盤,基礎上再添加上圖相應的磁盤,由于是測試用,為方便直觀理解,磁盤大小就是后面的數(shù)字:如sdb3,該磁盤大小為3GB。
-
卷的分布方案
卷名稱 | 卷類型 | 空間大小/GB | 存儲塊 |
---|---|---|---|
dis-volume | 分布式卷 | 12 | node1(/sde6),node2(/sde6) |
stripe-volume | 條帶卷 | 10 | node1(/sdd5),node2(/sdd5) |
rep-volume | 復制卷 | 5 | node3(/sdd5),node4(/sdd5) |
dis-stripe | 分布式條帶卷 | 12 | node1(/sdb3),node2(/sdb3),node3(/sdb3),node4(/sdb3) |
dis-rep | 分布式復制卷 | 8 | node1(/sdc4),node2(/sdc4),node3(sdc4),node4(sdc4) |
- 全部主機修改主機名
- 全部主機配置hosts文件,一樣的
- 全部node主機創(chuàng)建掛載文件夾,依實際掛載點創(chuàng)建
-
全部主機創(chuàng)建/gfs文件夾,將所需軟件包放入
mkdir /{gfs,sdb3,sdc4,sdd5} cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.64.11 node1 192.168.64.12 node2 192.168.64.13 node3 192.168.64.14 node4 192.168.64.15 client
- 完畢之后進行ping測試
- 通過傳輸方式將軟件包上傳到/gfs文件(里面有一個repo文件夾也要上傳)
- 以上一切完成之后,全部node主機執(zhí)行以下腳本
vim install.sh #!/bin/bash for i in $(fdisk -l | grep -wo "/dev/sd[b-z]" | sort) do dd if=/dev/zero of=$i bs=1024 count=1024 fdisk $i << EOF n p w EOF #空行很重要不要刪除 partprobe $i #//不重啟系統(tǒng)識別分區(qū) mkfs.ext4 ${i}1 #//格式化分區(qū) done mkdir /b3 /c4 /d5 /e6 fdisk -l | grep -w "/dev/sd[b-z]" | sed -r 's/.*(/d.{8}).*/1/g' | sed -r 's/(.*)(.{3}):(.*)/mount 121 /23/' | bash fdisk -l | grep -w "/dev/sd[b-z]" | sed -r 's/.*(/d.{8}).*/1/g' | sed -r 's/(.*)(.{3}):(.*)/121 /23 xfs default 0 0/' >> /etc/fstab #-w 只顯示全字符合的列。 iptables -F systemctl stop firewalld setenforce 0 cat << EOF >> /etc/yum.repos.d/gfs.repo [gfs] name=gfs baseurl=file:///gfs gpgcheck=0 enabled=1 EOF yum clean all && yum makecache yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma systemctl start glusterd systemctl enable glusterd EOF
sh install.sh //執(zhí)行腳本 netstat -lnpt //查看gluster服務端口是否開啟
腳本簡單理解
- 再node1上執(zhí)行如下命令構建gluster集群
[root@node1 ~]# gluster peer probe node2 peer probe: success. [root@node1 ~]# gluster peer probe node3 peer probe: success. [root@node1 ~]# gluster peer probe node4 peer probe: success.
[root@node1 ~]# gluster peer status //在每個節(jié)點上執(zhí)行查看集群狀態(tài);正常時為(Connected)
二、創(chuàng)建卷
1.創(chuàng)建分布式卷(擴大磁盤空間,讀寫速度快,沒有容錯能力)
[root@node1 ~]# gluster volume create dis-volume node1:/sde6 node2:/sde6 force //dis-volume為卷名稱,未指定創(chuàng)建卷類型,默認為分布式卷 volume create: dis-volume: success: please start the volume to access data [root@node1 ~]# gluster volume start dis-volume volume start: dis-volume: success [root@node1 ~]# gluster volume info dis-volume //查看該卷的相關信息
2.創(chuàng)建條帶卷(以數(shù)據(jù)塊為單位存儲,沒有容錯性)
[root@node1 ~]# gluster volume create stripe-volume stripe 2 node1:/sdd5 node2:/sdd5 force [root@node1 ~]# gluster volume start stripe-volume volume start: stripe-volume: success //stripe表示卷類型條帶卷,后面的數(shù)量表示條帶數(shù)
3.創(chuàng)建復制卷(磁盤空間為總空間一半,具備容錯性,讀快,寫慢)
[root@node1 ~]# gluster volume create rep-volume replica 2 node3:/sdd5 node4:/sdd5 force [root@node1 ~]# gluster volume start rep-volume volume start: rep-volume: success
4.創(chuàng)建分布式條帶卷(加大容量,讀取快,沒有容錯性)
[root@node1 ~]# gluster volume create dis-stripe stripe 2 node1:/sdb3 node2:/sdb3 node3:/sdb3 node4:/sdb3 force //指定類型為Distributed-Stripe,數(shù)值為2,而且后面跟了4個Brick Server,是2的2倍,所以創(chuàng)建的是分布式條帶卷。 volume create: dis-stripe: success: please start the volume to access data [root@node1 ~]# gluster volume start dis-stripe volume start: dis-stripe: success
5.創(chuàng)建分布式復制卷(擴展空間,總空間的一半,且具有容錯能力)
[root@node1 ~]# gluster volume create dis-rep replica 2 node1:/sdc4 node2:/sdc4 node3:/sdc4 node4:/sdc4/ force //指定類型為Distributed-Replicate,數(shù)值為2,而且后面跟了4個Brick Server,是2的2倍,所以創(chuàng)建的是分布式復制卷。 volume create: dis-rep: success: please start the volume to access data [root@node1 ~]# gluster volume start dis-rep volume start: dis-rep: success
三、部署Gluster客戶端
1.安裝客戶端軟件
- 將軟件包放至/gfs文件夾
- 修改前面提到的hostname以及hosts
- 運行如下腳本
vim in_cl.sh #!/bin/bash cat << EOF >> /etc/yum.repos.d/gfs.repo [gfs] name=gfs baseurl=file:///gfs gpgcheck=0 enabled=1 EOF yum clean all && yum makecache yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma systemctl start glusterd systemctl enable glusterd
sh in_cl.sh netstat -lnpt | grep glu //可以看到服務已經(jīng)啟動
[root@client ~]# mkdir -pv /test/{dis,stripe,rep,dis_stripe,dis_rep} //創(chuàng)建掛載目錄 [root@client ~]# mount -t glusterfs node1:dis-volume /test/dis [root@client ~]# mount -t glusterfs node1:stripe-volume /test/stripe/ [root@client ~]# mount -t glusterfs node1:rep-volume /test/rep/ [root@client ~]# mount -t glusterfs node1:dis-stripe /test/dis_stripe/ [root@client ~]# mount -t glusterfs node1:dis-rep /test/dis_rep/ //掛載glusterfs文件系統(tǒng)到本地客戶端,所制定的node1節(jié)點只是為了獲取配置信息,不代表只和他進行數(shù)據(jù)傳輸,會根據(jù)配置針對集群來進行數(shù)據(jù)的存放
- 修改fstab文件實現(xiàn)永久掛載
-
添加如下文件
vim /etc/fstab
node1:dis-volume /test/dis glusterfs defaults,_netdev 0 0 node1:stripe-volume /test/stripe glusterfs defaults,_netdev 0 0 node1:rep-volume /test/rep glusterfs defaults,_netdev 0 0 node1:dis-rep /test/dis_rep glusterfs defaults,_netdev 0 0 node1:dis-stripe /test/dis_stripe glusterfs defaults,_netdev 0 0
四、測試
-
生成測試文件(該文件雖沒有數(shù)據(jù),但是可以進行測試用途)
[root@client ~]# for i in {1..5};do dd if=/dev/zero of=/root/demon$i.log bs=1M count=43;done [root@client ~]# cp demon* /test/dis && cp demon* /test/dis_rep/ && cp demon* /test/dis_stripe/ && cp demon* /test/rep/ && cp demon* /test/stripe/
- 查看文件分布狀態(tài)
- 分布式卷(node1和node2的/sde6目錄查看,可以看到文件被分散開存放)
[root@node1 ~]# ll -h /sde6/ 總用量 130M -rw-r--r--. 2 root root 43M 4月 2 21:32 demon1.log -rw-r--r--. 2 root root 43M 4月 2 21:32 demon3.log -rw-r--r--. 2 root root 43M 4月 2 21:32 demon4.log drwx------. 2 root root 16K 4月 3 2019 lost+found [root@node2 ~]# ll -h /sde6/ 總用量 87M -rw-r--r--. 2 root root 43M 4月 3 05:32 demon2.log -rw-r--r--. 2 root root 43M 4月 3 05:32 demon5.log drwx------. 2 root root 16K 4月 3 03:01 lost+found
- 條帶卷(node1和node2的/sdd5目錄查看,清晰看到是以數(shù)據(jù)塊為單位存儲的)
[root@node1 ~]# ls -lh /sdd5/ 總用量 108M -rw-r--r--. 2 root root 22M 4月 2 21:31 demon1.log -rw-r--r--. 2 root root 22M 4月 2 21:31 demon2.log -rw-r--r--. 2 root root 22M 4月 2 21:31 demon3.log -rw-r--r--. 2 root root 22M 4月 2 21:31 demon4.log -rw-r--r--. 2 root root 22M 4月 2 21:31 demon5.log [root@node2 ~]# ls -lh /sdd5/ 總用量 108M -rw-r--r--. 2 root root 22M 4月 3 05:31 demon1.log -rw-r--r--. 2 root root 22M 4月 3 05:31 demon2.log -rw-r--r--. 2 root root 22M 4月 3 05:31 demon3.log -rw-r--r--. 2 root root 22M 4月 3 05:31 demon4.log -rw-r--r--. 2 root root 22M 4月 3 05:31 demon5.log
- 復制卷(node3和node4的/sdd5目錄,數(shù)據(jù)有備份)
[root@node3 ~]# ls -lh /sdd5/ 總用量 216M -rw-r--r--. 2 root root 43M 4月 3 05:32 demon1.log -rw-r--r--. 2 root root 43M 4月 3 05:32 demon2.log -rw-r--r--. 2 root root 43M 4月 3 05:33 demon3.log -rw-r--r--. 2 root root 43M 4月 3 05:33 demon4.log -rw-r--r--. 2 root root 43M 4月 3 05:33 demon5.log drwx------. 2 root root 16K 4月 3 03:03 lost+found [root@node4 ~]# ls -lh /sdd5/ 總用量 216M -rw-r--r--. 2 root root 43M 4月 3 05:32 demon1.log -rw-r--r--. 2 root root 43M 4月 3 05:32 demon2.log -rw-r--r--. 2 root root 43M 4月 3 05:33 demon3.log -rw-r--r--. 2 root root 43M 4月 3 05:33 demon4.log -rw-r--r--. 2 root root 43M 4月 3 05:33 demon5.log drwx------. 2 root root 16K 4月 3 02:55 lost+found
- 分布式條帶卷(節(jié)點1、2、3、4的/sdb3目錄,我日期沒有調整,海涵)
[root@node1 ~]# ls -lh /sdb3/ 總用量 65M -rw-r--r--. 2 root root 22M 4月 2 21:32 demon1.log -rw-r--r--. 2 root root 22M 4月 2 21:32 demon3.log -rw-r--r--. 2 root root 22M 4月 2 21:32 demon4.log drwx------. 2 root root 16K 4月 2 18:37 lost+found [root@node2 ~]# ls -lh /sdb3/ 總用量 65M -rw-r--r--. 2 root root 22M 4月 3 05:32 demon1.log -rw-r--r--. 2 root root 22M 4月 3 05:32 demon3.log -rw-r--r--. 2 root root 22M 4月 3 05:32 demon4.log drwx------. 2 root root 16K 4月 3 03:01 lost+found [root@node3 ~]# ls -lh /sdb3/ 總用量 44M -rw-r--r--. 2 root root 22M 4月 3 05:32 demon2.log -rw-r--r--. 2 root root 22M 4月 3 05:32 demon5.log drwx------. 2 root root 16K 4月 3 03:03 lost+found [root@node4 ~]# ls -lh /sdb3/ 總用量 44M -rw-r--r--. 2 root root 22M 4月 3 05:32 demon2.log -rw-r--r--. 2 root root 22M 4月 3 05:32 demon5.log drwx------. 2 root root 16K 4月 3 02:55 lost+found
- 分布式復制卷(節(jié)點1、2、3、4的/sdc4目錄,可看到文件沒有被分片,但是是分布開來存放的)
[root@node1 ~]# ls -lh /sdc4/ 總用量 130M -rw-r--r--. 2 root root 43M 4月 2 21:32 demon1.log -rw-r--r--. 2 root root 43M 4月 2 21:32 demon3.log -rw-r--r--. 2 root root 43M 4月 2 21:32 demon4.log drwx------. 2 root root 16K 4月 3 2019 lost+found [root@node2 ~]# ls -lh /sdc4/ 總用量 130M -rw-r--r--. 2 root root 43M 4月 3 05:32 demon1.log -rw-r--r--. 2 root root 43M 4月 3 05:32 demon3.log -rw-r--r--. 2 root root 43M 4月 3 05:32 demon4.log drwx------. 2 root root 16K 4月 3 03:01 lost+found [root@node3 ~]# ls -lh /sdc4/ 總用量 87M -rw-r--r--. 2 root root 43M 4月 3 05:32 demon2.log -rw-r--r--. 2 root root 43M 4月 3 05:32 demon5.log drwx------. 2 root root 16K 4月 3 03:01 lost+found [root@node4 ~]# ls -lh /sdc4/ 總用量 87M -rw-r--r--. 2 root root 43M 4月 3 05:32 demon2.log -rw-r--r--. 2 root root 43M 4月 3 05:32 demon5.log drwx------. 2 root root 16K 4月 3 03:01 lost+found
破壞測試
- 直接點關閉node2節(jié)點。關機操作。
- 客戶端操作
[root@client ~]# ls /test/dis/ demon1.log demon3.log demon4.log lost+found //可以看到另外兩個文件直接找不到了 [root@client ~]# ls /test/stripe/ [root@client ~]# //條帶卷因為文件都是分散開放,所以都沒有了 [root@client ~]# ls /test/dis_stripe/ demon2.log demon5.log lost+found //分布式條帶卷,因為是分布式存儲node2宕機導致數(shù)據(jù)不完整不會顯示,1,3,4號文件丟失 [root@client ~]# ls /test/dis_rep/ demon1.log demon2.log demon3.log demon4.log demon5.log lost+found //分布式復制卷完全不受任何影響 //總而言之,了解各卷的特點,再細心觀察以下文件分布的具體位置,才能盡可能保證數(shù)據(jù)可靠性
五、維護命令
[root@node3 ~]# gluster volume list dis-rep dis-stripe dis-volume rep-volume stripe-volume //任何一個節(jié)點都可以查看集群列表 [root@node1 ~]# gluster volume info //查看所有卷的信息 [root@node1 ~]# gluster volume status //查看卷的狀態(tài) [root@node3 ~]# gluster volume stop dis-stripe Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y volume stop: dis-stripe: success //停止卷 [root@node3 ~]# gluster volume start dis-stripe //啟動卷 [root@node3 ~]# gluster volume delete dis-stripe //刪除卷