GFS分布式文件系统

GlusterFS简介

开源的分布式文件系统
由存储服务器、客户端以及NFSISamba存储网关组成
无元数据服务器

GlusterS持点

扩展性和高性能
高可用性
全局统一命名空间
弹性卷管理
基于标准协议   //TCP协议

在这里插入图片描述

GlusterFS术语

Brick            砖块(后台存储空间)
Volume           卷   
FUSE             协议(传输时)
VFS              对外映射的接口(入口)
Glusterd         程序名称
VFS:入口 
FUSE:磁盘映射空间
EXT3:真实磁盘
Kernel space:内核空间协议
/dev/fule:文件
GFS是一个可扩展的分布式文件系统,用于大型的、分布式的、对大量数据进行访问的应用。它运行于廉价的普通硬件上,并提供容错功能。它可以给大量的用户提供总体性能较高的服务。
GFS 也就是 google File System,Google公司为了存储海量搜索数据而设计的专用文件系统。

模块化堆栈式架构

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

在这里插入图片描述

GlusterFS工作原理

在这里插入图片描述

写数据步骤

读数据则逆向进行
Application:客户端或应用程序通过GlusterFS的挂载点访问数据
linux系统内核通过VFS  API(连接点)收到请求并处理
VFS将数据递交给FUSL内核文件系统,fuse文件系统则是将数据通过/dev/fuse设备文件递交给了GlusterFS client端
GIusterFS client收到数据后,client根据配置文件的配置对数据进行处理
通过网络将数据传递至远端的GlusterFS Server,并且将数据写入到服务器存储设备上

GlusterFS工作流程

弹性HASH算法
画图举例

四个Brick节点的GlusterFS卷,平均分配2的32次方的区间的范围空间

在这里插入图片描述

访问问件时,通过计算该文件的HASH值,从而对应到Brick存储空间

在这里插入图片描述

通过HASH算法得到一个32位的整数
划分为N个连续的子空间,每个空间对应一个Brick(砖)
弹性HASH算法的优点
保证数据平均分布在每一个Brick中
解决了对元数据服务器的依赖,进而解决了单点故障以及访问瓶颈

GlusterFS的卷类型

分布式卷
条带卷
复制卷
分布式条带卷
分布式复制卷
条带复制卷
分布式条带复制卷

分布式卷(卷数量>=2)

没有对文件进行分块处理
通过扩展文件属性保存HASH值
支持的底层文件系统有EXT3、EXT4、ZFS、XFS等

在这里插入图片描述

分布式卷的特点

文件分布在不同的服务器,不具备冗余性
更容易和廉价地扩展卷的大小
单点故障会造成数据丢失
依赖底层的数据保护

创建分布式卷

创建一个名为dis-volume的分布式卷,文件将根据HASH分布在server1:/dir1、server2:/dir2和server3:/dir3中
#gluster volume create dis-volume server1:/dir1 server2:/dir2 server3:/dir3
dis-volume(名称,可以自定义)
server1 2(主机名)
dir1:磁盘空间挂载点
没有分块处理,文件只能存在一个server中,效率不断提高(通过哈希算法)

条带卷

根据偏移量将文件分成N块(N个条带节点),轮询的存储在每个Brick Server节点
存储大文件时,性能尤为突出
不具备冗余性,类似Raid0

在这里插入图片描述

从多个server中同时读取文件,效率提升

特点

数据被为割成更小块分布到块服务器群中的不同条带区
分布减少了负载且更小的文件加速了存取的速度
没有数据冗余

创建条带卷

创建了一个名为Stripe-volume的条带卷,文件将被分块轮询的存储在Server1:/dir1和Server2:/dir2两个Brick中
#gluster volume create stripe-volume stripe 2 transport tcp server1:/dir1 server2:/dir2

复制卷(最少两个)

同一文件保存一份或多分副本
因为要保存副本,所以磁盘利用率较低
若多个节点上的存储空间不一致,将按照木桶效应取最低节点的容量作为该卷的总容量

在这里插入图片描述

特点

卷中所有的服务器均保存一个完整的副本
卷的副本数量可由客户创建的时候决定
至少有两个块服务器或更多服务器
具备冗余性

创建复制卷

创建名为rep-volume的复制卷,文件将同时存储两个副本,分别在Server1:/dir1和Server2:/dir2两个Brick中
# gluster volume create rep-volume replica 2 transport tcp server1:/dir1 server2:/dir2

分布式条带卷

兼顾分布式卷和条带卷的功能
主要用于大文件访问处理
至少最少需要4台服务器

在这里插入图片描述

创建分布式条带卷

创建了名为dis-stripe的分布式条带卷,配置分布式的条带卷时,卷中Brick所包含的存储服务器数必须是条带数的倍数(>=2倍)
#gluster volume create dis-stripe stripe 2 transport tcp server1:/dir1server2:/dir2 server3:/dir3 server4:/dir4

分布式复制卷

兼顾分布式卷和复制卷的功能
用于需要冗余的情况

在这里插入图片描述

创建分布式复制卷

创建名为dis-rep的分布式条带卷,配置分布式复制卷时,卷中Brick所包含的存储服务器数必须是复制卷数的倍数(>=2倍)
#gluster volume create dis-rep replica 2transport tcp server1:/dir1 server2:/dir2 server3:/dir3 server4:/dir4

