当前位置:   article > 正文

云原生|对象存储|minio分布式集群的搭建和初步使用(可用于生产)_minio部署

minio部署

前言:

minio作为轻量级的对象存储服务安装还是比较简单的,但分布式集群可以大大提高存储的安全性,可靠性。分布式集群是在单实例的基础上扩展而来的

minio的分布式集群有如下要求:

  • 所有运行分布式 MinIO 的节点需要具有相同的访问密钥和秘密密钥才能连接。建议在执行 MINIO 服务器命令之前,将访问密钥作为环境变量,MINIO access key 和 MINIO secret key 导出到所有节点上 。
  • Minio 创建4到16个驱动器的擦除编码集。
  • Minio 选择最大的 EC 集大小,该集大小除以给定的驱动器总数。 例如,8个驱动器将用作一个大小为8的 EC 集,而不是两个大小为4的 EC 集 。
  • 建议所有运行分布式 MinIO 设置的节点都是同构的,即相同的操作系统、相同数量的磁盘和相同的网络互连 。
  • 运行分布式 MinIO 实例的服务器时间差不应超过15分钟。

单实例部署可以见我原来写的博文:Linux|minio对象存储服务的部署和初步使用总结_linux部署minio-CSDN博客

首先,minio的安装部署方式很多,可以使用docker,二进制,rpm 亦或者集成部署在kubernetes内,综合各种部署方式的优劣,本文选择rpm安装部署,该方式其实和二进制没什么太大区别,但足够简单,省去了很多麻烦。

其次就是minio的drive问题,minio要求ta使用的存储空间也就是drive必须是一个空的,单独挂载的磁盘,那么,有时候根据我们的使用目的,比如,我仅仅需要velero这个工具通过minio来存储kubernetes的备份文件,那么,对存储空间的要求就没有那么高了,因此,本文采用的是虚拟磁盘的挂载技术

最后,就是minio的console-address的问题,每一个minio单实例都集成有console,也就是web控制台,该控制台配置文件里不显式写也会启动,但端口是随机的,如果你需要更安全,那么,建议不写console,让ta自动分配随机端口,需要使用console的时候,通过日志来查询后使用

本次实践是使用的VMware虚拟机,VMware虚拟机服务器总计四台,IP分别是192.168.123.11,192.168.123.12,192.168.123.13,192.168.123.14,操作系统是centos-7.7,minio的版本为minio-20230413030807.0.0.x86_64

一,

minio集群的环境初始化

这些都是老生常谈的问题,就不在此详细说明了,防火墙关闭,selinux关闭,时间服务器,本集群无需内部域名映射

