利用glusterfs实现minio异地多活

场景

原本主机房只有一台单节点的minio,应客户要求,需要对minio做异地同步。成本考虑,计划在备用机房再部署一台单节点minio,然后利用glusterfs对minio的数据目录做同步,以实现异地多活的目的

资源规划

节点名称 节点ip 规划
主节点 192.168.3.231 老的minio单节点,配置glusterfs集群
备节点 192.168.4.231 新的minio单节点,配置glusterfs集群

配置glusterfs服务

  • [所有节点] 初始化工作,一定要禁用防火墙,否则 peer probe 会报错 peer probe: failed: Probe returned with Transport endpoint is not connected
#.1.配置dns并安装基础软件
sed -i 's/^nameserver.*/nameserver 223.5.5.5/g' /etc/resolv.conf
cat /etc/resolv.conf | grep "^nameserver" > /dev/null || echo "nameserver 223.5.5.5" > /etc/resolv.conf
yum install -y -q curl wget ntp ntpdate lrzsz telnet zip unzip net-tools

#.2.修改时区并同步时间
timedatectl set-timezone Asia/Shanghai
/usr/sbin/ntpdate -u ntp.aliyun.com

#.3.建议禁用firewalld否则重启后需要iptable -F清除防火墙策略
/usr/sbin/iptables -F
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service

