GlusterFS集群部署

目录

一、部署GlusterFS集群

1.准备环境

2.节点进行磁盘挂载,安装本地源

3.添加节点创建集群

4.根据规划创建卷

4.1创建分布式卷

4.2创建条带卷

4.3创建复制卷

4.4创建分布式条带卷

4.5创建分布式复制卷

5.部署gluster客户端

5.1安装客户端软件

5.2挂载Gluster文件系统

5.3测试Gluster文件系统

5.4查看文件分布

5.5冗余测试

二、其他维护命令


一、部署GlusterFS集群

1.准备环境

Node1节点:node1/192.168.187.48		  磁盘: /dev/sdb1			挂载点: /data/sdb1
											/dev/sdc1					/data/sdc1
											/dev/sdd1					/data/sdd1
											/dev/sde1					/data/sde1
 
Node2节点:node2/192.168.187.68		  磁盘: /dev/sdb1			挂载点: /data/sdb1
											/dev/sdc1					/data/sdc1
											/dev/sdd1					/data/sdd1
											/dev/sde1					/data/sde1
 
Node3节点:node3/192.168.187.78		  磁盘: /dev/sdb1			挂载点: /data/sdb1
											/dev/sdc1					/data/sdc1
											/dev/sdd1					/data/sdd1
											/dev/sde1					/data/sde1
 
Node4节点:node4/192.168.187.98   	  磁盘: /dev/sdb1			挂载点: /data/sdb1
											/dev/sdc1					/data/sdc1
											/dev/sdd1					/data/sdd1
											/dev/sde1					/data/sde1
 
=====客户端节点:192.168.187.108=====

1.首先,每台节点添加四块磁盘,仅做实验,无需太大
2.然后重启服务器,准备开始部署

2.节点进行磁盘挂载,安装本地源

所有节点(这里使用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)
        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 fdisk.sh

./fdisk.sh

df -hT

node1 :

node2: 

 

node3:

 

node4: 

配置各个节点的/etc/hosts文件(所有节点操作)

vim /etc/hosts    #添加映射

192.168.187.48 node1
192.168.187.68 node2
192.168.187.78 node3
192.168.187.98 node4

配置本地源

mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/

cd /opt
#上传压缩包

unzip gfsrepo.zip  #解压

cd /etc/yum.repo.d
vim /etc/yum.repos.d/glfs.repo   #编辑镜像源文件
[gfs]
name=gfs
baseurl=file:///opt/gfsrepeo
gpgcheck=0
enabled=1
 
yum clean all && yum makecache
yum -y install centos-release-gluster
#如采用官方yum 源安装,可以直接指向互联网仓库
 
yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
#第一次安装会有报错情况,找出报错关系给与移除


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

安装如果出现以下报错,可以删除之前的依赖包,然后重新下载

rpm -e --nodeps glusterfs-api glusterfs-libs glusterfs-fuse glusterfs-cli  glusterfs glusterfs-client-xlators

节点2:

节点3:

节点4:

3.添加节点创建集群

添加节点到存储信任池中(仅需在一个节点上操作,这里依旧在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: node3
Uuid: 135bca7b-9ff8-4ace-b4f1-336b43408a4e
State: Peer in Cluster (Connected)

Hostname: node2
Uuid: 40c45940-c0f4-4594-b71c-d5ba27af811e
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: 2aee2a0e-0b3f-4437-a5f1-c5b326c0e369
State: Peer in Cluster (Connected)

4.根据规划创建卷

========根据以下规划创建卷=========
卷名称 				卷类型				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)

4.1创建分布式卷

创建分布式卷,没有指定类型,默认创建的是分布式卷

[root@node1 ~]# 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: 6d231eeb-5f2c-49c9-b427-ca8773781d54
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

4.2创建条带卷

创建条带卷,指定类型为stripe

[root@node1 ~]# 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 ~]# 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: 9362a966-e95e-4e5c-86fc-f5a593f4e957
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

4.3创建复制卷

创建复制卷,指定类型为replica,数值为2,且后面跟了2个Brick Server,所以创建的是复制卷

[root@node1 ~]# 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 ~]# 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: dd646eac-baf2-44d3-9f24-a07c5c1d30c5
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.4创建分布式条带卷

创建分布式条带卷,指定类型为stripe,数值为2,而且后面跟了4个Brick Server,是2的两倍,所以创建的是分布式条带卷

[root@node1 ~]# 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 ~]# 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: a6b32dea-b91b-4747-b8a4-41c6fd77cb50
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

4.5创建分布式复制卷

指定类型为replica,数值为2,而且后面跟了4个Brick Server,是2的两倍,所以创建的是分布式复制卷