GlusterFS部署

环境:
在这里插入图片描述
在这里插入图片描述
部署

四台服务器node节点(每个节点上添加4块2G硬盘,重启主机,使其生效)
一台客户机

永久关闭防火墙,核心防护(现只在server1上操作)

[root@server1 ~]# systemctl stop firewalld.service 
[root@server1 ~]# setenforce 0
[root@server1 ~]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

替换文件(现只在node1节点上操作)

[root@server1 ~]# sed -i '/SELINUX/s/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config 
[root@server1 ~]# grep -v "#" /etc/selinux/config 

SELINUX=disabled
SELINUXTYPE=targeted

添加映射(node1、node2、node3、node4和client上设置),现只在node1节点上操作

[root@server1 ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
20.0.0.10   node1
20.0.0.11   node2
20.0.0.12   node3
20.0.0.14   node4

导入yum源目录(gfsrepo文件),并修改源
解压缩并安装软件(node1、node2、node3、node4和client上安装)

[root@node1 ~]# unzip gfsrepo.zip         #node上演示
[root@node1 ~]# cd /etc/yum.repos.d/      #设置源
[root@node1 yum.repos.d]# vi GLFS.repo
[GLFS]
name=glfs
baseurl=file:///root/gfsrepo
gpgcheck=0
enabled=1
[root@node1 yum.repo.d]# rm -rf local.repo
[root@node1 ~]# yum -y install glusterfs glusterfs-server gluster-fuse glusterfs-rdma

开启glusterd的服务,开机自启(现只在node1节点上演示)

[root@server1 ~]# systemctl start glusterd
[root@server1 ~]# systemctl status glusterd
● glusterd.service - GlusterFS, a clustered file-system server
   Loaded: loaded (/usr/lib/systemd/system/glusterd.service; disabled; vendor preset: disabled)
   Active: active (running) since 三 2020-11-25 18:43:14 CST; 11s ago
  Process: 41672 ExecStart=/usr/sbin/glusterd -p /var/run/glusterd.pid --log-level $LOG_LEVEL $GLUSTERD_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 41673 (glusterd)
   CGroup: /system.slice/glusterd.service
           └─41673 /usr/sbin/glusterd -p /var/run/glusterd.pid --log-level INFO

11月 25 18:43:14 server1 systemd[1]: Starting GlusterFS, a clustered file-system server...
11月 25 18:43:14 server1 systemd[1]: Started GlusterFS, a clustered file-system server.
[root@server1 ~]# systemctl enable glusterd
Created symlink from /etc/systemd/system/multi-user.target.wants/glusterd.service to /usr/lib/systemd/system/glusterd.service.

以上步骤结束之后,客户端不在同步内容。其他四台服务器命令仍然要一致(原因:客户端端口与这四台服务器端口不一致)

修改配置文件,测试是否能上网

[root@server1 ~]# vi /etc/resolv.conf 
nameserver 20.0.0.2
[root@server1 ~]# ping www.baidu.com
PING www.a.shifen.com (180.101.49.11) 56(84) bytes of data.
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=1 ttl=128 time=6.52 ms

时间同步(node1、node2、node3、node4上安装)

[root@server1 ~]# ntpdate ntp1.aliyun.com   //同步阿里云
24 Nov 18:51:02 ntpdate[41843]: step time server 120.25.115.20 offset -86400.695568 sec
[root@server1 ~]# date
2020年 11月 24日 星期二 18:51:58 CST

添加入存储信任池只要在一台服务器上添加其他服务器(现在node1节点上设置)

[root@server1 ~]# gluster peer probe node2
peer probe: success. 
[root@server1 ~]# gluster peer probe node3
peer probe: success. 
[root@server1 ~]# gluster peer probe node4
peer probe: success. 

查看各个节点状态

server1上看
[root@server1 ~]# gluster peer status 
Number of Peers: 3

Hostname: node2
Uuid: 20632dee-48ba-4be2-82d7-d5c9165a193d
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: 1fb48ebb-6613-4799-8994-ab910292da47
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: f6ac30f3-b587-4a46-9abf-95aa79443cc7
State: Peer in Cluster (Connected)
server2上看
[root@server2 ~]# gluster peer status 
Number of Peers: 3

Hostname: node1
Uuid: 55590ab3-d1f5-44cf-b2e1-7bbcb754aa27
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: 1fb48ebb-6613-4799-8994-ab910292da47
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: f6ac30f3-b587-4a46-9abf-95aa79443cc7
State: Peer in Cluster (Connected)
server3上看
[root@server3 ~]# gluster peer status 
Number of Peers: 3

Hostname: node1
Uuid: 55590ab3-d1f5-44cf-b2e1-7bbcb754aa27
State: Peer in Cluster (Connected)

Hostname: node2
Uuid: 20632dee-48ba-4be2-82d7-d5c9165a193d
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: f6ac30f3-b587-4a46-9abf-95aa79443cc7
State: Peer in Cluster (Connected)
server4上看
[root@server4 ~]# gluster peer status 
Number of Peers: 3

Hostname: node1
Uuid: 55590ab3-d1f5-44cf-b2e1-7bbcb754aa27
State: Peer in Cluster (Connected)

Hostname: node2
Uuid: 20632dee-48ba-4be2-82d7-d5c9165a193d
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: 1fb48ebb-6613-4799-8994-ab910292da47
State: Peer in Cluster (Connected)

初始化磁盘(node1、node2、node3、node4),只在node1上操作

[root@server1 ~]# fdisk -l //查看是否生成了四块磁盘(bcde)
[root@server1 ~]# fdisk /dev/sdb  ( fdisk /dev/sdc   fdisk /dev/sdd   fdisk /dev/sde)分开操作
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x80d26375 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-4194303,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-4194303,默认为 4194303):
将使用默认值 4194303
分区 1 已设置为 Linux 类型,大小设为 2 GiB
命令(输入 m 获取帮助):wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
[root@server1 ~]# fdisk -l //查看四块磁盘(四个服务器上都要查看)

