第七十一集 GlusterFS分布式文件系统☜(゚ヮ゚☜)


GlusterFS介绍

GlusterFS是一个高层次的分布式文件系统解决方案。通过增加一个逻辑层,对上层使用者掩盖了下面的实现,使用者不用了解也不需知道,文件的存储形式、分布。内部实现是整合了许多存储块并通过Infiniband RDMA或者 tcp/ip方式互联的一个并行的网络文件系统,这样的许多存储块可以通过许多廉价的x86主机,通过网络搭建起来。

适用场景

GlusterFS支持运行在任何标准IP网络上标准应用程序的标准客户端,如下图所示,用户可以在全局统一的命名空间中使用NFS/CIFS等标准协议来访问应用数据。GlusterFS采用弹性哈希算法数据分布策略,移除了元数据依赖,优化了数据分布,提高数据访问并行性,能够大幅提高大文件存储的性能。对于小文件,无元数据服务设计解决了元数据的问题。但GlusterFS并没有在I/O方面作优化,在存储服务器底层文件系统上仍然是大量小文件,本地文件系统元数据访问是一个瓶颈,数据分布和并行性也无法充分发挥作用。因此,GlusterFS适合存储大文件,小文件性能较差,还存在很大优化空间。

设计理念

GlusterFS主要由存储服务器、客户端以及 NFS/SAMBA 存储网关组成。不难发现,GlusterFS 架构中没有元数据服务器组件,这是其最大的设计点,对于提升整个系统的性能、可靠性和稳定性都有着决定性的意义。无元数据服务器设计的好处是没有单点故障和性能瓶颈问题,可提高系统扩展性、性能、可靠性和稳定性。对于海量小文件应用,这种设计能够有效解决元数据的难点问题。它的负面影响是,数据一致问题更加复杂,文件目录遍历操作效率低下,缺乏全局监控管理功能。同时也导致客户端承担了更多的职能,比如文件定位、名字空间缓存、逻辑卷视图维护等等,这些都增加了客户端的负载,占用相当的CPU和内存。

GlusterFS特点

拓展性和高性能
高可用性
全局统一命名空间(指共享),提供了一个API,为用户访问GFS服务器中数据的唯一入口
弹性卷管理
基于标准协议 :客户端和存储服务器交互需要借助网络,而相关的网络协议包括TCP/IP协议

GlusterFS组成

存储服务器:存储节点信息
客户端;存储元数据,帮用户定位文件的位置,索引等信息
NFS/Samba存储网关组成

GlusterFS专业术语

brick :用于存储用户数据的服务器
FUSE:远程的GFS,客户端的请求要交给FUSE(伪文件系统),就可以实现跨界点存储在GFS上
volume :本地文件系统的“分区”
VFS(虚拟端口):内核态的虚拟文件系统,用户是先提交请求给VFS,然后VFS交给FUSE再交给GFS客户端,最好客户端交给远程的存储
glusterd:是运行在存储节点的进程

卷的模式

为了满足不同应用对高性能、高可用的需求,GlusterFS 支持 7 种卷,即 distribute 卷、stripe 卷、replica 卷、distribute stripe 卷、distribute replica 卷、stripe Replica 卷、distribute stripe replica 卷。其实不难看出,GlusterFS的卷类型实际上可以分为3种基本卷和4种复合卷,每种类型的卷都有其自身的特点和适用场景。在企业生产环境中使用最多的是复合卷中的distribute replica 卷,即分布式复制卷。下面简单介绍一下分布式复制卷

GlusterFS集群部署

设备准备,四台CentOS7作为GFS节点,一台客户端

 - node1-4节点:磁盘/dev/sdb1		挂载点:/whd/sdb1
			 磁盘/dev/sde1		挂载点:/whd/sdc1
			 磁盘/dev/sdd1		挂载点:/whd/sdd1
			 磁盘/dev/sde1		挂载点:/whd/sde1
IP地址分别为:192.168.8.151		192.168.8.150
			192.168.8.152		192.168.8.153