内核优化(每个节点都执行):

  1. cat > /etc/sysctl.d/minio.conf <<EOF
  2. # maximum number of open files/file descriptors
  3. fs.file-max = 4194303
  4. # use as little swap space as possible
  5. vm.swappiness = 1
  6. # prioritize application RAM against disk/swap cache
  7. vm.vfs_cache_pressure = 50
  8. # minimum free memory
  9. vm.min_free_kbytes = 1000000
  10. # follow mellanox best practices https://community.mellanox.com/s/article/linux-sysctl-tuning
  11. # the following changes are recommended for improving IPv4 traffic performance by Mellanox
  12. # disable the TCP timestamps option for better CPU utilization
  13. net.ipv4.tcp_timestamps = 0
  14. # enable the TCP selective acks option for better throughput
  15. net.ipv4.tcp_sack = 1
  16. # increase the maximum length of processor input queues
  17. net.core.netdev_max_backlog = 250000
  18. # increase the TCP maximum and default buffer sizes using setsockopt()
  19. net.core.rmem_max = 4194304
  20. net.core.wmem_max = 4194304
  21. net.core.rmem_default = 4194304
  22. net.core.wmem_default = 4194304
  23. net.core.optmem_max = 4194304
  24. # increase memory thresholds to prevent packet dropping:
  25. net.ipv4.tcp_rmem = 4096 87380 4194304
  26. net.ipv4.tcp_wmem = 4096 65536 4194304
  27. # enable low latency mode for TCP:
  28. net.ipv4.tcp_low_latency = 1
  29. # the following variable is used to tell the kernel how much of the socket buffer
  30. # space should be used for TCP window size, and how much to save for an application
  31. # buffer. A value of 1 means the socket buffer will be divided evenly between.
  32. # TCP windows size and application.
  33. net.ipv4.tcp_adv_win_scale = 1
  34. # maximum number of incoming connections
  35. net.core.somaxconn = 65535
  36. # maximum number of packets queued
  37. net.core.netdev_max_backlog = 10000
  38. # queue length of completely established sockets waiting for accept
  39. net.ipv4.tcp_max_syn_backlog = 4096
  40. # time to wait (seconds) for FIN packet
  41. net.ipv4.tcp_fin_timeout = 15
  42. # disable icmp send redirects
  43. net.ipv4.conf.all.send_redirects = 0
  44. # disable icmp accept redirect
  45. net.ipv4.conf.all.accept_redirects = 0
  46. # drop packets with LSR or SSR
  47. net.ipv4.conf.all.accept_source_route = 0
  48. # MTU discovery, only enable when ICMP blackhole detected
  49. net.ipv4.tcp_mtu_probing = 1
  50. EOF
  51. sysctl -p /etc/sysctl.d/minio.conf
  52. # `Transparent Hugepage Support`*: This is a Linux kernel feature intended to improve
  53. # performance by making more efficient use of processor’s memory-mapping hardware.
  54. # But this may cause https://blogs.oracle.com/linux/performance-issues-with-transparent-huge-pages-thp
  55. # for non-optimized applications. As most Linux distributions set it to `enabled=always` by default,
  56. # we recommend changing this to `enabled=madvise`. This will allow applications optimized
  57. # for transparent hugepages to obtain the performance benefits, while preventing the
  58. # associated problems otherwise. Also, set `transparent_hugepage=madvise` on your kernel
  59. # command line (e.g. in /etc/default/grub) to persistently set this value.
  60. echo "Enabling THP madvise"
  61. echo madvise | sudo tee /sys/kernel/mm/transparent_hugepage/enabled

二,

minio集群的drive创建

每个节点都执行,这里是每个虚拟磁盘1G,分别挂载到/data1目录下的,如果是生产环境,建议 vim /etc/fstab 固化挂载

使用的普通用户minio-user 设置不可登陆,并赋予相关目录该用户的属组

  1. mkdir -p /data1/minio{1..4}
  2. groupadd -r minio-user
  3. useradd -M -r -g minio-user minio-user
  4. chown -Rf minio-user. /data1/
  5. dd if=/dev/zero of=/media/testfile1 bs=200M count=5
  6. dd if=/dev/zero of=/media/testfile2 bs=200M count=5
  7. dd if=/dev/zero of=/media/testfile3 bs=200M count=5
  8. dd if=/dev/zero of=/media/testfile4 bs=200M count=5
  9. mkfs.xfs /media/testfile1
  10. mkfs.xfs /media/testfile2
  11. mkfs.xfs /media/testfile3
  12. mkfs.xfs /media/testfile4
  13. mount -t xfs /media/testfile1 /data1/minio1/
  14. mount -t xfs /media/testfile2 /data1/minio2/
  15. mount -t xfs /media/testfile3 /data1/minio3/
  16. mount -t xfs /media/testfile4 /data1/minio4/