[root@server1 ~]# mkfs.ext4 /dev/sdb1 //格式化四块磁盘
[root@server1 ~]# mkfs.ext4 /dev/sdc1
[root@server1 ~]# mkfs.ext4 /dev/sdd1
[root@server1 ~]# mkfs.ext4 /dev/sde1

创建卷类型(node1、node2、node3、node4),现只在nide1节点上操作

[root@server1 ~]# mkdir -p /data/{sdb1,sdc1,sdd1,sde1}    创建挂载点
[root@server1 ~]# mount /dev/sdb1 /data/sdb1
[root@server1 ~]# mount /dev/sdc1 /data/sdc1
[root@server1 ~]# mount /dev/sdd1 /data/sdd1
[root@server1 ~]# mount /dev/sde1 /data/sde1
[root@server1 ~]# df -Th
文件系统       类型      容量  已用  可用 已用% 挂载点
/dev/sda3      xfs        39G  4.5G   34G   12% /
devtmpfs       devtmpfs  898M     0  898M    0% /dev
tmpfs          tmpfs     912M     0  912M    0% /dev/shm
tmpfs          tmpfs     912M  9.1M  903M    1% /run
tmpfs          tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sr0       iso9660   4.3G  4.3G     0  100% /mnt
/dev/sda5      xfs        19G   33M   19G    1% /home
/dev/sda1      xfs      1014M  174M  841M   18% /boot
tmpfs          tmpfs     183M   12K  183M    1% /run/user/42
tmpfs          tmpfs     183M     0  183M    0% /run/user/0
/dev/sdb1      ext4      2.0G  6.0M  1.9G    1% /data/sdb1
/dev/sdc1      ext4      2.0G  6.0M  1.9G    1% /data/sdc1
/dev/sdd1      ext4      2.0G  6.0M  1.9G    1% /data/sdd1
/dev/sde1      ext4      2.0G  6.0M  1.9G    1% /data/sde1

关闭发送键输入到所有会话,在server1上进行操作
创建分布式卷(创建在节点1,2上)

[root@server1 ~]# gluster volume create dis-vol node1:/data/sdb1 node2:/data/sdb1 force
volume create: dis-vol: success: please start the volume to access data
[root@server1 ~]# gluster volume info dis-vol  //查看信息
 
Volume Name: dis-vol
Type: Distribute
Volume ID: 4ae5dafb-6509-48f2-b360-ca3b571a6e29
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@server1 ~]# gluster volume start dis-vol //开启服务
volume start: dis-vol: success
[root@server1 ~]# gluster volume status dis-vol //查看分布式卷的状态
Status of volume: dis-vol 
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node1:/data/sdb1                      49152     0          Y       42611
Brick node2:/data/sdb1                      49152     0          Y       43432
 
Task Status of Volume dis-vol
------------------------------------------------------------------------------
There are no active volume tasks

创建条带卷(创建在3,4节点上)

[root@server1 ~]# gluster volume create stripe-vol stripe 2 node3:/data/sdb1 node4:/data/sdb1 force
volume create: stripe-vol: success: please start the volume to access data
[root@server1 ~]# gluster volume start stripe-vol  //开启条带式卷
volume start: stripe-vol: success
[root@server1 ~]# gluster volume info stripe-vol //查看信息
 
Volume Name: stripe-vol
Type: Stripe
Volume ID: c2016eda-cc96-4136-9021-d7124bf77642
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@server1 ~]# gluster volume status stripe-vol  // 查看状态
Status of volume: stripe-vol
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node3:/data/sdb1                      49152     0          Y       42379
Brick node4:/data/sdb1                      49152     0          Y       42676
 
Task Status of Volume stripe-vol
------------------------------------------------------------------------------
There are no active volume tasks

创建复制卷

[root@server1 ~]# gluster volume create rep-vol replica 2 node1:/data/sdc1 node2:/data/sdc1 force
volume create: rep-vol: success: please start the volume to access data
[root@server1 ~]# gluster volume start rep-vol 
volume start: rep-vol: success
[root@server1 ~]# gluster volume info rep-vol 
 
