GlusterFS概述
一、理论
Gluster fs是分布式存储文件系统,最大特点是没有元数据服务器,每个节点都可以作为集群的访问入口。
GFS特点
扩展性和高性能,可方便的增加服务器来提高性能,同时GFS本身的性能就很优秀
弹性哈希,GFS根据此算法在存储池中定位数据。
高可用性,配置复制卷后,可实现文件自动复制,当其中一个节点down掉时,不影响访问。
全局统一命名空间,将所有存储资源聚集成一个单一的虚拟存储池,对用户和应用屏蔽了物理存储信息。
弹性卷管理,gfs将数据存储在逻辑卷中,逻辑卷方便管理。
GFS架构
gfs server <---tcp/ib----> gfs client application
vfs
vfs
/dev/fuse
ext3 fuse
工作流程
1、客户端或应用程序通过gluster fs的挂载点访问数据.
2、linux系统内核通过vfs api收到请求并处理。
3、vfs将数据递交给fuse内核文件系统,并向系统注册一个实际的文件系统fuse,而fuse文件系统则是将数据通过/dev/fuse设备文件递交给了glusterfs client端。可以将fuse文件系统理解为一个代理。
4、glusterfs client收到数据后,cliten根据配置文件对数据进行处理。
5、经过glusterfs client处理后,通过网络将数据传递至远端的glusterfs server,并且将数据写入服务器存储设备。
二、实践
1、拓扑主机名 挂载磁盘 挂载目录
192.168.10.101 node1 /dev/sda(3G) /b3/dev/sdb(4G) /c4/dev/sdc(5G) /d5/dev/sdd(6G) /e6/dev/sde(7G) /f7192.168.10.102 node2 /dev/sda(3G) /b3/dev/sdb(4G) /c4/dev/sdc(5G) /d5/dev/sdd(6G) /e6/dev/sde(7G) /f7192.168.10.103 node3 /dev/sda(3G) /b3/dev/sdb(4G) /c4/dev/sdc(5G) /d5/dev/sdd(6G) /e6/dev/sde(7G) /f7192.168.10.104 node4 /dev/sda(3G) /b3/dev/sdb(4G) /c4/dev/sdc(5G) /d5/dev/sdd(6G) /e6/dev/sde(7G) /f7192.168.10.105 node5 /dev/sda(3G) /b3/dev/sdb(4G) /c4/dev/sdc(5G) /d5/dev/sdd(6G) /e6/dev/sde(7G) /f7192.168.10.106 node6 /dev/sda(3G) /b3/dev/sdb(4G) /c4/dev/sdc(5G) /d5/dev/sdd(6G) /e6/dev/sde(7G) /f7192.168.10.107 client卷名称 卷类型 空间大小 Brick
dis-volume 分布式卷 12G node1、2(/e6)
rep-volume 复制卷 5G node3、4(/d5)
stripe-volume 分散卷 10G node1、2、3、4(/b3)
dis-rep 分布式复制卷 8G node1、2、3、4(/c4)
dis-stripe 分布式分散卷 12G node1、2、3、4(/f7)2、过程
(1)创建集群
101、102、103、104、105、106
[root@localhost ~]# hostnamectl set-hostname node1
[root@localhost ~]# bash[root@localhost ~]# fdisk /dev/sda
[root@localhost ~]# fdisk /dev/sdb
[root@localhost ~]# fdisk /dev/sdc
[root@localhost ~]# fdisk /dev/sdd
[root@localhost ~]# fdisk /dev/sde[root@localhost ~]# mkfs -t xfs /dev/sda1
[root@localhost ~]# mkfs -t xfs /dev/sdb1
[root@localhost ~]# mkfs -t xfs /dev/sdc1
[root@localhost ~]# mkfs -t xfs /dev/sdd1
[root@localhost ~]# mkfs -t xfs /dev/sde1[root@localhost ~]# mkdir /b3
[root@localhost ~]# mkdir /c4
[root@localhost ~]# mkdir /d5
[root@localhost ~]# mkdir /e6
[root@localhost ~]# mkdir /f7[root@localhost ~]# mount /dev/sda1 /b3
[root@localhost ~]# mount /dev/sdb1 /c4
[root@localhost ~]# mount /dev/sdc1 /d5
[root@localhost ~]# mount /dev/sdd1 /e6
[root@localhost ~]# mount /dev/sde1 /f7[root@localhost ~]# vi /etc/fstab
/dev/sda1 /b3 xfs defaults 0 0
/dev/sdb1 /c4 xfs defaults 0 0
/dev/sdc1 /d5 xfs defaults 0 0
/dev/sdd1 /e6 xfs defaults 0 0
/dev/sde1 /f7 xfs defaults 0 0[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0[root@localhost ~]# cat <<EOF> /etc/hosts
192.168.10.101 node1
192.168.10.102 node2
192.168.10.103 node3
192.168.10.104 node4
192.168.10.105 node5
192.168.10.106 node6
EOF[root@localhost ~]# dnf -y install glusterfs glusterfs-server glusterfs-fuse注:
glusterfs:gluster客户端主程序
glusterfs-server:gluster服务端主程序
glusterfs-fuse:Filesystem Userspace是一个可加载的内核模块,其支持非特权用户创建自己的文件系统而不需要修改内核代码。通过在用户空间运行文件系统的代码通过FUSE代码与内核进行桥接。
s
[root@localhost ~]# systemctl start glusterd.service
[root@localhost ~]# systemctl enable glusterd.service 101
[root@localhost ~]# gluster peer probe node1
peer probe: success. Probe on localhost not needed
[root@localhost ~]# gluster peer probe node2
peer probe: success.
[root@localhost ~]# gluster peer probe node3
peer probe: success.
[root@localhost ~]# gluster peer probe node4
peer probe: success.
[root@localhost ~]# gluster peer probe node5
peer probe: success.
[root@localhost ~]# gluster peer probe node6
peer probe: success. [root@localhost ~]# gluster peer status
Number of Peers: 3Hostname: node2
Uuid: 469be571-b52a-4a89-a30a-c3a770753b0e
State: Peer in Cluster (Connected)Hostname: node3
Uuid: 24742939-afc6-4243-a8a8-1aa57a336128
State: Peer in Cluster (Connected)Hostname: node4
Uuid: dbc703a3-1e22-42cd-bedf-da3541bce983
State: Peer in Cluster (Connected)(2)、创建卷
101
[root@localhost ~]# gluster volume create dist-volume node1:/e6 node2:/e6 force
[root@localhost ~]# gluster volume info dist-volumeVolume Name: dist-volume
Type: Distribute
Volume ID: 40946bd8-cc79-406a-be3c-5c03dd2a207e
Status: Created
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/e6
Brick2: node2:/e6
Options Reconfigured:
transport.address-family: inet
nfs.disable: on[root@localhost ~]# gluster volume start dist-volume创建复制卷
[root@localhost ~]# gluster volume create rep-volume replica 2 node3:/d5 node4:/d5 force
[root@localhost ~]# gluster volume info rep-volumeVolume Name: rep-volume
Type: Replicate
Volume ID: b5d1afda-ab03-47a7-82b9-2786648a9b3a
Status: Created
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node3:/d5
Brick2: node4:/d5
Options Reconfigured:
transport.address-family: inet
nfs.disable: on[root@localhost ~]# gluster volume start rep-volume分散卷
gluster volume create disp-volume disperse 3 redundancy 1 node1:/b3 node2:/b3 node3:/b3 force[root@localhost ~]# gluster volume info disp-volume[root@localhost ~]# gluster volume start disp-volumegluster volume create strip-volume stripe 2 node1:/d5 node2:/d5 force创建分布式复制卷
[root@localhost ~]# gluster volume create dist-rep replica 2 node1:/c4 node2:/c4 node3:/c4 node4:/c4 force
[root@localhost ~]# gluster volume info dist-repVolume Name: dis-rep
Type: Distributed-Replicate
Volume ID: 197055f7-37d8-419f-bb22-9f05c7e1a032
Status: Created
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: node1:/c4
Brick2: node2:/c4
Brick3: node3:/c4
Brick4: node4:/c4
Options Reconfigured:
transport.address-family: inet
nfs.disable: on[root@localhost ~]# gluster volume start dist-rep分布式分散卷
gluster volume create dist-disp disperse 3 redundancy 1 node1:/f7 node2:/f7 node3:/f7 node4:/f7 node5:/f7 node6:/f7 forcegluster volume start dist-disp(3)、部署GFS客户端
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# yum -y install glusterfs glusterfs-fuse[root@localhost ~]# mkdir -p /test/{dist,rep,disp,dist_and_rep,dist_and_disp}
[root@localhost ~]# ls /test[root@localhost ~]# cat <<EOF> /etc/hosts
192.168.10.101 node1
192.168.10.102 node2
192.168.10.103 node3
192.168.10.104 node4
192.168.10.105 node5
192.168.10.106 node6
EOF[root@localhost ~]# mount -t glusterfs node1:dist-volume /test/dist
[root@localhost ~]# mount -t glusterfs node1:rep-volume /test/rep
[root@localhost ~]# mount -t glusterfs node1:disp-volume /test/disp[root@localhost ~]# mount -t glusterfs node1:dist-rep /test/dist_and_rep
[root@localhost ~]# mount -t glusterfs node1:dist-disp /test/dist_and_disp[root@localhost ~]# df -h5:修改fstab配置文件
[root@localhost ~]# vi /etc/fstab
在末尾添加:node1:dist-volume /test/dist glusterfs defaules,_netdev 0 0
node1:rep-volume /test/rep glusterfs defaules,_netdev 0 0
node1:dist-rep /test/dist_and_rep glusterfs defaules,_netdev 0 0
node1:disp-volume /test/disp glusterfs defaules,_netdev 0 0
node1:disp-rep /test/disp_and_rep glusterfs defaules,_netdev 0 0(4)、在客户端测试Gluster文件系统
dd if=/dev/zero of=/root/demo1.log bs=1M count=43
dd if=/dev/zero of=/root/demo2.log bs=1M count=43
dd if=/dev/zero of=/root/demo3.log bs=1M count=43
dd if=/dev/zero of=/root/demo4.log bs=1M count=43
dd if=/dev/zero of=/root/demo5.log bs=1M count=43
dd if=/dev/zero of=/root/demo6.log bs=1M count=43
dd if=/dev/zero of=/root/demo7.log bs=1M count=43
dd if=/dev/zero of=/root/demo8.log bs=1M count=43[root@localhost ~]# cp demo* /test/dist/
[root@localhost ~]# cp demo* /test/rep/
[root@localhost ~]# cp demo* /test/dist_and_rep/2:查看文件分布
node1和node2中查看分布式卷文件分布node1:
[root@localhost ~]# ll -h /e6
总用量 220M
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo1.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo2.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo3.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo4.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo5.lognode2:
[root@localhost ~]# ll -h /e6
总用量 132M
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo6.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo7.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo8.lognode3和node4中查看复制卷文件分布node3:
[root@localhost ~]# ll -h /d5
总用量 352M
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo1.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo2.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo3.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo4.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo5.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo6.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo7.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo8.lognode4:
[root@localhost ~]# ll -h /d5
总用量 352M
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo1.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo2.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo3.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo4.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo5.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo6.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo7.log
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo8.lognode1、node2、node3、node4中查看分布式复制卷文件分布node1:
[root@localhost ~]# ll -h /c4
总用量 173M
-rw-r--r--. 2 root root 43M 4月 17 22:06 demo1.log
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo2.log
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo3.log
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo4.log
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo5.lognode2:
[root@localhost ~]# ll -h /c4
总用量 173M
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo1.log
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo2.log
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo3.log
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo4.log
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo5.lognode3:
[root@localhost ~]# ll -h /c4
总用量 132M
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo6.log
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo7.log
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo8.lognode4:
[root@localhost ~]# ll -h /c4
总用量 132M
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo6.log
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo7.log
-rw-r--r--. 2 root root 43M 4月 17 22:07 demo8.log(5)、破坏性测试
挂起node2节点,客户端上查看/test/dist 发现只能看到demo1-5 查看/test/rep,发现demo1-8都可以看见。 查看/test/dist_and_rep发现demo1-8都能看见。再挂起node4,在客户端查看/test/rep,发现demo1-8都可以看见,查看/test/dist_and_rep发现demo1-8都能看见。