client端:192.168.8.155

四台GFS同时操作

##用脚本进行磁盘分区并挂载

vim /opt/fdisk.sh
#!/bin/bash
echo "the disks exist list:"
##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   
do
    case $VAR in
    sda)
 ##本地磁盘就退出case语句
        fdisk -l /dev/sda   
        break ;;
    sd[b-z])
        #create partitions
        echo "n    ##创建磁盘
                p
                
                
           
                w"  | fdisk /dev/$VAR
 
        #make filesystem
##格式化
        mkfs.xfs -i size=512 /dev/${VAR}"1" &> /dev/null    
	#mount the system
        mkdir -p /data/${VAR}"1" &> /dev/null
###永久挂载
        echo -e "/dev/${VAR}"1" /data/${VAR}"1" xfs defaults 0 0\n" >> /etc/fstab
###使得挂载生效
        mount -a &> /dev/null
        break ;;
    quit)
        break;;
    *)
        echo "wrong disk,please check again";;
    esac
done

##给予权限,执行脚本

chmod +x /opt/fdisk.sh
cd /opt/
sh -x fdisk.sh						#连续四次,交互过程填写1,2,3,4
[root@node4 opt]# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda3      xfs       197G  5.4G  192G   3% /
devtmpfs       devtmpfs  895M     0  895M   0% /dev
tmpfs          tmpfs     910M     0  910M   0% /dev/shm
tmpfs          tmpfs     910M   11M  900M   2% /run
tmpfs          tmpfs     910M     0  910M   0% /sys/fs/cgroup
/dev/sda1      xfs       197M  152M   45M  78% /boot
tmpfs          tmpfs     182M  4.0K  182M   1% /run/user/42
tmpfs          tmpfs     182M   36K  182M   1% /run/user/0
/dev/sdb1      xfs        20G   33M   20G   1% /data/sdb1
/dev/sdc1      xfs        20G   33M   20G   1% /data/sdc1
/dev/sdd1      xfs        30G   33M   30G   1% /data/sdd1
/dev/sde1      xfs        20G   33M   20G   1% /data/sde1

添加地址映射

echo "192.168.8.150 node1" >> /etc/hosts
echo "192.168.8.151 node2" >> /etc/hosts
echo "192.168.8.152 node3" >> /etc/hosts
echo "192.168.8.153 node4" >> /etc/hosts
echo "192.168.8.155 client" >> /etc/hosts

##安装部署GlusterFS,设置本地源安装

unzip gfsrepo.zip 
cd /etc/yum.repos.d/
mkdir bak
mv CentOS-* bak

vim gfs.repo
[glfs]
name=glfs
baseurl=file:///opt/gfsrepo
gpgcheck=0
enabled=1

yum clean all				#刷新本地仓库
yum makecache
rpm -e --nodeps glusterfs-api glusterfs-libs glusterfs-fuse glusterfs-cli  glusterfs glusterfs-client-xlators
yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma		#下载依赖包

##开启服务

systemctl start glusterd.service
systemctl enable glusterd.service
systemctl status glusterd.service

在node1上添加节点到存储信任池中

[root@node1 gfsrepo]# gluster peer probe node1
peer probe: success. 
[root@node1 gfsrepo]# gluster peer probe node2
peer probe: success. 
[root@node1 gfsrepo]# gluster peer probe node3
peer probe: success. 
[root@node1 gfsrepo]# gluster peer probe node4		
peer probe: success. Probe on localhost not needed
[root@node1 gfsrepo]# gluster peer status				#查看结果
Number of Peers: 3

Hostname: node1
Uuid: 83a80dc9-316f-4472-a9b2-8b8b0563bd66
State: Peer in Cluster (Connected)

Hostname: node2
Uuid: 0033f686-4ea0-43f7-922e-dd5bf47ad454
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: 7821c5d7-e0f3-4f41-b376-f9dbdbad7377
State: Peer in Cluster (Connected)

创建卷

#根据规划创建如下卷:

卷名称 				卷类型				Brick
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)