Volume Name: rep-vol
Type: Replicate
Volume ID: bff8c10f-8067-4cb5-9f9d-10902d3a61b7
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@server1 ~]# gluster volume status rep-vol 
Status of volume: rep-vol
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node1:/data/sdc1                      49153     0          Y       43269
Brick node2:/data/sdc1                      49153     0          Y       43614
Self-heal Daemon on localhost               N/A       N/A        Y       43289
Self-heal Daemon on node2                   N/A       N/A        Y       43634
Self-heal Daemon on node4                   N/A       N/A        Y       42779
Self-heal Daemon on node3                   N/A       N/A        Y       42469
 
Task Status of Volume rep-vol
------------------------------------------------------------------------------
There are no active volume tasks

创建分布式条带卷

[root@server1 ~]# gluster volume create dis-stripe stripe 2 node1:/sdd1 node2:/sdd1 node3:/sdd1 node4:/sdd1 force
volume create: dis-stripe: success: please start the volume to access data
[root@server1 ~]# gluster volume info dis-stripe 
 
Volume Name: dis-stripe
Type: Distributed-Stripe
Volume ID: 5fff41c8-4ba6-4c05-aa84-ff3bd8a84935
Status: Created
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: node1:/sdd1
Brick2: node2:/sdd1
Brick3: node3:/sdd1
Brick4: node4:/sdd1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
[root@server1 ~]# gluster volume start dis-stripe 
volume start: dis-stripe: success
[root@server1 ~]# gluster volume status dis-stripe 
Status of volume: dis-stripe
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node1:/sdd1                           49154     0          Y       43582
Brick node2:/sdd1                           49154     0          Y       43711
Brick node3:/sdd1                           49153     0          Y       42545
Brick node4:/sdd1                           49153     0          Y       42845
 
Task Status of Volume dis-stripe
------------------------------------------------------------------------------
There are no active volume tasks

创建分布式复制卷

[root@server1 ~]# 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@server1 ~]# gluster volume info dis-rep 
 
Volume Name: dis-rep
Type: Distributed-Replicate
Volume ID: 18a9e1d2-917b-46fb-a898-a018dccc45ad
Status: Created
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@server1 ~]# gluster volume start dis-rep 
volume start: dis-rep: success
[root@server1 ~]# gluster volume status dis-rep 
Status of volume: dis-rep
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node1:/data/sde1                      49155     0          Y       43832
Brick node2:/data/sde1                      49155     0          Y       43792
Brick node3:/data/sde1                      49154     0          Y       42633
Brick node4:/data/sde1                      49154     0          Y       42941
Self-heal Daemon on localhost               N/A       N/A        Y       43852
Self-heal Daemon on node4                   N/A       N/A        Y       42961
Self-heal Daemon on node2                   N/A       N/A        Y       43812
Self-heal Daemon on node3                   N/A       N/A        Y       42653
 
Task Status of Volume dis-rep
------------------------------------------------------------------------------
There are no active volume tasks

显示创建所有的卷

[root@server1 ~]# gluster volume list  //显示创建所有的卷
dis-rep
dis-stripe
dis-vol
rep-vol
stripe-vol

客户端,安装yum环境,查看映射

[root@kehuduan ~]# yum -y install glusterfs glusterfs-fuse
[root@kehuduan ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
20.0.0.10   node1
20.0.0.11   node2
20.0.0.12   node3
20.0.0.14   node4

临时挂载卷(客户机)

[root@kehuduan ~]# mkdir -p /text/{dis,strip,rep,dis_strip,dis_rep}  #创建挂载目录
[root@kehuduan ~]#  mount.glusterfs node1:dis-vol /text/dis  #挂载分布卷
[root@kehuduan ~]#  mount.glusterfs node1:stripe-vol /text/strip/ #挂载条带卷
[root@kehuduan ~]#  mount.glusterfs node1:rep-vol /text/rep/ #挂载复制卷
[root@kehuduan ~]#  mount.glusterfs node1:dis-stripe /text/dis_strip/  #挂载分布式条带卷
[root@kehuduan ~]#  mount.glusterfs node1:dis-rep /text/dis_rep/   #挂载分布式复制卷
[root@kehuduan ~]# df -Th
文件系统         类型            容量  已用  可用 已用% 挂载点
/dev/sda3        xfs              47G  4.5G   43G   10% /
devtmpfs         devtmpfs        898M     0  898M    0% /dev
tmpfs            tmpfs           912M     0  912M    0% /dev/shm
tmpfs            tmpfs           912M  9.2M  903M    2% /run
tmpfs            tmpfs           912M     0  912M    0% /sys/fs/cgroup
/dev/sda1        xfs            1014M  174M  841M   18% /boot
tmpfs            tmpfs           183M  4.0K  183M    1% /run/user/42
tmpfs            tmpfs           183M   48K  183M    1% /run/user/0
/dev/sr0         iso9660         4.3G  4.3G     0  100% /mnt
node1:dis-vol    fuse.glusterfs  3.9G   13M  3.7G    1% /text/dis
node1:stripe-vol fuse.glusterfs  3.9G   13M  3.7G    1% /text/strip
node1:rep-vol    fuse.glusterfs  2.0G  6.2M  1.9G    1% /text/rep
node1:dis-stripe fuse.glusterfs  162G   19G  144G   12% /text/dis_strip
node1:dis-rep    fuse.glusterfs  3.9G   13M  3.7G    1% /text/dis_rep

此时,观察到分布式条带卷的可用空间异常,检查,进行删除操作

客户机先删除挂载 [root@kehuduan ~]# umount /text/dis_strip/
server1上做以下操作
[root@server1 ~]# gluster volume stop dis-stripe 
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: dis-stripe: success
[root@server1 ~]# gluster volume delete dis-stripe 
Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
volume delete: dis-stripe: success
[root@server1 ~]# gluster volume info dis-stripe 
Volume dis-stripe does not exist

[root@server1 ~]# 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@server1 ~]# gluster volume start dis-stripe 
volume start: dis-stripe: success
[root@server1 ~]# gluster volume info dis-stripe 
 
Volume Name: dis-stripe
Type: Distributed-Stripe
Volume ID: 14a081e9-c09f-437c-a128-5cb1593fb65a
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@server1 ~]# gluster volume status dis-stripe 
Status of volume: dis-stripe
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick node1:/data/sdd1                      49154     0          Y       46575
Brick node2:/data/sdd1                      49154     0          Y       45993
Brick node3:/data/sdd1                      49153     0          Y       45036
Brick node4:/data/sdd1                      49153     0          Y       45361
 
