分布式文件系统--GlusterFS

1 篇文章 0 订阅
本文详细介绍了分布式文件系统的基本概念、作用和挂载使用,重点讲解了Google的分布式文件系统GFS的组件、工作流程以及基本卷与复合卷。接着展示了如何在多台服务器上部署GlusterFS集群,包括创建不同类型的卷(如分布式卷、条带卷、复制卷、分布式条带卷和分布式复制卷)以及客户端的安装和挂载。最后,进行了文件分布和破坏性测试,验证了系统的稳定性和容错能力。
摘要由CSDN通过智能技术生成

一、分布式文件系统

1.文件系统

1.1 组成

  • 文件系统接口
  • 对对像管理的软件集合
  • 对象及属性

1.2 作用

从系统角度来看,文件系统是对文件存储设备的空间进行组织和分配,负责文件存储并对存入的文件进行保护和检索的系统。
具体地说,它负责为用户建立文件,存入、读出、修改、转储文件,控制文件的存取

1.3 挂载使用

除根文件系统以外的文件系统创建后要使用需要先挂载至挂载点后才可以被访问,挂载点即分区设备文件关联的某个目录文件,类比:NFS

2.分布式文件系统–GFS

2.1 组成

1、存储服务器
2、客户端
3、NFS/Samba存储网关组成

2.2 专业术语

  • brick 存储服务器:实际存储用户数据的服务器

  • volume 本地文件系统的“分区”

  • FUSE : 用户空间的文件系统(类比EXT4),“这是一个伪文件系统”。
    以本地文件系统为例,用户想要读写一个文件,会借助于EXT4文件系统,然后把数据写在磁盘上,而如果是远端的GFS,客户端的请求则应该交给FUSE(伪文件系统),就可以实现跨界点存储在GFS上

  • FUSE(用户空间的文件系统)伪文件系统 用户端的交互模块

  • VFS(虚拟端口):内核态的虚拟文件系统,用户是先提交请求交给VFS 然后VFS交给FUSE 再交给GFS客户端,最后由客户端交给远端的存储

2.3 模块化堆栈式架构

  • 模块化、堆栈式的架构
    通过对模块的组合,实现复杂的功能
  • 模块化
    类似linux 编译安装;很多功能都可以做定制的,通常都是通过软件开发的方式封装为模块,按需使用/不适用
    GlusterFs也是这个思想:把功能封装为一个个模块,通过加载/调用/启用的方式就可以对应的功能

2.4 工作流程

客户端在本地发出读写请求,然后交由VFS 的API接受请求,接受请求后会交给FUSE(内核伪文件系统),FUSE可以模拟操作系统,所以可以对文件系统进行转存,转存的设备位置为:/dev/fuse(用于传输的设备-虚拟设备文件)——》交给GFS客户端,client 会根据配置文件对数据进行处理,然后再通过TCP/ib/rdma 网络发送到GFS服务端,并且将数据写到服务器存储设备上

2.5 基本卷与复合卷

GlusterFS 支持七种卷,即分布式卷、条带卷、复制卷、分布式条带卷、分布式复制卷、 条带复制卷和分布式条带复制卷

  • 分布式卷(默认):文件通过 HASH 算法分布到所有 Brick Server 上, 这种卷是 Glusterfs 的基础;以文件为单位根据 HASH 算法散列到不同的 Brick,其实 只是扩大了磁盘空间,如果有一块磁盘损坏,数据也将丢失,属于文件级的 RAID 0, 不具有容错能力
  • 条带卷(默认):类似 RAID0,文件被分成数据块并以轮询的方式分布到多个 Brick Server 上,文件存储以数据块为单位,支持大文件存储,文件越大,读取效率越高
  • 复制卷(Replica volume):将文件同步到多个 Brick 上,使其具备多个文件副本, 属于文件级 RAID 1,具有容错能力。因为数据分散在多个 Brick 中,所以读性能得 到很大提升,但写性能下降
  • 分布式条带卷(Distribute Stripe volume):Brick Server 数量是条带数(数据块分布 的 Brick 数量)的倍数,兼具分布式卷和条带卷的特点
  • 分布式复制卷(Distribute Replica volume):Brick Server 数量是镜像数(数据副本 数量)的倍数,兼具分布式卷和复制卷的特点
  • 条带复制卷(Stripe Replica volume):类似 RAID 10,同时具有条带卷和复制卷的 特点
  • 分布式条带复制卷(Distribute Stripe Replicavolume):三种基本卷的复合卷,通常 用于类 Map Reduce 应用