创建分布式卷,会提醒需要开启

[root@node1 gfsrepo]# gluster volume create dis-volume node1:/data/sdb1 node2:/data/sdb1 force
volume create: dis-volume: success: please start the volume to access data
[root@node1 gfsrepo]# gluster volume list				#查看卷列表
dis-volume
[root@node1 gfsrepo]# gluster volume start dis volume	#启动新建分布式卷
Usage: volume start <VOLNAME> [force]
[root@node1 gfsrepo]# gluster volume info dis-volume	#查看分布式卷信息
 
Volume Name: dis-volume
Type: Distribute
Volume ID: c542f24d-b18f-432f-acdd-6f7bb9ee6e1b
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 gfsrepo]# gluster volume create stripe-volume stripe 2 node1:/data/sdc1 node2:/data/sdc1 force
volume create: stripe-volume: success: please start the volume to access data
[root@node1 gfsrepo]# gluster volume start stripe-volume		
volume start: stripe-volume: success
[root@node1 gfsrepo]# gluster volume info stripe-volume
 
Volume Name: stripe-volume
Type: Stripe
Volume ID: 80ff853d-2439-4a31-81c9-99da146883e4
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

创建复制卷

[root@node1 gfsrepo]# gluster volume create rep-volume replica 2 node3:/data/sdb1 node4:/data/sdb1 force
volume create: rep-volume: success: please start the volume to access data
[root@node1 gfsrepo]# gluster volume start rep-volume
volume start: rep-volume: success
[root@node1 gfsrepo]# gluster volume info rep-volume
 
Volume Name: rep-volume
Type: Replicate
Volume ID: fbac45bc-a688-4228-a96b-d9407bd40f08
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

创建分布式条带卷

[root@node1 gfsrepo]# 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 gfsrepo]# gluster volume start dis-stripe
volume start: dis-stripe: success
[root@node1 gfsrepo]# gluster volume info dis-stripe
 
Volume Name: dis-stripe
Type: Distributed-Stripe
Volume ID: e83bc20b-70ae-486a-a7bc-5c20d774da6f
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

创建分布式复制卷

[root@client yum.repos.d]# gluster volume create dis-rep replica 2 node1:/data/sde1 node2:/data/sde1 node3:/data/sde1 node4:/data/sde1 force
[root@client yum.repos.d]# gluster volume start dis-rep
volume start: dis-rep: success
[root@node1 ~]# gluster volume info dis-rep 
Volume Name: dis-rep
Type: Distributed-Replicate
Volume ID: d13a594e-ed13-4cc4-a8a7-ec7c145bc766
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
[root@node1 ~]# gluster volume list
dis-rep
dis-stripe
dis-volume
rep-volume
stripe-volume

client端部署

[root@client ~]# cd /etc/yum.repos.d/			#设置本地仓库
[root@client yum.repos.d]# vim gif.repo
[glfs]
name=glfs
baseurl=file:///opt/gfsrepo
gpgcheck=0
enabled=1
[root@client yum.repos.d]# yum clean all
[root@client yum.repos.d]# yum makecache
[root@client yum.repos.d]# yum -y install glusterfs glusterfs-fuse
[root@client yum.repos.d]# mkdir -p /test/{dis,stripe,rep,dis_stripe,dis_rep}	#创建挂载目录

##配置/etc/hosts文件

[root@client yum.repos.d]# echo "192.168.8.150 node1" >> /etc/hosts
[root@client yum.repos.d]# echo "192.168.8.151 node2" >> /etc/hosts
[root@client yum.repos.d]# echo "192.168.8.152 node3" >> /etc/hosts
[root@client yum.repos.d]# echo "192.168.8.153 node4" >> /etc/hosts
[root@client yum.repos.d]# echo "192.168.8.155 client" >> /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

##永久挂载