Task Status of Volume dis-stripe
------------------------------------------------------------------------------
There are no active volume tasks
 
客户端重新挂载
[root@kehuduan ~]# mount.glusterfs node1:dis-stripe /text/dis_strip/
[root@kehuduan ~]# df -Th
文件系统         类型            容量  已用  可用 已用% 挂载点
/dev/sda3        xfs              47G  4.7G   43G   10% /
devtmpfs         devtmpfs        898M     0  898M    0% /dev
tmpfs            tmpfs           912M     0  912M    0% /dev/shm
tmpfs            tmpfs           912M  9.2M  903M    2% /run
tmpfs            tmpfs           912M     0  912M    0% /sys/fs/cgroup
/dev/sda1        xfs            1014M  174M  841M   18% /boot
tmpfs            tmpfs           183M  4.0K  183M    1% /run/user/42
tmpfs            tmpfs           183M   48K  183M    1% /run/user/0
/dev/sr0         iso9660         4.3G  4.3G     0  100% /mnt
node1:dis-vol    fuse.glusterfs  3.9G  213M  3.5G    6% /text/dis
node1:stripe-vol fuse.glusterfs  3.9G  213M  3.5G    6% /text/strip
node1:rep-vol    fuse.glusterfs  2.0G  207M  1.7G   12% /text/rep
node1:dis-rep    fuse.glusterfs  3.9G  213M  3.5G    6% /text/dis_rep
node1:dis-stripe fuse.glusterfs  7.8G   25M  7.3G    1% /text/dis_strip

[root@kehuduan ~]# cp /demo* /text/dis_strip/
[root@kehuduan ~]# cd /text/dis_strip/
[root@kehuduan dis_strip]# ll
总用量 204804
-rw-r--r--. 1 root root 41943040 11月 24 23:31 demo1.log
-rw-r--r--. 1 root root 41943040 11月 24 23:31 demo2.log
-rw-r--r--. 1 root root 41943040 11月 24 23:31 demo3.log
-rw-r--r--. 1 root root 41943040 11月 24 23:31 demo4.log
-rw-r--r--. 1 root root 41943040 11月 24 23:31 demo5.log
drwx------. 2 root root     4096 11月 24 19:08 lost+found

客户机上做测试


[root@kehuduan ~]# dd if=/dev/zero of=/demo1.log bs=40M count=1
记录了1+0 的读入
记录了1+0 的写出
41943040字节(42 MB)已复制,0.177112 秒,237 MB/秒
[root@kehuduan ~]# dd if=/dev/zero of=/demo2.log bs=40M count=1
记录了1+0 的读入
记录了1+0 的写出
41943040字节(42 MB)已复制,0.262383 秒,160 MB/秒
[root@kehuduan ~]# dd if=/dev/zero of=/demo3.log bs=40M count=1
记录了1+0 的读入
记录了1+0 的写出
41943040字节(42 MB)已复制,0.294576 秒,142 MB/秒
[root@kehuduan ~]# dd if=/dev/zero of=/demo4.log bs=40M count=1
记录了1+0 的读入
记录了1+0 的写出
41943040字节(42 MB)已复制,0.320709 秒,131 MB/秒
[root@kehuduan ~]# dd if=/dev/zero of=/demo5.log bs=40M count=1
记录了1+0 的读入
记录了1+0 的写出
41943040字节(42 MB)已复制,0.250666 秒,167 MB/秒
[root@kehuduan ~]# cd /  
[root@kehuduan /]# ll  //查看是否有5个文件生成
总用量 204830
lrwxrwxrwx.   1 root root        7 11月  4 17:12 bin -> usr/bin
dr-xr-xr-x.   5 root root     4096 11月  4 20:11 boot
-rw-r--r--.   1 root root 41943040 11月 24 20:03 demo1.log
-rw-r--r--.   1 root root 41943040 11月 24 20:04 demo2.log
-rw-r--r--.   1 root root 41943040 11月 24 20:04 demo3.log
-rw-r--r--.   1 root root 41943040 11月 24 20:04 demo4.log
-rw-r--r--.   1 root root 41943040 11月 24 20:04 demo5.log

