GlusterFS安装部署

一、安装

1、配置yum源

操作系统是centos7.9版本
1.1 配置163yum源

http://mirrors.163.com/.help/CentOS7-Base-163.repo

1.2 配置存储yum源

# yum install centos-release-gluster

地址为:

https://wiki.centos.org/SpecialInterestGroup/Storage

2、安装glusterFs

2.1 安装

# yum clean all
# yum makecache
# yum install glusterfs-server

当然具体使用,可以查看官网,地址如下:

https://docs.gluster.org/en/latest/Quick-Start-Guide/Quickstart/

2.2 只下载
对于内网环境的服务器来说,需要从外面把包下载下来上传到服务器。

# mkdir /tmp/gluster
# yum install  --downloadonly --downloaddir=/tmp/gluster  glusterfs-server

需要保证服务器上面没有安装这个软件包,下载的软件包就存放在/tmp/gluster目录下。

第二种方式也可以使用yum的缓存,把下载的包缓存下来,然后上传到服务器

二、配置

1、优化配置

这个不用配置,这里只是学习为了记录这个命令使用。
使用红帽提供的tuned-adm命令

# tuned-adm list
# tuned-adm profile virtual-guest // virtual-guest就是默认值

2、防火墙配置

如果开启了firewall

# firewall-cmd --permanent --add-service=glusterfs
# firewall-cmd  --reload
# cat /usr/lib/firewalld/services/glusterfs.xml // 查看开启的规则信息

三、集群搭建

3.1 节点分布

这里使用两台节点测试,两台都要安装glusterfs

主机 ip
Hadoop4 192.168.1.15
k8s-node2 192.168.1.16

3.2 节点加入集群

hadoop4节点执行

# gluster peer probe k8s-node2
[root@hadoop4 ~]# gluster peer status
Number of Peers: 1

Hostname: k8s-node2
Uuid: c4cedd4f-b101-4bbe-925e-4fde98202286
State: Peer in Cluster (Connected)

查看pool 列表

[root@hadoop4 ~]# gluster pool list
UUID					Hostname 	State
c4cedd4f-b101-4bbe-925e-4fde98202286	k8s-node2	Connected 
bce7edd7-eb96-49d8-a43b-e7d1d396cf97	localhost	Connected

一个是本机,一个是k8s-node2节点

四、配置lv

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

1、 创建pv

pvcreate /dev/sdb

2、创建pv

# vgcreate yjt /dev/sdb
[root@k8s-node2 ~]# vgs
  VG  #PV #LV #SN Attr   VSize  VFree 
  yjt   1   0   0 wz--n- 20.00g 20.00g

3、创建thin

lvcreate -L 10G  -T yjt/yjt-thin-pool

-T: 表示创建的是thin pool

4、创建lv

# lvcreate -V 2G -T yjt/yjt-thin-pool -n yjt-brick

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

5、磁盘格式化

# mkfs.xfs -i size=512 /dev/yjt/yjt-brick

6、挂载

[root@hadoop4 ~]# mkdir /data/brick1 -p
[root@hadoop4 ~]# mount /dev/yjt/yjt-brick /data/brick1
[root@hadoop4 ~]# echo '/dev/yjt/yjt-brick /data/brick1 xfs defaults 1 2' >> /etc/fstab

7、设置selinux
如果selinux关闭的话,这个可以不用设置

# semanage fcontext  -a -t glusterd_brick_t /data1/brick1
# restorecon -Rv /data/
# # ll -Z /data

以上操作在两个节点都要操作。

五、使用

5.1 创建分布式卷

1、创建分布式卷

[root@hadoop4 ~]# gluster volume create gv0 hadoop4:/data/brick1/brick k8s-node2:/data/brick1/brick
volume create: gv0: success: please start the volume to access data

这种默认创建出来的就是分布式卷
2、查看卷状态

# gluster volume info gv0 
 
Volume Name: gv0
Type: Distribute
Volume ID: 3a5a7c88-d4d3-4d0c-94c5-b95963c7a0fa
Status: Created
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: hadoop4:/data/brick1/brick
Brick2: k8s-node2:/data/brick1/brick
Options Reconfigured:
storage.fips-mode-rchecksum: on
transport.address-family: inet
nfs.disable: on

默认的状态是Create,需要启动
3、启动volume

[root@hadoop4 ~]# gluster volume start gv0 
volume start: gv0: success

查看状态

# gluster volume status gv0 
Status of volume: gv0
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick hadoop4:/data/brick1/brick            49152     0          Y       4587 
Brick k8s-node2:/data/brick1/brick          49152     0          Y       3633 
 
Task Status of Volume gv0
------------------------------------------------------------------------------
There are no active volume tasks

六、客户端挂载使用

1、安装包

# yum install glusterfs-fuse -y

这里就把k8s-node2当客户端使用了

2、挂载

# mkdir /gluster_client
# mount -t glusterfs hadoop4:/gv0 /gluster_client

写fstab

# echo 'hadoop4:/gv0 /gluster_client glusterfs defaults,_netdev,backup-volfile-servers=k8s-node2 1 2' >> /etc/fstab

3、写文件

[root@k8s-node2 glusterfs]# for i in `seq -w 1 100`; do cp -rp /var/log/messages /gluster_client/copy-test-$i; done

检查

# ls -lA /gluster_client/copy* | wc -l
100

查看对应节点上面的brick下面的数据文件

[root@k8s-node2 glusterfs]# ls -lA /data/brick1/brick/copy* | wc -l
50

七、删除分布式卷

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

官网:

https://docs.gluster.org/en/latest/Quick-Start-Guide/Quickstart/

记录学习和生活的酸甜苦辣.....哈哈哈
原文地址:https://www.cnblogs.com/yjt1993/p/14771486.html