固化挂载: 

  1. tail -f /etc/fstab
  2. /media/testfile1 /data1/minio1/ xfs defaults 0 0
  3. /media/testfile2 /data1/minio2/ xfs defaults 0 0
  4. /media/testfile3 /data1/minio3/ xfs defaults 0 0
  5. /media/testfile4 /data1/minio4/ xfs defaults 0 0
  1. [root@node1 ~]# df -ah
  2. Filesystem Size Used Avail Use% Mounted on
  3. sysfs 0 0 0 - /sys
  4. proc 0 0 0 - /proc
  5. devtmpfs 2.0G 0 2.0G 0% /dev
  6. securityfs 0 0 0 - /sys/kernel/security
  7. tmpfs 2.0G 52K 2.0G 1% /dev/shm
  8. devpts 0 0 0 - /dev/pts
  9. tmpfs 2.0G 68M 1.9G 4% /run
  10. tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
  11. 。。。。略略略。。。
  12. /dev/loop0 997M 99M 899M 10% /data1/minio1
  13. /dev/loop1 997M 99M 899M 10% /data1/minio2
  14. /dev/loop2 997M 99M 899M 10% /data1/minio3
  15. /dev/loop3 997M 99M 899M 10% /data1/minio4

三,

正式安装部署minio

每个节点都执行:

rpm -ivh minio-20230413030807.0.0.x86_64.rpm

安装完毕后,查看minio的启动脚本:

  1. [root@node1 ~]# cat /etc/systemd/system/minio.service
  2. [Unit]
  3. Description=MinIO
  4. Documentation=https://docs.min.io
  5. Wants=network-online.target
  6. After=network-online.target
  7. AssertFileIsExecutable=/usr/local/bin/minio
  8. [Service]
  9. WorkingDirectory=/usr/local
  10. User=minio-user
  11. Group=minio-user
  12. ProtectProc=invisible
  13. EnvironmentFile=-/etc/default/minio
  14. ExecStartPre=/bin/bash -c "if [ -z \"${MINIO_VOLUMES}\" ]; then echo \"Variable MINIO_VOLUMES not set in /etc/default/minio\"; exit 1; fi"
  15. ExecStart=/usr/local/bin/minio server $MINIO_OPTS $MINIO_VOLUMES
  16. # Let systemd restart this service always
  17. Restart=always
  18. # Specifies the maximum file descriptor number that can be opened by this process
  19. LimitNOFILE=1048576
  20. # Specifies the maximum number of threads this process can create
  21. TasksMax=infinity
  22. # Disable timeout logic and wait until process is stopped
  23. TimeoutStopSec=infinity
  24. SendSIGKILL=no
  25. [Install]
  26. WantedBy=multi-user.target
  27. # Built for ${project.name}-${project.version} (${project.name})

观察该脚本,发现用户这方面我们已经设置好了,前面创建了用户,现在是两个关键变量$MINIO_OPTS $MINIO_VOLUMES 以及存放变量的文件/etc/default/minio

可以看到,刚安装完毕是没有这个文件的,需要我们自己创建(每个节点都一样的):

  1. cat >/etc/default/minio <<EOF
  2. # Set the hosts and volumes MinIO uses at startup
  3. # The command uses MinIO expansion notation {x...y} to denote a
  4. # sequential series.
  5. #
  6. # The following example covers four MinIO hosts
  7. # with 4 drives each at the specified hostname and drive locations.
  8. # The command includes the port that each MinIO server listens on
  9. # (default 9000)
  10. ## 这块是文件磁盘的位置 因为我们是集群节点是163-166 这边是一种池化写法
  11. MINIO_VOLUMES="http://192.168.123.{11...14}:39111/data1/minio{1...4}"
  12. # Set all MinIO server options
  13. #
  14. # The following explicitly sets the MinIO Console listen address to
  15. # port 9001 on all network interfaces. The default behavior is dynamic
  16. # port selection.
  17. ## minio-console的地址 就是web界面控制台
  18. MINIO_OPTS="--address :39111 --console-address :39112"
  19. # Set the root username. This user has unrestricted permissions to
  20. # perform S3 and administrative API operations on any resource in the
  21. # deployment.
  22. #
  23. # Defer to your organizations requirements for superadmin user name.
  24. # console的登陆账号
  25. MINIO_ROOT_USER=minioadmin
  26. # Set the root password
  27. #
  28. # Use a long, random, unique string that meets your organizations
  29. # requirements for passwords.
  30. # console的登陆密码
  31. MINIO_ROOT_PASSWORD=minioadmin
  32. EOF