复制5个文件到挂载目录上
[root@kehuduan /]# cp /demo* /text/dis
[root@kehuduan /]# cp /demo* /text/strip/
[root@kehuduan /]# cp /demo* /text/rep/
[root@kehuduan /]# cp /demo* /text/dis_strip/
[root@kehuduan /]# cp /demo* /text/dis_rep/

 查看文件
 [root@kehuduan /]# ll /text/dis
 [root@kehuduan /]# ll /text/stripe
 [root@kehuduan /]# ll /text/rep
 [root@kehuduan /]# ll /text/dis-stripe
 [root@kehuduan /]# ll /text/dis-rep
日志位置:[root@kehuduan ~]# vi /var/log/glusterfs/text-dis_strip-.log

查看分布式卷分布情况(node1:/data/sdb1,node2:/data/sdb1)

server1上查看
[root@server1 ~]# ls -lh /data/sdb1
总用量 161M
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo1.log
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo2.log
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo3.log
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo4.log
server2上查看
[root@server2 ~]# ls -lh /data/sdb1
总用量 41M
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo5.log
drwx------. 2 root root 16K 11月 24 19:08 lost+found

查看条带卷分布情况(node3:/data/sdb1,node4:/data/sdb1)
server3上查看

[root@server3 ~]# ls -lh /data/sdb1
总用量 101M
-rw-r--r--. 2 root root 20M 11月 24 15:06 demo1.log
-rw-r--r--. 2 root root 20M 11月 24 15:06 demo2.log
-rw-r--r--. 2 root root 20M 11月 24 15:06 demo3.log
-rw-r--r--. 2 root root 20M 11月 24 15:06 demo4.log
-rw-r--r--. 2 root root 20M 11月 24 15:06 demo5.log
drwx------. 2 root root 16K 11月 24 14:08 lost+found
server4上查看
[root@server4 ~]# ls -lh /data/sdb1
总用量 101M
-rw-r--r--. 2 root root 20M 11月 24 20:06 demo1.log
-rw-r--r--. 2 root root 20M 11月 24 20:06 demo2.log
-rw-r--r--. 2 root root 20M 11月 24 20:06 demo3.log
-rw-r--r--. 2 root root 20M 11月 24 20:06 demo4.log
-rw-r--r--. 2 root root 20M 11月 24 20:06 demo5.log
drwx------. 2 root root 16K 11月 24 19:08 lost+found

查看复制卷分布情况(node1:/data/sdc1,node2:/data/sdc1)

[root@server1 ~]# ls -lh /data/sdc1
总用量 201M
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo1.log
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo2.log
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo3.log
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo4.log
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo5.log
drwx------. 2 root root 16K 11月 24 19:08 lost+found

[root@server2 ~]# ls -lh /data/sdc1
总用量 201M
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo1.log
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo2.log
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo3.log
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo4.log
-rw-r--r--. 2 root root 40M 11月 24 20:06 demo5.log
drwx------. 2 root root 16K 11月 24 19:08 lost+found

查看分布式条带卷分布情况(node1:/data/sdd1 node2:/data/sdd1 node3:/data/sdd1 node4:/data/sdd1)

[root@server1 ~]# ls -lh /data/sdd1
总用量 81M
-rw-r--r--. 2 root root 20M 11月 24 23:31 demo1.log
-rw-r--r--. 2 root root 20M 11月 24 23:31 demo2.log
-rw-r--r--. 2 root root 20M 11月 24 23:31 demo3.log
-rw-r--r--. 2 root root 20M 11月 24 23:31 demo4.log
drwx------. 2 root root 16K 11月 24 19:08 lost+found

[root@server2 ~]# ls -lh /data/sdd1
总用量 81M
-rw-r--r--. 2 root root 20M 11月 24 23:31 demo1.log
-rw-r--r--. 2 root root 20M 11月 24 23:31 demo2.log
-rw-r--r--. 2 root root 20M 11月 24 23:31 demo3.log
-rw-r--r--. 2 root root 20M 11月 24 23:31 demo4.log
drwx------. 2 root root 16K 11月 24 19:08 lost+found
[root@server3 ~]# ls -lh /data/sdd1
总用量 21M
-rw-r--r--. 2 root root 20M 11月 24 18:31 demo5.log
drwx------. 2 root root 16K 11月 24 14:08 lost+found

[root@server4 ~]#  ls -lh /data/sdd1
总用量 21M
-rw-r--r--. 2 root root 20M 11月 24 23:31 demo5.log
drwx------. 2 root root 16K 11月 24 19:08 lost+found

查看分布式复制卷分布情况(node1:/data/sde1 node2:/data/sde1 node3:/data/sde1 node4:/data/sde1)

[root@server1 ~]# ls -lh /data/sde1
总用量 161M
-rw-r--r--. 2 root root 40M 11月 24 20:08 demo1.log
-rw-r--r--. 2 root root 40M 11月 24 20:08 demo2.log
-rw-r--r--. 2 root root 40M 11月 24 20:08 demo3.log
-rw-r--r--. 2 root root 40M 11月 24 20:08 demo4.log
drwx------. 2 root root 16K 11月 24 19:09 lost+found

