Gluster FS分布式文件系统

Gluster FS概述

分布式文件系统介绍

分布式文件系统(Distributed File System)是指文件系统管理的物理存储资源并不直接与本地节点相连,而是分布于计算网络中的一个或者多个节点的计算机上。目前意义上的分布式文件系统大多都是由多个节点计算机构成,结构上是典型的客户机/服务器模式。流行的模式是当客户机需要存储数据时,服务器指引其将数据分散的存储到多个存储节点上,以提供更快的速度,更大的容量及更好的冗余特性。

1.文件系统组成

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

2.文件系统作用

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

3.文件系统的挂载使用

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

Gluster FS 简介

它是开源的分布式文件系统,由存储服务器、客户端以及NFS/Samba存储网关组成。

Gluster FS 特点

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

Gluster FS组成

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

Gluster FS专业术语

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

模块化堆栈式架构

  • 模块化、堆栈式的架构
  • 通过对模块的组合,实现复杂的功能

模块化

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

Gluster FS工作原理

在这里插入图片描述

  • 客户端存储将文件放入,通过system call调用VFS内核寻端口
  • VFS将数据交给FUSE,FUSE将数据保存到/dev/fuse虚拟设备中(缓存中),然后唤醒GFS-client
  • client将数据传输给server端,server端通过VFS将数据保存在EXT3这种文件系统中,然后保存到brick存储服务器

GlusterFS卷类型

基本卷

  • 1.distribute volume:分布式卷
    文件通过HASH算法分布到所有Brick Server上,一个节点的磁盘损坏,数据丢失
  • 2.stripe volume:条带卷
    文件被分成数据块并以轮询的方式分布到多个Brick Server上,文件存储以数据块为单位,支持大文件存储,文件越大,读取效率越高
  • 3.replica volume:复制卷
    将文件同步到多个Brick Server上,使其具备多个文件副本,具有容错能力。因为数据分散在多个 Brick 中,所以读性能得 到很大提升,但写性能下降。

复合卷

  • 1.distribute stripe volume:分布式条带卷
    Brick Server 数量是条带数(数据块分布 的 Brick 数量)的倍数,兼具分布式卷和条带卷的特点。
  • 2.distribute replica volume:分布式复制卷
    Brick Server 数量是镜像数(数据副本 数量)的倍数,兼具分布式卷和复制卷的特点
  • 3.stripe replica volume:条带复制卷
    类似 RAID 10,同时具有条带卷和复制卷的 特点
  • 4.distribute stripe replicavolume:分布式条带复制卷
    三种基本卷的复合卷,通常 用于类 Map Reduce 应用

GlusterFS集群部署

实验环境:

所有节点添加四块磁盘

Node1节点:192.168.220.101
磁盘:/dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 
挂载点:/data/sdb1 /data/sdc1 /data/sdd1 /data/sde1

Node2节点:192.168.220.102
磁盘:/dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 
挂载点:/data/sdb1 /data/sdc1 /data/sdd1 /data/sde1

Node3节点:192.168.220.103
磁盘:/dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 
挂载点:/data/sdb1 /data/sdc1 /data/sdd1 /data/sde1

Node4节点:192.168.220.104
磁盘:/dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 
挂载点:/data/sdb1 /data/sdc1 /data/sdd1 /data/sde1

客户端节点:192.168.220.200

在这里插入图片描述

1.关闭防火墙

[root@node1 ~]# systemctl stop firewalld
[root@node1 ~]# setenforce 0

2.磁盘分区并挂载

编写执行脚本

[root@node1 ~]# vim /opt/fdisk.sh
#!/bin/bash
#提示信息
echo "the disks exist list:"
#过滤出系统所带磁盘
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])
        #免交互磁盘分区
        echo "n    ##创建磁盘
                p
                
                
           
                w"  | fdisk /dev/$VAR
 
		#格式化文件系统
        mkfs.xfs -i size=512 /dev/${VAR}"1" &> /dev/null    
		#创建挂载目录
        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
[root@node1 ~]# chmod +x /opt/fdisk.sh
[root@node1 opt]# ./fdisk.sh
//依次执行4次,分别将对应的磁盘挂载到对应的挂载点。示例:/dev/sdb1 --> /data/sdb1
chose which disk you want to create:4
//交互时,选择1-4
[root@node1 opt]# df -hT

在这里插入图片描述

3.添加映射

[root@node1 opt]# echo "192.168.220.101 node1" >> /etc/hosts
[root@node1 opt]# echo "192.168.220.102 node2" >> /etc/hosts
[root@node1 opt]# echo "192.168.220.103 node3" >> /etc/hosts
[root@node1 opt]# echo "192.168.220.104 node4" >> /etc/hosts
[root@node1 opt]# echo "192.168.220.105 client" >> /etc/hosts

安装部署GlusterFS

备份yum源的repo文件

[root@node1 gfsrepo]# cd /etc/yum.repos.d/
[root@node1 yum.repos.d]# mkdir bak
[root@node1 yum.repos.d]# mv CentOS-* bak
[root@node1 yum.repos.d]# ls
bak