[root@client ~]# vim /etc/fstab
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-stripe		/test/dis_stripe		glusterfs		defaults,_netdev		0 0
node1:dis-rep			/test/dis_rep			glusterfs		defaults,_netdev		0 0
[root@client ~]# mount -a
测试GlusterFS文件系统
[root@client ~]# cd /opt
###在卷中写入文件
[root@client opt]# dd if=/dev/zero of=/opt/demo1.log bs=1M count=20
记录了20+0 的读入
记录了20+0 的写出
20971520字节(21 MB)已复制,0.0442097 秒,474 MB/秒
[root@client opt]# dd if=/dev/zero of=/opt/demo2.log bs=1M count=20
记录了20+0 的读入
记录了20+0 的写出
20971520字节(21 MB)已复制,0.0903227 秒,232 MB/秒
[root@client opt]# dd if=/dev/zero of=/opt/demo3.log bs=1M count=20
记录了20+0 的读入
记录了20+0 的写出
20971520字节(21 MB)已复制,0.0920415 秒,228 MB/秒
[root@client opt]# dd if=/dev/zero of=/opt/demo4.log bs=1M count=20
记录了20+0 的读入
记录了20+0 的写出
20971520字节(21 MB)已复制,0.0890255 秒,236 MB/秒
[root@client opt]# dd if=/dev/zero of=/opt/demo5.log bs=1M count=20
记录了20+0 的读入
记录了20+0 的写出
20971520字节(21 MB)已复制,0.0900589 秒,233 MB/秒
[root@client opt]# cp demo* /test/dis
[root@client opt]# cp demo* /test/stripe/
[root@client opt]# cp demo* /test/rep/
[root@client opt]# cp demo* /test/dis_stripe/
[root@client opt]# cp demo* /test/dis_rep/

在node1和node2上查看分布式卷情况

node1:
[root@node1 yum.repos.d]# ls -lh /data/sdb1
总用量 80M
-rw-r--r--. 2 root root 20M 813 09:45 demo1.log
-rw-r--r--. 2 root root 20M 813 09:45 demo2.log
-rw-r--r--. 2 root root 20M 813 09:45 demo3.log
-rw-r--r--. 2 root root 20M 813 09:45 demo4.log

node2:
[root@node2 yum.repos.d]# ll -h /data/sdb1
总用量 20M
-rw-r--r--. 2 root root 20M 813 09:45 demo5.log

在node1和node2上查看条带卷情况

[root@node1 yum.repos.d]# ls -lh /data/sdc1					#数据分片一半,没有冗余
总用量 50M
-rw-r--r--. 2 root root 10M 813 09:45 demo1.log
-rw-r--r--. 2 root root 10M 813 09:45 demo2.log
-rw-r--r--. 2 root root 10M 813 09:45 demo3.log
-rw-r--r--. 2 root root 10M 813 09:45 demo4.log
-rw-r--r--. 2 root root 10M 813 09:45 demo5.log

[root@node2 yum.repos.d]# ll -h /data/sdc1
总用量 50M
-rw-r--r--. 2 root root 10M 813 09:45 demo1.log
-rw-r--r--. 2 root root 10M 813 09:45 demo2.log
-rw-r--r--. 2 root root 10M 813 09:45 demo3.log
-rw-r--r--. 2 root root 10M 813 09:45 demo4.log
-rw-r--r--. 2 root root 10M 813 09:45 demo5.log

在node3和node4查看负责卷分布

[root@node4 yum.repos.d]# ll -h /data/sdb1					#数据未分片,有冗余
总用量 100M
-rw-r--r--. 2 root root 20M 813 09:45 demo1.log		
-rw-r--r--. 2 root root 20M 813 09:45 demo2.log
-rw-r--r--. 2 root root 20M 813 09:45 demo3.log
-rw-r--r--. 2 root root 20M 813 09:45 demo4.log
-rw-r--r--. 2 root root 20M 813 09:45 demo5.log

[root@node3 yum.repos.d]# ll -h /data/sdb1
total 100M
-rw-r--r--. 2 root root 20M 八月 13 09:45 demo1.log
-rw-r--r--. 2 root root 20M 八月 13 09:45 demo2.log
-rw-r--r--. 2 root root 20M 八月 13 09:45 demo3.log
-rw-r--r--. 2 root root 20M 八月 13 09:45 demo4.log
-rw-r--r--. 2 root root 20M 八月 13 09:45 demo5.log