[root@server2 ~]# ls -lh /data/sde1
总用量 161M
-rw-r--r--. 2 root root 40M 11月 24 20:08 demo1.log
-rw-r--r--. 2 root root 40M 11月 24 20:08 demo2.log
-rw-r--r--. 2 root root 40M 11月 24 20:08 demo3.log
-rw-r--r--. 2 root root 40M 11月 24 20:08 demo4.log
drwx------. 2 root root 16K 11月 24 19:09 lost+found

[root@server3 ~]# ls -lh /data/sde1
总用量 41M
-rw-r--r--. 2 root root 40M 11月 24 15:08 demo5.log
drwx------. 2 root root 16K 11月 24 14:09 lost+found

[root@server4 ~]#  ls -lh /data/sde1
总用量 41M
-rw-r--r--. 2 root root 40M 11月 24 20:08 demo5.log
drwx------. 2 root root 16K 11月 24 19:09 lost+found

破坏测试

关闭node2服务器(在客户端)查看实验结果(关闭虚拟机)
[root@kehuduan dis_strip]# cd /text/dis
[root@kehuduan dis]# ll  (demo5.log消失了)
总用量 163844
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo1.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo2.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo3.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo4.log
drwx------. 2 root root     4096 11月 24 19:08 lost+found


[root@kehuduan dis]# cd ..
[root@kehuduan text]# cd strip/
[root@kehuduan strip]# ll
总用量 204804
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo1.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo2.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo3.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo4.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo5.log
drwx------. 2 root root     4096 11月 24 19:08 lost+found
[root@kehuduan strip]# ls -lh
总用量 201M
-rw-r--r--. 1 root root  40M 11月 24 20:06 demo1.log
-rw-r--r--. 1 root root  40M 11月 24 20:06 demo2.log
-rw-r--r--. 1 root root  40M 11月 24 20:06 demo3.log
-rw-r--r--. 1 root root  40M 11月 24 20:06 demo4.log
-rw-r--r--. 1 root root  40M 11月 24 20:06 demo5.log
drwx------. 2 root root 4.0K 11月 24 19:08 lost+found
[root@kehuduan strip]# cd
[root@kehuduan ~]# df -Th
文件系统         类型            容量  已用  可用 已用% 挂载点
/dev/sda3        xfs              47G  4.7G   43G   10% /
devtmpfs         devtmpfs        898M     0  898M    0% /dev
tmpfs            tmpfs           912M     0  912M    0% /dev/shm
tmpfs            tmpfs           912M  9.2M  903M    2% /run
tmpfs            tmpfs           912M     0  912M    0% /sys/fs/cgroup
/dev/sda1        xfs            1014M  174M  841M   18% /boot
tmpfs            tmpfs           183M  4.0K  183M    1% /run/user/42
tmpfs            tmpfs           183M   48K  183M    1% /run/user/0
/dev/sr0         iso9660         4.3G  4.3G     0  100% /mnt
node1:dis-vol    fuse.glusterfs  2.0G  167M  1.7G    9% /text/dis
node1:stripe-vol fuse.glusterfs  3.9G  213M  3.5G    6% /text/strip
node1:rep-vol    fuse.glusterfs  2.0G  207M  1.7G   12% /text/rep
node1:dis-rep    fuse.glusterfs  3.9G  213M  3.5G    6% /text/dis_rep
node1:dis-stripe fuse.glusterfs  5.9G  139M  5.4G    3% /text/dis_strip
[root@kehuduan ~]# cd /text/strip/
[root@kehuduan strip]# ll
总用量 204804
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo1.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo2.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo3.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo4.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo5.log
drwx------. 2 root root     4096 11月 24 19:08 lost+found
[root@kehuduan strip]# cd ..
[root@kehuduan text]# cd rep/
[root@kehuduan rep]# ll
总用量 204804
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo1.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo2.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo3.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo4.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo5.log
drwx------. 2 root root     4096 11月 24 19:08 lost+found
[root@kehuduan rep]# cd ..
[root@kehuduan text]# cd rep/
[root@kehuduan rep]# ll
总用量 204804
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo1.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo2.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo3.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo4.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo5.log
drwx------. 2 root root     4096 11月 24 19:08 lost+found
[root@kehuduan rep]# cd ..
[root@kehuduan text]# cd dis_strip/
[root@kehuduan dis_strip]# ll
总用量 40964
-rw-r--r--. 1 root root 41943040 11月 24 23:31 demo5.log
drwx------. 2 root root     4096 11月 24 19:08 lost+found
[root@kehuduan dis_strip]# cd /text/dis_rep/
[root@kehuduan dis_rep]# ll
总用量 204804
-rw-r--r--. 1 root root 41943040 11月 24 20:08 demo1.log
-rw-r--r--. 1 root root 41943040 11月 24 20:08 demo2.log
-rw-r--r--. 1 root root 41943040 11月 24 20:08 demo3.log
-rw-r--r--. 1 root root 41943040 11月 24 20:08 demo4.log
-rw-r--r--. 1 root root 41943040 11月 24 20:08 demo5.log
drwx------. 2 root root     4096 11月 24 19:09 lost+found