二、部署 GlusterFS 群集

环境
node1   192.168.30.6
node2   192.168.30.7
node3   192.168.30.8
node4   192.168.30.9
client  192.168.30.5

1 准备环境

磁盘与挂载点相对应

在这里插入图片描述

2 配置/etc/hosts文件

在这里插入图片描述

3 安装GlusterFS并启动

[root@node1 ~]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma   //,其他节点同样操作
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 glusterfs-3.10.2-1.el7.x86_64 已安装并且是最新版本
软件包 glusterfs-server-3.10.2-1.el7.x86_64 已安装并且是最新版本
软件包 glusterfs-fuse-3.10.2-1.el7.x86_64 已安装并且是最新版本
软件包 glusterfs-rdma-3.10.2-1.el7.x86_64 已安装并且是最新版本
无须任何处理


[root@node1 opt]# systemctl start glusterd.service   //启动
[root@node1 opt]# systemctl enable glusterd.service   //开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/glusterd.service to /usr/lib/systemd/system/glusterd.service.
[root@node1 opt]# systemctl status glusterd.service   //查询状态
● glusterd.service - GlusterFS, a clustered file-system server
   Loaded: loaded (/usr/lib/systemd/system/glusterd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-08-11 19:11:03 CST; 2s ago
 Main PID: 19604 (glusterd)
   CGroup: /system.slice/glusterd.service
           └─19604 /usr/sbin/glusterd -p /var/run/glusterd.pid --log-level INFO...

Aug 11 19:11:03 node1 systemd[1]: Starting GlusterFS, a clustered file-system.....
Aug 11 19:11:03 node1 systemd[1]: Started GlusterFS, a clustered file-system ...r.
Hint: Some lines were ellipsized, use -l to show in full.

4 时间同步,加入存储信任池

[root@node1 opt]# ntpdate ntp1.aliyun.com   //同步阿里云的ntp服务器
11 Aug 19:13:20 ntpdate[19714]: adjust time server 120.25.115.20 offset 0.003094 sec

[root@node1 opt]# gluster peer probe node1  //加入存储信任池,只需要在一台节点上操作即可
peer probe: success. Probe on localhost not needed
[root@node1 opt]# gluster peer probe node2
peer probe: success. 
[root@node1 opt]# gluster peer probe node3
peer probe: success. 
[root@node1 opt]# gluster peer probe node4
peer probe: success. 
[root@node1 opt]# gluster peer status //在每个Node节点上查看群集状态
Number of Peers: 3

Hostname: node2
Uuid: a02106dc-7fed-4bf8-9968-efa2a5bc4ec7
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: 038c0761-f1f6-42c3-914e-40aedbdbf720
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: 6840d481-bf60-43b8-ae71-97395a0d9bcb
State: Peer in Cluster (Connected)

5 创建卷

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

5.1 创建分布式卷

[root@node1 opt]# 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 opt]# gluster volume list  //查看卷列表
dis-volume 
[root@node1 opt]# gluster volume start dis-volume   //启动新建分布式卷
volume start: dis-volume: success
[root@node1 opt]# gluster volume info dis-volume   //查看创建分布式卷信息
 
Volume Name: dis-volume
Type: Distribute
Volume ID: cffc4402-ec03-4a48-aebe-3158e5231dc5
Status: Started
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

5.2 创建条带卷

[root@node1 opt]# gluster volume create stripe-volume stripe 2 node1:/data/sdc1 node2:/data/sdc1 force  //指定类型为 stripe,数值为 2,且后面跟了 2 个 Brick Server,所以创建的是条带卷
volume create: stripe-volume: success: please start the volume to access data
[root@node1 opt]# gluster volume start stripe-volume   //启动新建条带卷
volume start: stripe-volume: success
[root@node1 opt]# gluster volume info stripe-volume   //查看新建条带卷信息
 
Volume Name: stripe-volume
Type: Stripe
Volume ID: 478b8497-4c3d-4db4-b958-2abf5798aac2
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 opt]# 