该配置文件的说明:

  1. MINIO_VOLUMES="http://192.168.123.{11...14}:39111/data1/minio{1...4}"
  2. 可以拆开写成 MINIO_VOLUMES="http://192.168.123.11:39111/data1/minio{1...4} http://192.168.123.12:39111/data1/minio{1...4} http://192.168.123.13:39111/data1/minio{1...4}
  3. http://192.168.123.14:39111/data1/minio{1...4}"
  4. 因为,四个VMware服务器IP是连续的,所以可以写成上面的简略形式,下面的拆开写法也是OK的
  1. MINIO_OPTS="--address :39111 --console-address :39112"
  2. 可以改成MINIO_OPTS="--address :39111 " ,修改为这种形式的时候,minio启动的时候console就会使用随机端口,minio server的服务端口是39111,默认是9000,建议修改端口以提高服务的安全性
  1. MINIO_ROOT_USER=minioadmin
  2. MINIO_ROOT_PASSWORD=minioadmin
  3. 这两个是minio服务的web登录账号密码,实际生产中建议设置密码复杂一些

最后还需要给该文件赋权:

chown -Rf minio-user. /etc/default/minio

四,

启动minio服务

  1. systemctl enable minio
  2. systemctl start minio
  3. systemctl status minio

最后一个命令输出如下,表示服务正常:

  1. Dec 28 23:45:57 node1 minio[23188]: MinIO Object Storage Server
  2. Dec 28 23:45:57 node1 minio[23188]: Copyright: 2015-2023 MinIO, Inc.
  3. Dec 28 23:45:57 node1 minio[23188]: License: GNU AGPLv3 <https://www.gnu.org/licenses/agpl-3.0.html>
  4. Dec 28 23:45:57 node1 minio[23188]: Version: RELEASE.2023-04-13T03-08-07Z (go1.20.3 linux/amd64)
  5. Dec 28 23:45:57 node1 minio[23188]: Status: 16 Online, 0 Offline.
  6. Dec 28 23:45:57 node1 minio[23188]: API: http://10.96.24.248:39111 http://192.168.123.11:39111 http://169.254.25.10:39111 http://10.96.0.3:39111 http://10.96.0.1:39111 http://172.17.0.1:39111 http://10.244.26.0:39111 http://127.0.0.1:39111
  7. Dec 28 23:45:57 node1 minio[23188]: Console: http://10.96.24.248:43585 http://192.168.123.11:43585 http://169.254.25.10:43585 http://10.96.0.3:43585 http://10.96.0.1:43585 http://172.17.0.1:43585 http://10.244.26.0:43585 http://127.0.0.1:43585
  8. Dec 28 23:45:57 node1 minio[23188]: Documentation: https://min.io/docs/minio/linux/index.html
  9. Dec 28 23:45:58 node1 minio[23188]: You are running an older version of MinIO released 8 months ago
  10. Dec 28 23:45:58 node1 minio[23188]: Update: Run `mc admin update`

关键字段是Dec 28 23:45:57 node1 minio[23188]: Status:         16 Online, 0 Offline. 这个表示drive全部被发现

最下面有一个警告,说的是minio版本有点低,可以忽略,You are running an older version of MinIO released 8 months ago

还有一个警告找不到了,不过也是无所谓,那个警告大体意思是操作系统内核太低,建议内核版本4以上,minio的性能会更好一点。

目前的内核版本:

  1. [root@node4 ~]# uname -a
  2. Linux node4 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

console也就是web管理界面的端口:

Console: http://10.96.24.248:35382 http://192.168.123.14:35382 http://169.254.25.10:35382 http://10.96.0.3:35382 http://10.96.0.1:35382 http://172.17.0.1:35382 http://10.244.41.0:35382 http://127.0.0.1:35382