再关闭node3节点,客户端查看现象

[root@kehuduan dis_rep]# cd
[root@kehuduan ~]# cd /text/strip
-bash: cd: /text/strip: 传输端点尚未连接
[root@kehuduan dis_rep]# ll
总用量 204804
-rw-r--r--. 1 root root 41943040 11月 24 20:08 demo1.log
-rw-r--r--. 1 root root 41943040 11月 24 20:08 demo2.log
-rw-r--r--. 1 root root 41943040 11月 24 20:08 demo3.log
-rw-r--r--. 1 root root 41943040 11月 24 20:08 demo4.log
-rw-r--r--. 1 root root 41943040 11月 24 20:08 demo5.log
drwx------. 2 root root     4096 11月 24 19:09 lost+found

访问控制(仅拒绝)

note1节点上操作
[root@server1 ~]# gluster volume set rep-vol auth.reject 20.0.0.13
volume set: success
客户机验证:
[root@kehuduan dis_rep]# cd
[root@kehuduan ~]# df -Th
文件系统         类型            容量  已用  可用 已用% 挂载点
/dev/sda3        xfs              47G  4.7G   43G   10% /
devtmpfs         devtmpfs        898M     0  898M    0% /dev
tmpfs            tmpfs           912M     0  912M    0% /dev/shm
tmpfs            tmpfs           912M  9.2M  903M    2% /run
tmpfs            tmpfs           912M     0  912M    0% /sys/fs/cgroup
/dev/sda1        xfs            1014M  174M  841M   18% /boot
tmpfs            tmpfs           183M  4.0K  183M    1% /run/user/42
tmpfs            tmpfs           183M   48K  183M    1% /run/user/0
/dev/sr0         iso9660         4.3G  4.3G     0  100% /mnt
node1:dis-vol    fuse.glusterfs  2.0G  167M  1.7G    9% /text/dis
node1:stripe-vol fuse.glusterfs  2.0G  107M  1.8G    6% /text/strip
node1:dis-rep    fuse.glusterfs  3.9G  213M  3.5G    6% /text/dis_rep
node1:dis-stripe fuse.glusterfs  3.9G  113M  3.6G    4% /text/dis_strip
[root@kehuduan ~]# cd /text/dis
[root@kehuduan dis]# ll
总用量 163844
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo1.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo2.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo3.log
-rw-r--r--. 1 root root 41943040 11月 24 20:06 demo4.log
drwx------. 2 root root     4096 11月 24 19:08 lost+found
[root@kehuduan dis]# vi demo1.log  //此时查看日志文件出现乱码
[root@kehuduan dis]# cat demo1.log

note1检点再次禁用
[root@server1 ~]# gluster volume set dis-stripe auth.reject 20.0.0.13
volume set: success
[root@kehuduan dis]# cd  //发现该节点没有被挂载
[root@kehuduan ~]# df -Th
文件系统         类型            容量  已用  可用 已用% 挂载点
/dev/sda3        xfs              47G  4.8G   43G   11% /
devtmpfs         devtmpfs        898M     0  898M    0% /dev
tmpfs            tmpfs           912M     0  912M    0% /dev/shm
tmpfs            tmpfs           912M  9.2M  903M    2% /run
tmpfs            tmpfs           912M     0  912M    0% /sys/fs/cgroup
/dev/sda1        xfs            1014M  174M  841M   18% /boot
tmpfs            tmpfs           183M  4.0K  183M    1% /run/user/42
tmpfs            tmpfs           183M   48K  183M    1% /run/user/0
/dev/sr0         iso9660         4.3G  4.3G     0  100% /mnt
node1:dis-vol    fuse.glusterfs  2.0G  167M  1.7G    9% /text/dis
node1:stripe-vol fuse.glusterfs  2.0G  107M  1.8G    6% /text/strip
node1:dis-rep    fuse.glusterfs  3.9G  213M  3.5G    6% /text/dis_rep
[root@kehuduan ~]# vi /var/log/glusterfs/text-rep-.log //查看日志
[2020-11-24 15:59:08.284517] E [fuse-bridge.c:5322:notify] 0-fuse: Server authenication failed. Shutting down.
[2020-11-24 15:59:08.284550] I [fuse-bridge.c:5802:fini] 0-fuse: Unmounting '/text/rep/'.

访问控制(仅允许)
[root@server1 ~]# gluster volume set rep-vol auth.allow 20.0.0.13
volume set: success
[root@server1 ~]# gluster volume set dis-stripe auth.allow 20.0.0.13
volume set: success
在进行以下操作
[root@server1 ~]# gluster volume stop rep-vol 
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: rep-vol: success
[root@server1 ~]# gluster volume start rep-vol 
volume start: rep-vol: success
客户端挂载,发现报错
[root@kehuduan ~]# mount.glusterfs node1:rep-vol /text/rep/
Mount failed. Please check the log file for more details.

[root@server1 ~]# gluster volume set rep-vol auth.allow 20.0.0.13
volume set: success
仅拒绝:
[root@server1]# gluster volume set dis-vol auth.reject 20.0.0.13
volume set: success

仅允许
[root@server1]# gluster volume set dis-vol auth.allow 20.0.0.13
volume set: success
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值