5.3 创建复制卷

[root@node1 opt]# gluster volume create rep-volume replica 2 node3:/data/sdb1 node4:/data/sdb1 force  //指定类型为 replica,数值为 2,且后面跟了 2 个 Brick Server,所以创建的是复制卷
volume create: rep-volume: success: please start the volume to access data
[root@node1 opt]# gluster volume start rep-volume   //启动新建复制卷

volume start: rep-volume: success
[root@node1 opt]# gluster volume info rep-volume    //查看新建复制卷信息
 
Volume Name: rep-volume
Type: Replicate
Volume ID: 2ae6ca8a-73af-485b-86d1-c6b0ed74a09b
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

5.4 创建分布式条带卷

[root@node1 opt]# gluster volume create dis-stripe stripe 2 node1:/data/sdd1 node2:/data/sdd1 node3:/data/sdd1 node4:/data/sdd1 force  //指定类型为 stripe,数值为 2,而且后面跟了 4 个 Brick Server,是 2 的两倍,所以创建的是分布式条带卷
volume create: dis-stripe: success: please start the volume to access data
[root@node1 opt]# gluster volume start dis-stripe   //启动新建分布式条带卷
volume start: dis-stripe: success
[root@node1 opt]# gluster volume info dis-stripe   //查看分布式条带卷信息
 
Volume Name: dis-stripe
Type: Distributed-Stripe
Volume ID: 54bcbe8e-f30a-4bbb-a36a-13d7cfaaab2b
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

5.5 创建分布式复制卷

[root@node1 opt]# gluster volume create dis-rep replica 2 node1:/data/sde1 node2:/data/sde1 node3:/data/sde1 node4:/data/sde1 force  //指定类型为 replica,数值为 2,而且后面跟了 4 个 Brick Server,是 2 的两倍,所以创建的是分布式复制卷
volume create: dis-rep: success: please start the volume to access data
[root@node1 opt]# gluster volume start dis-rep  //启动新建分布式复制卷
volume start: dis-rep: success
[root@node1 opt]# gluster volume info dis-rep    //查看新建分布式复制卷信息
 
Volume Name: dis-rep
Type: Distributed-Replicate
Volume ID: 39a8d0e8-79e9-431f-aeca-b69254d687c5
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

5.6 查看卷列表

[root@node1 opt]# gluster volume list
dis-rep
dis-stripe
dis-volume
rep-volume
stripe-volume

6.部署客户端

6.1 配置hosts文件

[root@client ~]# echo "192.168.30.6 node1" >> /etc/hosts
[root@client ~]# echo "192.168.30.7 node2" >> /etc/hosts
[root@client ~]# echo "192.168.30.8 node3" >> /etc/hosts
[root@client ~]# echo "192.168.30.9 node4" >> /etc/hosts
[root@client ~]# echo "192.168.30.5 client" >> /etc/hosts
[root@client ~]# 

6.2 安装gfs客户端

[root@client opt]# yum -y install glusterfs glusterfs-fuse
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
匹配 glusterfs-3.10.2-1.el7.x86_64 的软件包已经安装。正在检查更新。
匹配 glusterfs-fuse-3.10.2-1.el7.x86_64 的软件包已经安装。正在检查更新。
无须任何处理

6.3 创建挂载点,挂载 gluster文件系统