很明显是  http://192.168.123.14:35382   其它的IP可能由于是minio和kubernetes运行在一起了吧,忽略掉就可以了

登录web管理界面:

 创建桶(我已经创建过了,叫test)

monitoring 可以看到有使用多少磁盘 

 传一个大文件上去:

传输速度还是比较快的,比ftp什么的快多了

 在看看磁盘使用空间:

可以看到,一个800多M的文件被minio打散了分布存储到了各个节点上了

下载文件:

可以看到,下载是先从minio server上各个节点收集文件在下载的

五,

测试高可用

192.168.123.14节点关机

仍然可以正常下载 上传文件:

 

查看服务状态:

  1. [root@node1 ~]# systemctl status minio
  2. ● minio.service - MinIO
  3. Loaded: loaded (/etc/systemd/system/minio.service; enabled; vendor preset: disabled)
  4. Active: active (running) since Fri 2023-12-29 18:53:31 CST; 7h ago
  5. Docs: https://docs.min.io
  6. Process: 15886 ExecStartPre=/bin/bash -c if [ -z "${MINIO_VOLUMES}" ]; then echo "Variable MINIO_VOLUMES not set in /etc/default/minio"; exit 1; fi (code=exited, status=0/SUCCESS)
  7. Main PID: 15889 (minio)
  8. Tasks: 15
  9. Memory: 144.9M
  10. CGroup: /system.slice/minio.service
  11. └─15889 /usr/local/bin/minio server --address :39111 --console-address :39112 http://192.168.123.{11...14}:39111/data1/minio{1...4}
  12. Dec 30 01:59:23 node1 minio[15889]: API: SYSTEM()
  13. Dec 30 01:59:23 node1 minio[15889]: Time: 17:59:23 UTC 12/29/2023
  14. Dec 30 01:59:23 node1 minio[15889]: DeploymentID: 5e75dcd3-d3de-4a08-bdee-3197016ceded
  15. Dec 30 01:59:23 node1 minio[15889]: Error: Marking 192.168.123.14:39111 offline temporarily; caused by Post "http://192.168.123.14:39111/minio/peer/v30/log": dial tcp 192.168.123.14:39111: connect: no route to host (*fmt.wrapError)
  16. Dec 30 01:59:23 node1 minio[15889]: 6: internal/logger/logonce.go:118:logger.(*logOnceType).logOnceIf()
  17. Dec 30 01:59:23 node1 minio[15889]: 5: internal/logger/logonce.go:149:logger.LogOnceIf()
  18. Dec 30 01:59:23 node1 minio[15889]: 4: internal/rest/client.go:259:rest.(*Client).Call()
  19. Dec 30 01:59:23 node1 minio[15889]: 3: cmd/peer-rest-client.go:68:cmd.(*peerRESTClient).callWithContext()
  20. Dec 30 01:59:23 node1 minio[15889]: 2: cmd/peer-rest-client.go:710:cmd.(*peerRESTClient).doConsoleLog()
  21. Dec 30 01:59:23 node1 minio[15889]: 1: cmd/peer-rest-client.go:734:cmd.(*peerRESTClient).ConsoleLog.func1()

 在关闭一个节点,上传不了了,也下载不了任何文件了,只能看看:

 两个关闭的节点在开启,很快的啊,啪  的一下 就恢复了:

下载和上传功能完全恢复,很快的,就不演示了, 在看服务状态就没什么报错了:

  1. [root@node1 ~]# systemctl status minio
  2. ● minio.service - MinIO
  3. Loaded: loaded (/etc/systemd/system/minio.service; enabled; vendor preset: disabled)
  4. Active: active (running) since Sat 2023-12-30 02:37:20 CST; 1s ago
  5. Docs: https://docs.min.io
  6. Process: 64997 ExecStartPre=/bin/bash -c if [ -z "${MINIO_VOLUMES}" ]; then echo "Variable MINIO_VOLUMES not set in /etc/default/minio"; exit 1; fi (code=exited, status=0/SUCCESS)
  7. Main PID: 64999 (minio)
  8. Tasks: 11
  9. Memory: 143.1M
  10. CGroup: /system.slice/minio.service
  11. └─64999 /usr/local/bin/minio server --address :39111 --console-address :39112 http://192.168.123.{11...14}:39111/data1/minio{1...4}
  12. Dec 30 02:37:20 node1 minio[64999]: Copyright: 2015-2023 MinIO, Inc.
  13. Dec 30 02:37:20 node1 minio[64999]: License: GNU AGPLv3 <https://www.gnu.org/licenses/agpl-3.0.html>
  14. Dec 30 02:37:20 node1 minio[64999]: Version: RELEASE.2023-04-13T03-08-07Z (go1.20.3 linux/amd64)
  15. Dec 30 02:37:20 node1 minio[64999]: Use `mc admin info` to look for latest server/drive info
  16. Dec 30 02:37:20 node1 minio[64999]: Status: 15 Online, 1 Offline.
  17. Dec 30 02:37:20 node1 minio[64999]: API: http://10.96.24.248:39111 http://192.168.123.11:39111 http://169.254.25.10:39111 http://10.96.0.3:39111 http://10.96.0.1:39111 http://172.17.0.1:39111 http://10.244.26.0:39111 http://127.0.0.1:39111
  18. Dec 30 02:37:20 node1 minio[64999]: Console: http://10.96.24.248:39112 http://192.168.123.11:39112 http://169.254.25.10:39112 http://10.96.0.3:39112 http://10.96.0.1:39112 http://172.17.0.1:39112 http://10.244.26.0:39112 http://127.0.0.1:39112
  19. Dec 30 02:37:20 node1 minio[64999]: Documentation: https://min.io/docs/minio/linux/index.html
  20. Dec 30 02:37:21 node1 minio[64999]: You are running an older version of MinIO released 8 months ago

总结:

minio可以作为网盘使用,但一般是与其它组件联合使用,例如,kubernetes集群内部使用,kafka,redis等等,根据实际需求持久化数据,minio自带有比较完整的权限系统,安全性还是有一定保障的。

本例中,1个节点关闭或者损坏不影响minio集群的使用,2个节点关闭或者损坏将只能读存储,不可以上传或者下载了,也就是只能看看

minio是去中心化的,也就是没有什么主从之分的,因此可以使用nginx做负载均衡:

  1. upstream minio_servers {
  2. server 192.168.123.11:39111;
  3. server 192.168.123.12:39111;
  4. server 192.168.123.13:39111;
  5. server 192.168.123.14:39111;
  6. }
  7. server {
  8. listen 80;
  9. server_name 192.168.123.11;
  10. # To allow special characters in headers
  11. ignore_invalid_headers off;
  12. # Allow any size file to be uploaded.
  13. # Set to a value such as 1000m; to restrict file size to a specific value
  14. client_max_body_size 0;
  15. # To disable buffering
  16. proxy_buffering off;
  17. location / {
  18. proxy_set_header X-Real-IP $remote_addr;
  19. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  20. proxy_set_header X-Forwarded-Proto $scheme;
  21. proxy_set_header Host $http_host;
  22. proxy_connect_timeout 300;
  23. # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
  24. proxy_http_version 1.1;
  25. proxy_set_header Connection "";
  26. chunked_transfer_encoding off;
  27. proxy_pass http://minio_servers; # If you are using docker-compose this would be the hostname i.e. minio
  28. # Health Check endpoint might go here. See https://www.nginx.com/resources/wiki/modules/healthcheck/
  29. # /minio/health/live;
  30. }
  31. access_log /var/log/nginx/minio_access.log custom_sls_log;
  32. error_log /var/log/nginx/minio.error.log;
  33. }

当然了,如果console显式的配置了端口并且是统一的端口,那么,也可以放nginx里负载均衡,和上面基本一样的配置,就不演示了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/577350
推荐阅读
相关标签
  

闽ICP备14008679号