GlusterFS部署

发布时间:2022-07-04 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了GlusterFS部署脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

目录
  • 硬件、环境介绍
  • 安装
  • 配置LV
  • 创建分布式卷
  • 客户端挂载使用
该文档是纯GlusterFS,而非红帽的GlusterFS,需注意!!! 声明:如需在单个节点上执行的都会有用户和主机名,如没有命令前没有用户名和主机名则为所有节点都执行 wiki 官网

硬件、环境介绍

node1/CentOS7.9/192.168.1.111/桥接/2G/2核/80G、20G
node2/CentOS7.9/192.168.1.112/桥接/2G/2核/80G、20G

注:2台机上的20G用来做GlusterFS使用

安装

2台机上都需要安装glusterfs,这里使用centos的

Systemctl stop firewalld && systemctl disable firewalld
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
setenforce 0
mount /dev/sr0 /mnt/usb1        ===>该步按需

yum -y install centos-release-gluster
yum clean all && yum makecache
yum -y install glusterfs-server

systemctl start glusterd && systemctl enable glusterd
glusterd --version

cat /usr/lib/firewalld/services/glusterfs.XMl     ===> 查看开启的规则信息

[root@node1 ~]# vim /etc/hosts
192.168.1.111   node1
192.168.1.112   node2

# 将node2添加到gluster中
[root@node1 ~]# gluster PEer PRobe node2
[root@node1 ~]# gluster peer status
Number of Peers: 1

Hostname: node2
Uuid: 2543bce7-bb6a-4974-ad54-67d3d3f2d72d
State: Peer in Cluster (Connected)

# 查看池中的主机
[root@node1 ~]# gluster pool list
UUID					Hostname 	State
2543bce7-bb6a-4974-ad54-67d3d3f2d72d	node2    	Connected 
6b5efcf3-e34f-4fac-87bc-fda1ae6e4189	localhost	Connected 

配置LV

两个节点都在本地虚拟机先添加一块磁盘,用于当作存储,两个节点都要操作如下命令

# 创建pv
pvcreate /dev/sdb
vgcreate opop /dev/sdb

# 创建thin
lvcreate -L 5G  -t opop/opop-thin-pool
注:-T表示创建的是thin pool

# 创建lv
lvcreate -V 2G -T opop/opop-thin-pool  -n  opop-brick

而后可用lvdisplay查看详细信息。
其实上述这些操作都可以不用做,直接对磁盘进行格式化就行。

mkfs.xfs -i size=512 /dev/opop/opop-brick

# 挂载
mkdir -p /data/brick1
mount /dev/opop/opop-brick /data/brick1
echo '/dev/opop/opop-brick /data/brick1  xfs defaults  1  2' >> /etc/fstab

注:已经被设置为共享卷的文件夹是不能再被挂载

DF -h | grep data
/dev/mapper/opop-opop--brick  2.0G   33M  2.0G    2% /data/brick1


===================
如果selinux关闭的话,这个可不设置
# SEManage fcontext  -a -t glusterd_brick_t /data1/brick1
# reStorecon -Rv /data/
# ll -Z /data
===================

创建分布式卷

这种默认创建出来的就是分布式卷

[root@node1 ~]# gluster volume create gv0 node1:/data/brick1/brick node2:/data/brick1/brick


[root@node1 ~]# gluster volume info gv0 
 
Volume Name: gv0
Type: Distribute
Volume ID: 1b19e7ff-4608-4576-ab4f-fe8ef764102e
Status: Created                ====>默认的状态是Create,需要启动
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/data/brick1/brick
Brick2: node2:/data/brick1/brick
Options Reconfigured:
storage.fips-mode-rchecksum: on
transport.address-family: inet
nfs.disable: on


# 启动volume
gluster volume start gv0 
# 查看状态
gluster volume status gv0

客户端挂载使用

这里就把node2当客户端来使用
[root@node2 ~]# yum -y install glusterfs-fuse

# 挂载
[root@node2 ~]# mkdir /gluster_client
[root@node2 ~]# mount -t glusterfs node1:/gv0  /gluster_client
[root@node2 ~]# echo 'node1:/gv0 /gluster_client  glusterfs  defaults,_netdev,backup-volfile-servers=node2 1 2' >> /etc/fstab

# 写文件
[root@node2 ~]# for i in `seq -w 1 100`; do cp -rp /VAR/LOG/messages /gluster_client/copy-test-$i; done

[root@node2 ~]# ls -lA /gluster_client/copy* | wc -l

# 查看客户端节点上面的brick下面的数据文件
[root@node2 ~]# ll -lA /data/brick1/brick/copy-test-0* | wc -l

# 删除分布式卷
# umount /gluster_client/
# gluster volume stop gv0 // 停止卷
# gluster volume delete gv0 // 删除卷

脚本宝典总结

以上是脚本宝典为你收集整理的GlusterFS部署全部内容,希望文章能够帮你解决GlusterFS部署所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。