●开源的分布式文件系统
●由存储服务器,客户端以及NFS/Samba存储网关组成
●无元数据服务器
●扩展性和高性能
●高可用性
●全局统一命名空间
●弹性卷管理
●基于标准协议
●模块化,堆栈式的架构
●通过对模块的组合,实现复杂的功能d
说明:
●Application:客户端或应用程序通过GlusterFS的挂载点访问数据
●VFS:linux系统内核
●FLUS-/dev/flus:VFS将数据递交给FUSE内核文件系统,fuse文件系统则是将数据通过/dev/fuse设备文件递交给了GLusterFS client端
●GLusterFS client:GLusterFS client收到数据后,client根据配置文件的配置对数据进行处理
●GlusterFS server:通过网路将数据传递至远端的GlusterFS Server,并且将数据写入到服务器存储设备上
●通过HASH算法得到一个32位的整数
●划分为N个连续的子空间,每个空间对应一个Brick
●弹性HASH算法的优点:
●分布式卷
●条带卷
●复制卷
●分布式条带卷
●分布式复制卷
●条带复制卷
●分布式条带复制卷
●没有对文件进行分块处理
●通过扩展文件属性保存HASH值
●支持的底层文件系统有EXT3,EXT4,ZFS,XFS等
●文件分布在不同的服务器,不具备冗余性
●更容易和廉价地扩展卷的大小
●单点故障会造成数据丢失
●依赖底层的数据保护
●创建一个名为dis-volume的分布式卷,文件将根据HASH分布在server1:/dir1,server2:/dir2和server3:/dir3中
#gluster volume create die-volume server1:/dir1 server2:/dir2 server3:/dir3
●根据偏移量将文件分成N块(N个条带节点),轮询的存储在每个Brick Server节点
●存储大文件时,性能尤为突出
●不具备冗余性,类似Raid0
●数据被分割成更小块分布到块服务器中的不同条带区
●分布减少了负载且更小的文件加速了存取的速度
●没有数据冗余
● 创建了一个名为Strip-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:/dir1 server2:/dir2 server3:/dir3 server4:/dir4
●兼顾分布式卷和复制卷的功能
●用于需要冗余的情况
● 创建名为dis-rep的分布式复制卷,额皮质分布式复制卷时,卷中Brick所包含的存储服务器数必须是复制卷的倍数(>=2倍)
# gluster volume create dis-rep replica 2 transport tcp server1:/dir1 server2:/dir2 server3:/dir3 server4:/dir4
操作系统 | IP | 主机名 | 硬盘数量 |
---|---|---|---|
centos7.4 | 20.0.0.11 | node1 | sdb:20G sdc:20G sdd:20G sde:20G |
centos7.4 | 20.0.0.12 | node2 | sdb:20G sdc:20G sdd:20G sde:20G |
centos7.4 | 20.0.0.13 | node3 | sdb:20G sdc:20G sdd:20G sde:20G |
centos7.4 | 20.0.0.15 | node4 | sdb:20G sdc:20G sdd:20G sde:20G |
1.闭防火墙,核心防护
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
2.修改主机名
[root@localhost ~]# hostnamectl set-hostname node1
[root@localhost ~]# hostnamectl set-hostname node2
[root@localhost ~]# hostnamectl set-hostname node3
[root@localhost ~]# hostnamectl set-hostname node4
[root@localhost ~]# su
3.域名解析
[root@node1 ~]# vi /etc/hosts
20.0.0.11 node1
20.0.0.12 node2
20.0.0.13 node3
20.0.0.15 node4
scp /etc/hosts [email protected]:/etc/hosts
scp /etc/hosts [email protected]:/etc/hosts
scp /etc/hosts [email protected]:/etc/hosts
4.写脚本,创建磁盘分区
##在四台服务器上添加4块新硬盘##
[root@node1 ~]# vi disk.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)
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
[root@node1 ~]# chmod +x disk.sh
[root@node1 ~]# ./disk.sh //分别输入1,2,3,4创建磁盘分区
the disks exist list:
================================
1) sdb
2) sdc
3) sdd
4) sde
5) quit
[root@node1 ~]# df -Th
/dev/sdb1 xfs 20G 33M 20G 1% /data/sdb1
/dev/sdc1 xfs 20G 33M 20G 1% /data/sdc1
/dev/sdd1 xfs 20G 33M 20G 1% /data/sdd1
/dev/sde1 xfs 20G 33M 20G 1% /data/sde1
##其他三台服务器复制脚步操作##
[root@node1 ~]# scp disk.sh [email protected]:/root
[root@node1 ~]# scp disk.sh [email protected]:/root
[root@node1 ~]# scp disk.sh [email protected]:/root
5.搭建GFS本源
##把GFS本地源文件夹传到/abc目录下
[root@node1 abc]# cd /etc/yum.repos.d/
[root@node1 yum.repos.d]# mv backup/ backup.bak/
[root@node1 yum.repos.d]# vi GLFS.repo
[GLFS]
name=glfs
baseurl=file:///abc/gfsrepo/
gpgcheck=0
enabled=1
[root@node1 yum.repos.d]# yum -y install glusterfs-server glusterfs-fuse glusterfs-rdma
[root@node1 yum.repos.d]# systemctl start glusterd.service
[root@node1 yum.repos.d]# 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 yum.repos.d]# systemctl status glusterd.service
##其他三个同理##
[root@node2 ~]# mkdir /abc/gfsrepo/
[root@node3 ~]# mkdir /abc/gfsrepo/
[root@node4 ~]# mkdir /abc/gfsrepo/
[root@node1 abc]# scp -r /abc/gfsrepo/ [email protected]:/abc/
[root@node1 abc]# scp -r /abc/gfsrepo/ [email protected]:/abc/
[root@node1 abc]# scp -r /abc/gfsrepo/ [email protected]:/abc/
6.设置时间同步
[root@node1 ~]# yum -y install ntpdate
[root@node1 ~]# ntpdate ntp1.aliyun.com
7.添加入存储信任池,只要在一台主机上添加其他节点即可
[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: b1c2d15a-97bd-4c10-a1d3-13f0bb2a8a10
State: Peer in Cluster (Connected)
Hostname: node3
Uuid: e5e99a92-4001-42a8-b958-71f6bd8ae3f0
State: Peer in Cluster (Connected)
Hostname: node4
Uuid: a9059dfe-8254-4ab2-80be-3fac9e167e74
State: Peer in Cluster (Connected)
1.分布式卷
[root@node1 ~]# 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@node1 ~]# gluster volume info dis-vol
Volume Name: dis-vol
Type: Distribute
Volume ID: b1256331-2191-4a5d-8392-9acc3a978684
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 ~]# gluster volume start dis-vol
volume start: dis-vol: success
[root@node1 ~]# gluster volume info dis-vol
Volume Name: dis-vol
Type: Distribute
Volume ID: b1256331-2191-4a5d-8392-9acc3a978684
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-vol stripe 2 node1:/data/sdc1 node2:/data/sdc1 force
volume create: stripe-vol: success: please start the volume to access data
[root@node1 ~]# gluster volume start stripe-vol
volume start: stripe-vol: success
[root@node1 ~]# gluster volume info stripe-vol
Volume Name: stripe-vol
Type: Stripe
Volume ID: 4cfef65d-1193-495a-8d00-c8c8f14e6f53
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-vol replica 2 node3:/data/sdd1 node4:/data/sdd1 force
volume create: rep-vol: success: please start the volume to access data
[root@node1 ~]# gluster volume info rep-vol
Volume Name: rep-vol
Type: Replicate
Volume ID: 1db5498e-d27d-4886-8d67-c4a31ccc3295
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node3:/data/sdd1
Brick2: node4:/data/sdd1
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/sdb1 node4:/data/sdb1 force
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: 78843c3a-eb16-408c-9dc5-3565d50f4a8a
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/sdb1
Brick4: node4:/data/sdb1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
5.分布式复制卷
[root@node1 ~]# 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@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: 5d9a0b1c-f7a9-41b5-80dc-1f366b180674
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
1.搭建GFS本地源
[root@node1 ~]# scp -r /abc/gfsrepo/ [email protected]:/abc/
[root@localhost abc]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mv backup/ backup.bak/
[root@localhost yum.repos.d]# vi GLFS.repo
[GLFS]
name=glfs
baseurl=file:///abc/gfsrepo
gpgcheck=0
enabled=1
2.域名解析
[root@localhost yum.repos.d]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
20.0.0.11 node1
20.0.0.12 node2
20.0.0.13 node3
20.0.0.15 node4
3.挂载
##挂载分布式卷##
[root@localhost yum.repos.d]# mount.glusterfs node1:dis-vol /test/dis/
[root@localhost yum.repos.d]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 50G 4.1G 46G 9% /
devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 13M 3.8G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda5 xfs 242G 37M 241G 1% /home
/dev/sda1 xfs 1014M 174M 841M 18% /boot
tmpfs tmpfs 781M 12K 781M 1% /run/user/42
tmpfs tmpfs 781M 0 781M 0% /run/user/0
/dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt
node1:dis-vol fuse.glusterfs 40G 65M 40G 1% /test/dis
##挂载条带卷##
[root@localhost yum.repos.d]# mkdir -p /test/stripe
[root@localhost yum.repos.d]# mount.glusterfs node1:stripe-vol /test/stripe/
[root@localhost yum.repos.d]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 50G 4.1G 46G 9% /
devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 13M 3.8G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda5 xfs 242G 37M 241G 1% /home
/dev/sda1 xfs 1014M 174M 841M 18% /boot
tmpfs tmpfs 781M 12K 781M 1% /run/user/42
tmpfs tmpfs 781M 0 781M 0% /run/user/0
/dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt
node1:dis-vol fuse.glusterfs 40G 65M 40G 1% /test/dis
node1:stripe-vol fuse.glusterfs 40G 65M 40G 1% /test/stripe
##挂载复制卷##
[root@localhost yum.repos.d]# mkdir -p /test/rep
[root@localhost yum.repos.d]# mount.glusterfs node3:rep-vol /test/rep/
[root@localhost yum.repos.d]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 50G 4.1G 46G 9% /
devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 13M 3.8G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda5 xfs 242G 37M 241G 1% /home
/dev/sda1 xfs 1014M 174M 841M 18% /boot
tmpfs tmpfs 781M 12K 781M 1% /run/user/42
tmpfs tmpfs 781M 0 781M 0% /run/user/0
/dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt
node1:dis-vol fuse.glusterfs 40G 65M 40G 1% /test/dis
node1:stripe-vol fuse.glusterfs 40G 65M 40G 1% /test/stripe
node3:rep-vol fuse.glusterfs 20G 33M 20G 1% /test/rep
##挂载分布式条带卷##
[root@localhost yum.repos.d]# mkdir -p /test/dis-stripe
[root@localhost yum.repos.d]# mount.glusterfs node1:dis-stripe /test/dis-stripe/
[root@localhost yum.repos.d]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 54G 4.4G 50G 9% /
devtmpfs devtmpfs 4.1G 0 4.1G 0% /dev
tmpfs tmpfs 4.1G 0 4.1G 0% /dev/shm
tmpfs tmpfs 4.1G 13M 4.1G 1% /run
tmpfs tmpfs 4.1G 0 4.1G 0% /sys/fs/cgroup
/dev/sda5 xfs 259G 38M 259G 1% /home
/dev/sda1 xfs 1.1G 183M 881M 18% /boot
tmpfs tmpfs 819M 13k 819M 1% /run/user/42
tmpfs tmpfs 819M 0 819M 0% /run/user/0
/dev/sr0 iso9660 4.6G 4.6G 0 100% /mnt
node1:dis-vol fuse.glusterfs 43G 68M 43G 1% /test/dis
node1:stripe-vol fuse.glusterfs 43G 68M 43G 1% /test/stripe
node3:rep-vol fuse.glusterfs 22G 34M 22G 1% /test/rep
node1:dis-stripe fuse.glusterfs 86G 136M 86G 1% /test/dis-stripe
##挂载分布式复制卷##
[root@localhost yum.repos.d]# mkdir -p /test/dis-rep
[root@localhost yum.repos.d]# mount.glusterfs node1:dis-rep /test/dis-rep/
[root@localhost yum.repos.d]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 50G 4.1G 46G 9% /
devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 13M 3.8G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda5 xfs 242G 37M 241G 1% /home
/dev/sda1 xfs 1014M 174M 841M 18% /boot
tmpfs tmpfs 781M 12K 781M 1% /run/user/42
tmpfs tmpfs 781M 0 781M 0% /run/user/0
/dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt
node1:dis-vol fuse.glusterfs 40G 65M 40G 1% /test/dis
node1:stripe-vol fuse.glusterfs 40G 65M 40G 1% /test/stripe
node3:rep-vol fuse.glusterfs 20G 33M 20G 1% /test/rep
node1:dis-stripe fuse.glusterfs 80G 130M 80G 1% /test/dis-stripe
node1:dis-rep fuse.glusterfs 40G 65M 40G 1% /test/dis-rep
4.创建测试文件
##创建5个40M的文件##
[root@localhost yum.repos.d]# dd if=/dev/zero of=/demo1.log bs=1M count=40
[root@localhost yum.repos.d]# dd if=/dev/zero of=/demo2.log bs=1M count=40
[root@localhost yum.repos.d]# dd if=/dev/zero of=/demo3.log bs=1M count=40
[root@localhost yum.repos.d]# dd if=/dev/zero of=/demo4.log bs=1M count=40
[root@localhost yum.repos.d]# dd if=/dev/zero of=/demo5.log bs=1M count=40
##复制5个文件到不同卷上##
[root@localhost /]# cp /demo* /test/dis
[root@localhost /]# cp /demo* /test/stripe
[root@localhost /]# cp /demo* /test/rep
[root@localhost /]# cp /demo* /test/dis-stripe
[root@localhost /]# cp /demo* /test/dis-rep
##查看##
[root@localhost /]# cd /test/
[root@localhost test]# ll
total 20
drwxr-xr-x 3 root root 4096 Oct 27 17:38 dis
drwxr-xr-x 3 root root 4096 Oct 27 17:39 dis-rep
drwxr-xr-x 3 root root 4096 Oct 27 17:39 dis-stripe
drwxr-xr-x 3 root root 4096 Oct 27 17:38 rep
drwxr-xr-x 3 root root 4096 Oct 27 17:38 stripe
##关闭node2查看文件##
[ro[root@localhost test]# ls -lh dis
total 160M
-rw-r--r-- 1 root root 40M Oct 27 17:38 demo1.log
-rw-r--r-- 1 root root 40M Oct 27 17:38 demo2.log
-rw-r--r-- 1 root root 40M Oct 27 17:38 demo3.log
-rw-r--r-- 1 root root 40M Oct 27 17:38 demo4.log
[root@localhost test]# ls -lh dis-rep
total 200M
-rw-r--r-- 1 root root 40M Oct 27 17:39 demo1.log
-rw-r--r-- 1 root root 40M Oct 27 17:39 demo2.log
-rw-r--r-- 1 root root 40M Oct 27 17:39 demo3.log
-rw-r--r-- 1 root root 40M Oct 27 17:39 demo4.log
-rw-r--r-- 1 root root 40M Oct 27 17:39 demo5.log
[root@localhost test]# ls -lh dis-stripe
total 40M
-rw-r--r-- 1 root root 40M Oct 27 17:39 demo5.log
[root@localhost test]# ls -lh stripe
ls: reading directory stripe: Transport endpoint is not connected
total 0
##关闭node3查看文件##
[root@localhost test]# ls -lh rep
total 200M
-rw-r--r-- 1 root root 40M Oct 27 17:38 demo1.log
-rw-r--r-- 1 root root 40M Oct 27 17:38 demo2.log
-rw-r--r-- 1 root root 40M Oct 27 17:38 demo3.log
-rw-r--r-- 1 root root 40M Oct 27 17:38 demo4.log
-rw-r--r-- 1 root root 40M Oct 27 17:38 demo5.log
1.删除卷
[root@node1 ~]# gluster volume stop rep-vol
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) yes
volume stop: rep-vol: success
[root@node1 ~]# gluster volume list
dis-rep
dis-stripe
dis-vol
rep-vol
stripe-vol
[root@node1 ~]# gluster volume delete rep-vol //删除卷时,信任池中不能有主机处于宕机状态,否则删除不成功
2.访问控制
[root@node1 ~]# gluster volume set dis-vol auth.reject 20.0.0.12
volume set: success //仅拒绝
[root@node1 ~]# gluster volume set dis-vol auth.allow 20.0.0.12
volume set: success //仅允许