[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: 58527b17-da9c-4e32-82e3-40c6b27fffae
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.部署gluster客户端

5.1安装客户端软件

配置本地源

#将gfsrepo软件上传到/opt目录下
unzip gfsrepo.zip    #解压
cd /etc/yum.repos.d/   #配置本地源
mkdir bak
mv *.repo bak

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

yum clean all && yum makecache

添加映射

vim /etc/hosts    #添加映射

192.168.187.48 node1
192.168.187.68 node2
192.168.187.78 node3
192.168.187.98 node4

安装gluster

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

5.2挂载Gluster文件系统

[root@client ~]# mkdir -p /test/{dis,stripe,rep,dis-stripe,dis-rep}
[root@client ~]# cd /test/
[root@client test]# ls
dis  dis-rep  dis-stripe  rep  stripe
[root@client test]# mount.glusterfs node1:dis-volume /test/dis
[root@client test]# mount.glusterfs node1:stripe-volume /test/stripe
[root@client test]# mount.glusterfs node1:rep-volume /test/rep
[root@client test]# mount.glusterfs node1:dis-stripe /test/dis-stripe
[root@client test]# mount.glusterfs node1:dis-rep /test/dis-rep
[root@client test]# df -hT
文件系统            类型            容量  已用  可用 已用% 挂载点
/dev/sda3           xfs              79G   13G   66G   17% /
devtmpfs            devtmpfs        1.9G     0  1.9G    0% /dev
tmpfs               tmpfs           1.9G     0  1.9G    0% /dev/shm
tmpfs               tmpfs           1.9G   13M  1.9G    1% /run
tmpfs               tmpfs           1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda1           xfs             497M  167M  330M   34% /boot
tmpfs               tmpfs           378M  4.0K  378M    1% /run/user/42
tmpfs               tmpfs           378M   32K  378M    1% /run/user/0
/dev/sr0            iso9660         4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64
/dev/sdc1           xfs             6.0G   33M  6.0G    1% /data/sdc1
/dev/sdd1           xfs             6.0G   33M  6.0G    1% /data/sdd1
/dev/sde1           xfs             6.0G   33M  6.0G    1% /data/sde1
node1:dis-volume    fuse.glusterfs   12G   65M   12G    1% /test/dis
node1:stripe-volume fuse.glusterfs   12G   65M   12G    1% /test/stripe
node1:rep-volume    fuse.glusterfs  6.0G   33M  6.0G    1% /test/rep
node1:dis-stripe    fuse.glusterfs   24G  130M   24G    1% /test/dis-stripe
node1:dis-rep       fuse.glusterfs   12G   65M   12G    1% /test/dis-rep

5.3测试Gluster文件系统

[root@client test]#dd if=/dev/zero of=/opt/demo1.log bs=1M count=40
记录了40+0 的读入
记录了40+0 的写出
41943040字节(42 MB)已复制,0.0290747 秒,1.4 GB/秒
[root@client test]#dd if=/dev/zero of=/opt/demo2.log bs=1M count=40
记录了40+0 的读入
记录了40+0 的写出
41943040字节(42 MB)已复制,0.0621137 秒,675 MB/秒
[root@client test]#dd if=/dev/zero of=/opt/demo3.log bs=1M count=40
记录了40+0 的读入
记录了40+0 的写出
41943040字节(42 MB)已复制,0.0661249 秒,634 MB/秒
[root@client test]#dd if=/dev/zero of=/opt/demo4.log bs=1M count=40
记录了40+0 的读入
记录了40+0 的写出
41943040字节(42 MB)已复制,0.194974 秒,215 MB/秒
[root@client test]#dd if=/dev/zero of=/opt/demo5.log bs=1M count=40
记录了40+0 的读入
记录了40+0 的写出
41943040字节(42 MB)已复制,0.241915 秒,173 MB/秒
[root@client test]#ls -lh /opt
总用量 298M
drwx--x--x.  4 root root    28 10月 12 09:28 containerd
-rw-r--r--.  1 root root   40M 10月 14 14:05 demo1.log
-rw-r--r--.  1 root root   40M 10月 14 14:06 demo2.log
-rw-r--r--.  1 root root   40M 10月 14 14:06 demo3.log
-rw-r--r--.  1 root root   40M 10月 14 14:06 demo4.log
-rw-r--r--.  1 root root   40M 10月 14 14:06 demo5.log
-rwxr-xr-x.  1 root root   838 10月 14 11:55 fdisk.sh
drwxr-xr-x.  3 root root  8.0K 3月  27 2018 gfsrepo
-rw-r--r--.  1 root root   50M 10月  8 11:01 gfsrepo.zip
drwxr-xr-x. 38 7161 31415 4.0K 10月  4 16:59 mysql-5.7.20
-rw-r--r--.  1 root root   47M 8月  23 12:26 mysql-boost-5.7.20.tar.gz
drwxrwxr-x.  6 root root  4.0K 11月 20 2019 redis-5.0.7
-rw-r--r--.  1 root root  1.9M 9月  27 14:51 redis-5.0.7.tar.gz
drwxr-xr-x.  2 root root     6 10月 31 2018 rh

[root@client test]#cd /opt
[root@client opt]#ls
containerd  demo3.log  fdisk.sh     mysql-5.7.20               redis-5.0.7.tar.gz
demo1.log   demo4.log  gfsrepo      mysql-boost-5.7.20.tar.gz  rh
demo2.log   demo5.log  gfsrepo.zip  redis-5.0.7
[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

5.4查看文件分布

查看分布式文件分布(node1:/data/sdb1 node2:/data/sdb1)

[root@node1 ~]#ls -lh /data/sdb1
总用量 160M
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo1.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo2.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo3.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo4.log

[root@node2 ~]#ls -lh /data/sdb1
总用量 40M
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo5.log

 

 

查看条带卷文件分布(node1:/data/sdc1 node2:/data/sdc1)

[root@node1 ~]#ls -lh /data/sdc1
总用量 100M
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo1.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo2.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo3.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo4.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo5.log

[root@node2 ~]#ls -lh /data/sdc1
总用量 100M
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo1.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo2.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo3.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo4.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo5.log

查看复制卷文件分布(node3:/data/sdb1 node4:/data/sdb1)

[root@node3 ~]#ls -lh /data/sdb1
总用量 200M
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo1.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo2.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo3.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo4.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo5.log

[root@node4 ~]#ls -lh /data/sdb1
总用量 200M
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo1.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo2.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo3.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo4.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo5.log

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

[root@node1 ~]#ls -lh /data/sdd1
总用量 80M
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo1.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo2.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo3.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo4.log

[root@node2 ~]#ls -lh /data/sdd1
总用量 80M
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo1.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo2.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo3.log
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo4.log

[root@node3 ~]#ls -lh /data/sdd1
总用量 20M
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo5.log

[root@node4 ~]#ls -lh /data/sdd1
总用量 20M
-rw-r--r--. 2 root root 20M 10月 14 14:08 demo5.log

 

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

[root@node1 ~]#ls -lh /data/sde1
总用量 160M
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo1.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo2.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo3.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo4.log

[root@node2 ~]#ls -lh /data/sde1
总用量 160M
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo1.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo2.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo3.log
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo4.log

[root@node3 ~]#ls -lh /data/sde1
总用量 40M
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo5.log

[root@node4 ~]#ls -lh /data/sde1
总用量 40M
-rw-r--r--. 2 root root 40M 10月 14 14:08 demo5.log

5.5冗余测试

当我们宕掉node2机器,在客户端查看文件是否正常

分布式卷数据查看,缺少demo5,不具备冗余

[root@client opt]# ll /test/dis
总用量 204800
-rw-r--r--. 1 root root 41943040 10月 14 14:08 demo1.log
-rw-r--r--. 1 root root 41943040 10月 14 14:08 demo2.log
-rw-r--r--. 1 root root 41943040 10月 14 14:08 demo3.log
-rw-r--r--. 1 root root 41943040 10月 14 14:08 demo4.log
-rw-r--r--. 1 root root 41943040 10月 14 14:08 demo5.log

条带卷,无法访问,不具备冗余

[root@client opt]# ll /test/stripe
总用量 0

复制卷,在node3和node4上,关闭node4进行测试,具有冗余性

[root@client opt]# ll /test/dis-rep/
总用量 204800
-rw-r--r--. 1 root root 41943040 10月 14 14:08 demo1.log
-rw-r--r--. 1 root root 41943040 10月 14 14:08 demo2.log
-rw-r--r--. 1 root root 41943040 10月 14 14:08 demo3.log
-rw-r--r--. 1 root root 41943040 10月 14 14:08 demo4.log
-rw-r--r--. 1 root root 41943040 10月 14 14:08 demo5.log

二、其他维护命令

1.查看GlusterFS卷
gluster volume list 
 
2.查看所有卷的信息
gluster volume info
 
3.查看所有卷的状态
gluster volume status
 
4.停止一个卷
gluster volume stop dis-stripe
 
5.删除一个卷,注意:删除卷时,需要先停止卷,且信任池中不能有主机处于宕机状态,否则删除不成功
gluster volume delete dis-stripe
 
6.设置卷的访问控制
#仅拒绝
gluster volume set dis-rep auth.allow 192.168.187.98
 
#仅允许
gluster volume set dis-rep auth.allow 192.168.187.*
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值