[root@client opt]# mkdir -p /test/{dis,stripe,rep,dis_stripe,dis_rep}
[root@client opt]# ls /test
dis  dis_rep  dis_stripe  rep  stripe
[root@client opt]# mount.glusterfs node1:dis-volume /test/dis
[root@client opt]# mount.glusterfs node1:stripe-volume /test/stripe
[root@client opt]# mount.glusterfs node1:rep-volume /test/rep
[root@client opt]# mount.glusterfs node1:dis-stripe /test/dis_stripe
[root@client opt]# mount.glusterfs node1:dis-rep /test/dis_rep
[root@client opt]# df -hT
文件系统            类型            容量  已用  可用 已用% 挂载点
/dev/sda3           xfs             197G  4.5G  193G    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            1014M  174M  841M   18% /boot
tmpfs               tmpfs           182M   12K  182M    1% /run/user/42
tmpfs               tmpfs           182M     0  182M    0% /run/user/0
node1:dis-volume    fuse.glusterfs  8.0G   65M  8.0G    1% /test/dis
node1:stripe-volume fuse.glusterfs  8.0G   65M  8.0G    1% /test/stripe
node1:rep-volume    fuse.glusterfs  4.0G   33M  4.0G    1% /test/rep
node1:dis-stripe    fuse.glusterfs   16G  130M   16G    1% /test/dis_stripe
node1:dis-rep       fuse.glusterfs  8.0G   65M  8.0G    1% /test/dis_rep
[root@client opt]# 

7.测试

7.1 写入数据

[root@client opt]# ls -lh /opt
总用量 150M
-rw-r--r--  1 root root  20M 811 19:55 demo1.log
-rw-r--r--  1 root root  20M 811 19:55 demo2.log
-rw-r--r--  1 root root  20M 811 19:55 demo3.log
-rw-r--r--  1 root root  20M 811 19:55 demo4.log
-rw-r--r--  1 root root  20M 811 19:55 demo5.log
drwxr-xr-x  3 root root 8.0K 1120 2020 gfsrepo
-rw-r--r--  1 root root  50M 811 09:33 gfsrepo.zip
drwxr-xr-x. 2 root root    6 1031 2018 rh
[root@client opt]# 
[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/

7.2 查看文件分布

7.2.1 分布式卷

在这里插入图片描述

7.2.2 条带卷

在这里插入图片描述

7.2.3 复制卷

在这里插入图片描述

7.2.4 分布式条带卷

在这里插入图片描述

7.2.5 分布式复制卷

7.3 破坏性测试

7.3.1 关闭一台节点服务器

在这里插入图片描述

7.3.2 查看文件
[root@client test]# ls -lh dis/ stripe/ rep dis_stripe/ dis_rep/
dis/:
总用量 80M
-rw-r--r-- 1 root root 20M 811 19:55 demo1.log
-rw-r--r-- 1 root root 20M 811 19:55 demo2.log
-rw-r--r-- 1 root root 20M 811 19:55 demo3.log
-rw-r--r-- 1 root root 20M 811 19:55 demo4.log

dis_rep/:
总用量 100M
-rw-r--r-- 1 root root 20M 811 19:55 demo1.log
-rw-r--r-- 1 root root 20M 811 19:55 demo2.log
-rw-r--r-- 1 root root 20M 811 19:55 demo3.log
-rw-r--r-- 1 root root 20M 811 19:55 demo4.log
-rw-r--r-- 1 root root 20M 811 19:55 demo5.log

dis_stripe/:
总用量 20M
-rw-r--r-- 1 root root 20M 811 19:55 demo5.log

rep:
总用量 100M
-rw-r--r-- 1 root root 20M 811 19:55 demo1.log
-rw-r--r-- 1 root root 20M 811 19:55 demo2.log
-rw-r--r-- 1 root root 20M 811 19:55 demo3.log
-rw-r--r-- 1 root root 20M 811 19:55 demo4.log
-rw-r--r-- 1 root root 20M 811 19:55 demo5.log

stripe/:
ls: 正在读取目录stripe/: 传输端点尚未连接
总用量 0

小结

  • 在多个后端存储中定位文件:
    使用弹性HASH算法来解决数据定位、索引、寻址的功能
    先通过HASH算法对数据可以得到一个值(该值有2的32次方个组合)
    每个数据对应了0-2的32次方的一个值

  • (分布式)平均分配的好处:
    当数据量越来越大的时候,相对每个存储节点的数据量(几率)是相等的
    而如果考虑到单点故障问题,当数据存储在C存储节点,对此GFS是会有备份机制的(卷),默认3备份,所以GFS本身的机制会对数据产生冗余,以此解决单点故障

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值