新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
GFS分布式文件系統(tǒng)集群(實踐篇)-創(chuàng)新互聯(lián)
實踐部署
實踐環(huán)境
- 開啟5臺Linux虛擬機,并在其中四臺分別添加4塊硬盤,每塊硬盤內(nèi)存為:20G
- 開啟后分別設(shè)置虛擬機名稱為:node1、node2、node3、node4、client
- 服務(wù)器地址分別為
- node1:192.168.116.128
- node2:192.168.116.130
- node3:192.168.116.129
- node4:192.168.116.131
- client:192.168.116.132
在所有虛擬機中配置主機名解析
vim /etc/hosts
...
192.168.116.128 node1
192.168.116.130 node2
192.168.116.129 node3
192.168.116.131 node4
:wq
在node1節(jié)點服務(wù)器中編輯格式磁盤腳本,并執(zhí)行腳本
mkdir /abc //創(chuàng)建目錄
cd /abc
vim disk.sh //編輯腳本
mkdir -p /data/sd{b..e}1
for i in {b..e};do
echo 'n
w' | fdisk /dev/sd${i}
mkfs.xfs /dev/sd${i}1
mount /dev/sd${i}1 /data/sd${i}1
done
:wq
chmod +x disk.sh //添加執(zhí)行權(quán)限
./disk.sh //執(zhí)行腳本
df -hT //查看磁盤信息
文件系統(tǒng) 類型 容量 已用 可用 已用% 掛載點
/dev/sda2 xfs 20G 1.5G 19G 8% /
devtmpfs devtmpfs 903M 0 903M 0% /dev
tmpfs tmpfs 912M 0 912M 0% /dev/shm
tmpfs tmpfs 912M 8.6M 904M 1% /run
tmpfs tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda5 xfs 8.0G 33M 8.0G 1% /home
/dev/sda1 xfs 8.0G 135M 7.9G 2% /boot
tmpfs tmpfs 183M 0 183M 0% /run/user/0
/dev/sdb1 xfs 20G 33M 20G 1% /data/sdb1
/dev/sdc1 xfs 20G 33M 20G 1% /data/sdc1
/dev/sdd1 xfs 20G 33M 20G 1% /data/sdd1
/dev/sde1 xfs 20G 33M 20G 1% /data/sde1 //成功分區(qū)
將腳本文件分別推送到兩外3個節(jié)點服務(wù)器,并分別執(zhí)行腳本文件
scp disk.sh root@192.168.116.130:/opt/
scp disk.sh root@192.168.116.129:/opt/
scp disk.sh root@192.168.116.131:/opt/
在所有node節(jié)點服務(wù)器中搭建yum源,使用yum源安裝GFS服務(wù)
- GFS軟件yum包下載
mount.cifs //192.168.80.2/shares /abc/ //掛載yum存放目錄 cd /etc/yum.repos.d/ //進入yum倉庫目錄 mkdir bak //創(chuàng)建文件夾 mv CentOS-* bak/ //將已存在的源全部放入創(chuàng)建的文件夾內(nèi) vim glfs.repo //編輯yum源 [glfs] name=glfs baseurl=file:///abc/gfsrepo //指定yum源路徑 gpgcheck=0 enabled=1 :wq yum list //重新加載yum倉庫 yum install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma -y //安裝GFS服務(wù) systemctl stop firewalld.service //關(guān)閉防火墻 setenforce 0 //關(guān)閉selinux systemctl start glusterd.service //啟動gfs服務(wù) systemctl enable glusterd.service //設(shè)置開啟自啟 ntpdate ntp1.aliyun.com //同步阿里云時間
進入node1節(jié)點服務(wù)器,添加信任節(jié)點
gluster peer probe node2 gluster peer probe node3 gluster peer probe node4
在所有節(jié)點服務(wù)器查看信任節(jié)點信息
gluster peer status
Number of Peers: 3
Hostname: node2
Uuid: 86e94693-aaaf-4eb9-91d6-edce0489e4f7
State: Peer in Cluster (Connected)
Hostname: node3
Uuid: 1ee7a579-4a0e-493e-8709-d8234b8bb858
State: Peer in Cluster (Connected)
Hostname: node4
Uuid: b98e1eb0-3639-47be-a767-3a3df125443a
State: Peer in Cluster (Connected)
在node1節(jié)點創(chuàng)建分布式卷
[root@node1 yum.repos.d]# gluster volume create dis-vol node1:/data/sdb1 node2:/data/sdb1 force //創(chuàng)建分布式卷 force 強制執(zhí)行
[root@node1 yum.repos.d]# gluster volume info dis-vol //查看卷信息
Volume Name: dis-vol
Type: Distribute
Volume ID: 370023d1-cdc9-4b0d-9c57-663ebad503cd
Status: Created
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdb1
Brick2: node2:/data/sdb1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
[root@node1 yum.repos.d]# gluster volume list //查看創(chuàng)建的卷
dis-vol
[root@node1 yum.repos.d]# gluster volume start dis-vol //啟動卷
volume start: dis-vol: success
[root@node1 yum.repos.d]# gluster volume status dis-vol //查看卷狀態(tài)
tatus of volume: dis-vol
Gluster process TCP Port RDMA Port Online Pid
------------------------------------------------------------------------------
Brick node1:/data/sdb1 49152 0 Y 12100
Brick node2:/data/sdb1 49152 0 Y 11714
Task Status of Volume dis-vol
------------------------------------------------------------------------------
There are no active volume tasks
[root@node1 yum.repos.d]# gluster volume info dis-vol //再次查看卷信息
Volume Name: dis-vol
Type: Distribute
Volume ID: 370023d1-cdc9-4b0d-9c57-663ebad503cd
Status: Started //處于啟動狀態(tài)
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdb1
Brick2: node2:/data/sdb1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
創(chuàng)建條帶卷
[root@node1 yum.repos.d]# gluster volume create stripe-vol stripe 2 node1:/data/sdc1 node2:/data/sdc1 force
volume create: stripe-vol: success: please start the volume to access data
[root@node1 yum.repos.d]# gluster volume start stripe-vol
volume start: stripe-vol: success
[root@node1 yum.repos.d]# gluster volume info stripe-vol
Volume Name: stripe-vol
Type: Stripe
Volume ID: da81b00a-0e98-43d9-b55a-726c758ecef9
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdc1
Brick2: node2:/data/sdc1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
創(chuàng)建復(fù)制卷
[root@node1 yum.repos.d]# gluster volume create rep-vol replica 2 node3:/data/sdb1 node4:/data/sdb1 force
volume create: rep-vol: success: please start the volume to access data
[root@node1 yum.repos.d]# gluster volume start rep-vol
volume start: rep-vol: success
[root@node1 yum.repos.d]# gluster volume info rep-vol
Volume Name: rep-vol
Type: Replicate
Volume ID: fa5bd0c7-5d8d-49da-a25d-9d3fb0592fe3
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node3:/data/sdb1
Brick2: node4:/data/sdb1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
創(chuàng)建分布式條帶卷(至少4個節(jié)點)
[root@node1 yum.repos.d]# gluster volume create dis-stripe stripe 2 node1:/data/sdd1 node2:/data/sdd1 node3:/data/sdd1 node4:/data/sdd1 force
volume create: dis-stripe: success: please start the volume to access data
[root@node1 yum.repos.d]# gluster volume start dis-stripe
volume start: dis-stripe: success
[root@node1 yum.repos.d]# gluster volume info dis-stripe
Volume Name: dis-stripe
Type: Distributed-Stripe
Volume ID: 6dc5d7c3-76ed-437d-b5fe-e0b875c0de18
Status: Started
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdd1
Brick2: node2:/data/sdd1
Brick3: node3:/data/sdd1
Brick4: node4:/data/sdd1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
創(chuàng)建分布式復(fù)制卷(至少4個節(jié)點)
[root@node1 yum.repos.d]# gluster volume create dis-rep replica 2 node1:/data/sde1 node2:/data/sde1 node3:/data/sde1 node4:/data/sde1 force
volume create: dis-rep: success: please start the volume to access data
[root@node1 yum.repos.d]# gluster volume start dis-rep
volume start: dis-rep: success
[root@node1 yum.repos.d]# gluster volume info dis-rep
Volume Name: dis-rep
Type: Distributed-Replicate
Volume ID: dd2c8b19-d63b-42aa-be66-ca760335d0a0
Status: Started
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: node1:/data/sde1
Brick2: node2:/data/sde1
Brick3: node3:/data/sde1
Brick4: node4:/data/sde1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
查看創(chuàng)建的卷
[root@node1 yum.repos.d]# gluster volume list
dis-rep
dis-stripe
dis-vol
rep-vol
stripe-vol
client配置
systemctl stop firewalld.service //關(guān)閉防火墻
setenforce 0
mkdir /abc
mount.cifs //192.168.100.8/shares /abc/ //掛載yum源碼包目錄
cd /etc/yum.repos.d/
mkdir bak
mv CentOS-* bak/
vim glfs.repo //創(chuàng)建yum源
[glfs]
name=glfs
baseurl=file:///abc/gfsrepo
gpgcheck=0
enabled=1
:wq
yum list
yum install glusterfs glusterfs-fuse -y //安裝GFS
mkdir -p /text/dis
mkdir /text/strip
mkdir /text/rep
mkdir /text/dis-str
mkdir /text/dis-rep //創(chuàng)建5個掛載點目錄
mount.glusterfs node1:dis-vol /text/dis/ //掛載分布式卷
mount.glusterfs node1:stripe-vol /text/strip/ //掛載條帶卷
mount.glusterfs node3:rep-vol /text/rep/ //掛載復(fù)制卷
mount.glusterfs node2:dis-stripe /text/dis-str/ //掛載分布式條帶卷
mount.glusterfs node4:dis-rep /text/dis-rep/ //掛載分布式復(fù)制卷
df -h
件系統(tǒng) 容量 已用 可用 已用% 掛載點
···
node1:dis-vol 20G 265M 20G 2% /test/dis
node1:stripe-vol 20G 265M 20G 2% /test/strip
node1:rep-vol 10G 233M 9.8G 3% /test/rep
node1:dis-stripe 40G 330M 40G 1% /test/dis_stripe
node1:dis-rep 20G 265M 20G 2% /test/dis_rep
在client服務(wù)器中創(chuàng)建5個40M的文件,并將文件分別復(fù)制到5個掛載目錄中
dd if=/dev/zero of=/demo1.log bs=1M count=40
dd if=/dev/zero of=/demo2.log bs=1M count=40
dd if=/dev/zero of=/demo3.log bs=1M count=40
dd if=/dev/zero of=/demo4.log bs=1M count=40
dd if=/dev/zero of=/demo5.log bs=1M count=40
cp /demo* /test/dis
cp /demo* /test/strip
cp /demo* /test/rep
cp /demo* /test/dis_stripe
cp /demo* /test/dis_rep
在node1、node2中查看分布式卷存放方式
[root@node1 ~]# ll -h /data/sdb1/
總用量 160M
-rw-r--r--. 2 root root 40M 12月 18 16:22 demo1.log //每個文件都是完整的
-rw-r--r--. 2 root root 40M 12月 18 16:22 demo2.log
-rw-r--r--. 2 root root 40M 12月 18 16:22 demo3.log
-rw-r--r--. 2 root root 40M 12月 18 16:22 demo4.log
[root@node2 ~]# ll -h /data/sdb1/
總用量 40M
-rw-r--r--. 2 root root 40M 12月 18 16:22 demo5.log //通過hash算法分布式存放在兩臺節(jié)點服務(wù)器中
在node1、node2中查看條帶卷存放方式
[root@node1 ~]# ll -h /data/sdc1/
總用量 100M
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo1.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo2.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo3.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo4.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo5.log
[root@node2 ~]# ll -h /data/sdc1/
總用量 100M
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo1.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo2.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo3.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo4.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo5.log
//所有文件都被分成各一半進行分布存儲
在node3、node4中查看復(fù)制卷
[root@node3 ~]# ll -h /data/sdb1
總用量 200M
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo1.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo2.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo3.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo4.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo5.log
[root@node4 ~]# ll -h /data/sdb1/
總用量 200M
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo1.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo2.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo3.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo4.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo5.log
//所有文件都被完整復(fù)制一遍,進行存儲
分別在所有節(jié)點服務(wù)器中查看分布式條帶卷存放方式
[root@node1 ~]# ll -h /data/sdd1/
總用量 80M
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo1.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo2.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo3.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo4.log
[root@node2 ~]# ll -h /data/sdd1/
總用量 80M
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo1.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo2.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo3.log
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo4.log
[root@node3 ~]# ll -h /data/sdd1/
總用量 20M
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo5.log
[root@node4 ~]# ll -h /data/sdd1/
總用量 20M
-rw-r--r--. 2 root root 20M 12月 18 16:23 demo5.log
//根據(jù)哈希算法將部分?jǐn)?shù)據(jù)分布到前兩個節(jié)點各存儲一般,另一部分?jǐn)?shù)據(jù)分配到另外兩個節(jié)點各存儲一半
分別在所有節(jié)點服務(wù)器中查看分布式復(fù)制卷存放方式
[root@node1 ~]# ll -h /data/sde1/
總用量 160M
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo1.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo2.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo3.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo4.log
[root@node2 ~]# ll -h /data/sde1/
總用量 160M
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo1.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo2.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo3.log
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo4.log
[root@node3 ~]# ll -h /data/sde1/
總用量 40M
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo5.log
[root@node4 ~]# ll -h /data/sde1/
總用量 40M
-rw-r--r--. 2 root root 40M 12月 18 16:23 demo5.log
通過哈希算分布在兩個節(jié)點上存儲,另外兩個節(jié)點分別保存副本
在node1刪除卷
[root@node1 ~]# gluster volume list //查看已有的卷
die-replica
dis-stripe
dis-vol
rep-vol
stripe-vol
[root@node1 ~]# gluster volume stop rep-vol //停止要刪除的卷
topping volume will make its data inaccessible. Do you want to continue? (y/n) y //輸入y確認(rèn)停止
volume stop: rep-vol: success
[root@node1 ~]# gluster volume delete rep-vol //執(zhí)行命令刪除卷
Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
volume delete: rep-vol: success //成功刪除
[root@node1 ~]# gluster volume list //再次查看卷,已成功刪除
die-replica
dis-stripe
dis-vol
stripe-vol
訪問控制設(shè)置
gluster volume set dis-vol auth.reject 192.168.116.130 //設(shè)置拒絕主機訪問、掛載
gluster volume set dis-vol auth.allow 192.168.116.130 //設(shè)置允許主機訪問、掛載
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)站名稱:GFS分布式文件系統(tǒng)集群(實踐篇)-創(chuàng)新互聯(lián)
URL標(biāo)題:http://www.dlmjj.cn/article/dcdoio.html