#.4.建议关闭selinux否则会限制服务
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
  • [所有节点] 创建一个配置glusterfs卷的目录,并安装glusterfs服务(先装centos-release-gluster再装glusterfs-server
mkdir -p /data/glusterfs

yum install -y centos-release-gluster
yum install -y glusterfs-server

systemctl start glusterd.service
systemctl enable glusterd.service
  • [主节点] 创建glusterfs集群并添加备用节点
gluster peer status
gluster peer probe 192.168.4.231
gluster peer status
  • [主节点] 主节点创建一个数据卷并启动(务必关闭防火墙否则会失败)
gluster volume create gfs-storage replica 2 transport tcp 192.168.3.231:/data/glusterfs 192.168.4.231:/data/glusterfs force
gluster volume start gfs-storage
gluster volume status gfs-storage
gluster volume info | egrep "(Name|Status|^Brick)"

启动minio单节点

  • [所有节点] 创建一个存储应用数据的目录,并将本机的glusterfs卷挂载到该目录(务必同步时间并重启volume否则会失败)
mkdir -p /mnt/appdata
mount -t glusterfs 127.0.0.1:/gfs-storage /mnt/appdata
df -Th | grep gluster
  • [所有节点] 将minio数据目录配置在挂载的glusterfs卷上,再启动minio单节点
mkdir -p /mnt/appdata/minio/data
curl -L http://iso.sqlfans.cn/linux/minio.2023-06-29 -o /usr/bin/minio
chmod +x /usr/bin/minio

export MINIO_ROOT_USER=minioadmin
export MINIO_ROOT_PASSWORD=minioadmin
nohup /usr/bin/minio server /mnt/appdata/minio/data --console-address=":9100" > /var/log/minio_`date +%Y%m%d%H`.log 2>&1 &
netstat -lnpt | grep 9100

场景演练

测试 minio 同步

  • [主节点] 登录minio控制台,创建bucket并上传测试文件
#.地址:http://192.168.3.231:9100
#.账号:minioadmin
#.密码:minioadmin
  • [备用节点] 登录minio控制台,确认bucket及文件已同步
#.地址:http://192.168.4.231:9100
#.账号:minioadmin
#.密码:minioadmin

演练 glusterfs 故障

  • 第1步,[主节点] 杀掉glusterfs服务,模拟宕机
ps -ef | grep -v grep | grep glusterfs | awk '{print $2}' | xargs kill -9 2> /dev/null
  • 第2步,登录主要节点的minio控制台,发现页面可以打开,但登录失败(因为minio进程仍在,而glusterfs挂载点失效)
  • 第3步,登录备用节点的minio控制台,上传新的测试文件
  • 第4步,启动主节点的glusterfs服务并重新挂载,模拟恢复
systemctl start glusterd.service
mount -t glusterfs 127.0.0.1:/gfs-storage /mnt/appdata

注:若杀掉glusterfs进程并重启服务后执行 ll /mnt/appdata 报错 Transport endpoint is not connected,可尝试 reboot 再重新 mount

  • 第5步,登录主节点的minio控制台,确认新的测试文件已同步

遇到的问题

场景1:启动minio报错 expected format-type: fs, found: xl-single

  • 症状:利用 minio 2022-02-24 版本启动minio报错 expected format-type: fs, found: xl-single
[root@localhost ~]# /opt/minio.2022-02-24 server /mnt/appdata/minio/data --console-address=":9100"
ERROR Unable to initialize backend: format.json file: expected format-type: fs, found: xl-single
  • 解决:启动命令中挂载的目录已经被minio占用了,比如以前启动的minio挂载过,删掉 .minio.sys 这个隐藏目录就好了
[root@localhost ~]# ll -a /mnt/appdata/minio/data/
drwxr-xr-x 7 root root 97 Jul 11 15:52 .minio.sys

[root@localhost ~]# rm -rf /mnt/appdata/minio/data/.minio.sys

[root@localhost ~]# /opt/minio.2022-02-24 server /mnt/appdata/minio/data --console-address=":9100"
Console: http://10.30.4.231:9100 http://172.17.0.1:9100 http://127.0.0.1:9100
RootUser: minioadmin
RootPass: minioadmin

场景2:启动minio提示内核版本过低

  • 症状:利用 minio 2023-06-29 版本启动minio提示 Detected Linux kernel version older than 4.0.0 release
[root@localhost ~]# /opt/minio.2023-06-29 server /mnt/appdata/minio/data --console-address=":9100"
;?WARNING: Detected Linux kernel version older than 4.0.0 release, there are some known potential performance problems with this kernel version. MinIO recommends a minimum of 4.x.x linux kernel version for best performance
ERROR Unable to use the drive /mnt/appdata/minio/data: Drive /mnt/appdata/minio/data: found backend type fs, expected xl or xl-single - to migrate to a supported backend visit https://min.io/docs/minio/linux/operations/install-deploy-manage/migrate-fs-gateway.html: Invalid arguments specified
  • 解决:CentOS 7.9 的内核版本默认为 3.10.0,将内核版本需要升级到5.4.240,即可解决。
[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

[root@localhost ~]# uname -rs
Linux 3.10.0-1160.el7.x86_64

场景3:启动minio报错 Unable to initialize config system

  • 症状:利用 minio 2023-06-29 版本挂载glusterfs目录(示例 /mnt/appdata分区格式为fuse.glusterfs)并启动minio报错 ERROR Unable to initialize backend: format.json file: expected format-type: fs, found: xl-single,而挂载本地目录则正常(示例 /data/appdata分区格式为xfs),详细如下:
[root@localhost ~]# df -Th
Filesystem              Type            Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs              36G   18G   18G  52% /
127.0.0.1:/gfs-storage  fuse.glusterfs   36G   19G   17G  53% /mnt/appdata

[root@localhost ~]# /opt/minio.2023-06-29 server /data/appdata/minio/data --console-address=":9100"
Console: http://10.30.4.231:9100 http://172.17.0.1:9100 http://127.0.0.1:9100
RootUser: minioadmin
RootPass: minioadmin

[root@localhost ~]# rm -rf /mnt/appdata/minio/data/.minio.sys
[root@localhost ~]# /opt/minio.2023-06-29 server /mnt/appdata/minio/data --console-address=":9100"

API: SYSTEM()
Time: 08:29:33 UTC 07/11/2023
DeploymentID: 5db66c9a-60a4-4b9e-8cce-7bc188b1273c
Error: invalid argument (syscall.Errno)
       6: internal/logger/logger.go:258:logger.LogIf()
       5: cmd/storage-errors.go:165:cmd.osErrToFileErr()
       4: cmd/xl-storage.go:2423:cmd.(*xlStorage).RenameData()
       3: cmd/xl-storage-disk-id-check.go:380:cmd.(*xlStorageDiskIDCheck).RenameData()
       2: cmd/erasure-object.go:797:cmd.renameData.func1()
       1: github.com/minio/pkg@v1.7.5/sync/errgroup/errgroup.go:123:errgroup.(*Group).Go.func1()
Waiting for all MinIO sub-systems to be initialized.. possible cause (Unable to initialize config system: Storage resources are insufficient for the write operation .minio.sys/config/config.json)
  • 解决:经过对不同版本的minio测试发现,自 minio.2022-09-01 开始,minio 不再支持glusterfs挂载的分区目录
  • 更新:2023.09.04 测试发现 minio.2023-08-31 版本又支持glusterfs挂载的分区目录
[root@localhost ~]# rm -rf /mnt/appdata/minio/data/.minio.sys
[root@localhost ~]# /opt/minio.2022-08-26 server /mnt/appdata/minio/data --console-address=":9100"
Console: http://10.30.4.231:9100 http://172.17.0.1:9100 http://127.0.0.1:9100
RootUser: minioadmin
RootPass: minioadmin

[root@localhost ~]# rm -rf /mnt/appdata/minio/data/.minio.sys
[root@localhost ~]# /opt/minio.2022-09-01 server /mnt/appdata/minio/data --console-address=":9100"

API: SYSTEM()
......
Waiting for all MinIO sub-systems to be initialized.. possible cause (Unable to initialize config system: Storage resources are insufficient for the write operation .minio.sys/config/config.json)
Copyright © www.sqlfans.cn 2023 All Right Reserved更新时间: 2023-09-22 15:07:56

results matching ""

    No results matching ""