解压gfsrepo.zip

[root@node1 opt]# unzip gfsrepo.zip

配置本地yum源

[root@node1 yum.repos.d]# vim /etc/yum.repos.d/glfs.repo
[glfs]
name=glfs
baseurl=file:///opt/gfsrepo
gpgcheck=0
enabled=1

[root@node1 yum.repos.d]# yum clean all		//刷新本地仓库
[root@node1 yum.repos.d]# yum makecache 

安装并启动

安装需要的组件

[root@node1 yum.repos.d]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma

报错
在这里插入图片描述
解决方法
如果yum安装的时候报以上错误,是因为高低版本不兼容导致,手动卸载(又几个卸载几个)
例如上图的 glusterfs-libs-3.12.2-18.e17.x86_64 就需要手动卸载
rpm卸载需要忽略依赖关系,使用 --nodeps

[root@node1 ~]# rpm -e --nodeps glusterfs-api glusterfs-fuse glusterfs-cli  glusterfs glusterfs-client-xlators
//重新安装
[root@node1 ~]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma

在这里插入图片描述

启动服务

[root@node1 ~]# systemctl start glusterd.service 
[root@node1 ~]# 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 ~]# systemctl status glusterd.service

在这里插入图片描述

添加节点到存储信任池中

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

[root@node1 ~]# gluster peer probe node1
peer probe: success. Probe on localhost not needed
[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		//查看群集状态
Number of Peers: 3

Hostname: node2
Uuid: bd6f47d2-b338-4085-861f-32e52958fe54
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: cb84757e-acfe-45cb-97b4-819c14e8ecfa
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: 2272401f-6755-4f56-9a45-45bb00cc9f98
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)
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 ~]# gluster volume list		//查看卷列表
dis-volume
[root@node1 ~]# gluster volume start dis-volume		//启动新建分布式卷
volume start: dis-volume: success
[root@node1 ~]# gluster volume info dis-volume		//查看分布式卷信息
 
Volume Name: dis-volume
Type: Distribute
Volume ID: 405df37e-3d6d-4c80-aa91-30201548baf3
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
2.创建条带卷
[root@node1 ~]# 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 ~]# gluster volume start stripe-volume		 //启动新建条带卷
volume start: stripe-volume: success
[root@node1 ~]# gluster volume info stripe-volume		//查看新建条带卷信息
 
Volume Name: stripe-volume
Type: Stripe
Volume ID: 212c2e2f-8fea-4fa3-a49a-186dcde83e29
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
3.创建复制卷
[root@node1 ~]# 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 ~]# gluster volume start rep-volume 	//启动新建复制卷
volume start: rep-volume: success
[root@node1 ~]# gluster volume info rep-volume		//查看新建复制卷信息
 
Volume Name: rep-volume
Type: Replicate
Volume ID: 3f1e6180-2b1b-4e31-b27e-784cef95c04b
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
4.创建分布式条带卷
[root@node1 ~]# 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 ~]# gluster volume start dis-stripe
volume start: dis-stripe: success
[root@node1 ~]# gluster volume info dis-stripe
 
Volume Name: dis-stripe
Type: Distributed-Stripe
Volume ID: 4c336a26-fabb-4fcc-b089-719ecf01ab02
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.创建分布式复制卷
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 的两倍,所以创建的是分布式复制卷
[root@node1 ~]# 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: 4d15f99b-cf6e-4352-addd-b16bd8fcd3af
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
6.查看卷列表
[root@node1 ~]# gluster volume list
dis-rep
dis-stripe
dis-volume
rep-volume
stripe-volume

客户端部署

1.配置hosts文件
[root@client ~]# echo "192.168.220.101 node1" >> /etc/hosts
[root@client ~]# echo "192.168.220.102 node2" >> /etc/hosts
[root@client ~]# echo "192.168.220.103 node3" >> /etc/hosts
[root@client ~]# echo "192.168.220.104 node4" >> /etc/hosts
[root@client ~]# echo "192.168.220.105 client" >> /etc/hosts
2.安装gfs客户端

设置本地仓库

[root@client ~]# cd /etc/yum.repos.d/
[root@client yum.repos.d]# mkdir repo.bak
[root@client yum.repos.d]# mv *.repo repo.bak
[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
3.创建挂载点,挂载 gluster文件系统
[root@client yum.repos.d]# mkdir -p /test/{dis,stripe,rep,dis_stripe,dis_rep}
[root@client yum.repos.d]# 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 yum.repos.d]# 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
测试
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/
2.查看文件分布

**分布式卷
**
在这里插入图片描述
条带卷
在这里插入图片描述

** 复制卷**
在这里插入图片描述
分布式条带卷
在这里插入图片描述
分布式复制卷
在这里插入图片描述

3.破坏性测试

关闭一台节点服务器
在这里插入图片描述
查看文件

[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

总结
通过以上的实验可以看出,凡是带复制的,数据都是比较安全的

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值