在node1-4上查看分布式条带卷

[root@node1 yum.repos.d]# ls -lh /data/sdd1					#数据一半被分片,无冗余
总用量 40M
-rw-r--r--. 2 root root 10M 813 09:45 demo1.log
-rw-r--r--. 2 root root 10M 813 09:45 demo2.log
-rw-r--r--. 2 root root 10M 813 09:45 demo3.log
-rw-r--r--. 2 root root 10M 813 09:45 demo4.log

[root@node2 yum.repos.d]# ll -h /data/sdd1
总用量 40M
-rw-r--r--. 2 root root 10M 813 09:45 demo1.log
-rw-r--r--. 2 root root 10M 813 09:45 demo2.log
-rw-r--r--. 2 root root 10M 813 09:45 demo3.log
-rw-r--r--. 2 root root 10M 813 09:45 demo4.log

[root@node4 yum.repos.d]# ll -h /data/sdd1
总用量 10M
-rw-r--r--. 2 root root 10M 813 09:45 demo5.log

[root@node3 yum.repos.d]# ll -h /data/sdd1
total 10M
-rw-r--r--. 2 root root 10M 八月 13 09:45 demo5.log

在node1-4上查看分布式复制卷

[root@node1 yum.repos.d]# ls -lh /data/sde1
总用量 80M
-rw-r--r--. 2 root root 20M 813 09:45 demo1.log
-rw-r--r--. 2 root root 20M 813 09:45 demo2.log
-rw-r--r--. 2 root root 20M 813 09:45 demo3.log
-rw-r--r--. 2 root root 20M 813 09:45 demo4.log

[root@node2 yum.repos.d]# ll -h /data/sde1
总用量 80M
-rw-r--r--. 2 root root 20M 813 09:45 demo1.log
-rw-r--r--. 2 root root 20M 813 09:45 demo2.log
-rw-r--r--. 2 root root 20M 813 09:45 demo3.log
-rw-r--r--. 2 root root 20M 813 09:45 demo4.log

[root@node4 yum.repos.d]# ll -h /data/sde1
总用量 20M
-rw-r--r--. 2 root root 20M 813 09:45 demo5.log

[root@node3 yum.repos.d]# ll -h /data/sde1
total 20M
-rw-r--r--. 2 root root 20M 八月 13 09:45 demo5.log

破坏性测试:关闭node2节点在client端观察

分布式卷:

[root@client test]# cd /test/dis
[root@client dis]# ll
总用量 81920													#缺少demo5数据
-rw-r--r--. 1 root root 20971520 813 09:45 demo1.log
-rw-r--r--. 1 root root 20971520 813 09:45 demo2.log
-rw-r--r--. 1 root root 20971520 813 09:45 demo3.log
-rw-r--r--. 1 root root 20971520 813 09:45 demo4.log

条带卷:

[root@client test]# cd stripe/
[root@client stripe]# ll
ls: 正在读取目录.: 传输端点尚未连接	
总用量 0														#条带卷无法访问,不具备冗余性

分布式条带卷

[root@client dis]# cd /test/dis_stripe/
[root@client dis_stripe]# ll
总用量 20480
-rw-r--r--. 1 root root 20971520 813 09:45 demo5.log	#分布式条带卷不具备冗余性

[root@client dis_stripe]# cd /test/dis_rep/					#数据正常未丢失
[root@client dis_rep]# ll
总用量 102400
-rw-r--r--. 1 root root 20971520 813 09:45 demo1.log
-rw-r--r--. 1 root root 20971520 813 09:45 demo2.log
-rw-r--r--. 1 root root 20971520 813 09:45 demo3.log
-rw-r--r--. 1 root root 20971520 813 09:45 demo4.log
-rw-r--r--. 1 root root 20971520 813 09:45 demo5.log
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值