深入实践:MinIO配置与使用
在数字化时代,数据存储与管理变得尤为重要,尤其是对于非结构化数据如日志文件的处理。MinIO,作为一个高性能、可扩展的分布式对象存储系统,以其对Amazon S3的全面兼容性和轻量级设计,成为了众多企业和开发者存储大量数据的首选。本文将带你深入了解MinIO的配置方法
部署MinIO
集群节点规划
节点信息 | 服务 | 数据盘 |
---|---|---|
192.168.1.10 | minio server | /data/minio_data/{data1,data2} |
192.168.1.11 | minio server | /data/minio_data/{data1,data2} |
192.168.1.12 | minio server | /data/minio_data/{data1,data2} |
192.168.1.13 | minio server | /data/minio_data/{data1,data2} |
192.168.1.14 | nginx |
依赖:Ansible,docker,nginx,具体参考资料在文末
集群基础环境准备
创建minio节点 配置文件minio.hosts
代码语言:shell复制[minio]
192.168.1.10
192.168.1.11
192.168.1.12
192.168.1.13
初始化环境
关闭防火墙
代码语言:shell复制# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
修改系统最大文件数
代码语言:shell复制ulimit -n #查看最大连接数
ulimit -a
echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf
sysctl -p
reboot
创建启动脚本/配置文件/数据目录
代码语言:shell复制# 创建启动脚本目录
ansible -i minio.hosts minio -m file -a 'path=/usr/local/app/minio/bin state=directory mode=0755'
# 创建配置文件目录
ansible -i minio.hosts minio -m file -a 'path=/etc/minio state=directory mode=0755'
# 创建数据目录
ansible -i minio.hosts minio -m file -a 'path=/data/minio_data/data1 state=directory mode=0755'
ansible -i minio.hosts minio -m file -a 'path=/data/minio_data/data2 state=directory mode=0755'
安装包准备
下载minio
代码语言:shell复制# 下载minio
cd /data/minio/bin && wget https://dl.min.io/server/minio/release/linux-amd64/minio
推送安装包
代码语言:shell复制# 推送minio到所有节点
ansible -i minio.hosts minio -m copy -a 'src=/usr/local/app/minio/bin/minio dest=/usr/local/app/minio/bin/minio mode=0755'
启动脚本准备
脚本名称:run.sh
代码语言:shell复制#!/bin/bash
export MINIO_ROOT_USER=minio #访问密钥,用于身份验证。根据自身情况进行修改
export MINIO_ROOT_PASSWORD=123456 # 秘密密钥,用于身份验证,根据自身情况进行修改。
/usr/local/app/minio/bin/minio server --config-dir /etc/minio --address ":9000" --console-address ":9001"
http://192.168.1.36/data/minio_data/data1 http://192.168.1.36/data/minio_data/data2
http://192.168.1.91/data/minio_data/data1 http://192.168.1.91/data/minio_data/data2
http://192.168.1.92/data/minio_data/data1 http://192.168.1.92/data/minio_data/data2
http://192.168.1.110/data/minio_data/data1 http://192.168.1.110/data/minio_data/data2
部署
推送启动脚本到所有节点
代码语言:shell复制ansible -i minio.hosts minio -m copy -a 'src=/usr/local/app/minio/bin/run.sh dest=/usr/local/app/minio/bin/run.sh mode=0755'
创建systemd配置文件minio.service
/usr/lib/systemd/system/minio.service
代码语言:shell复制[Unit]
Description=Minio service
Documentation=https://docs.minio.io/
[Service]
WorkingDirectory=/usr/local/app/minio/bin/
ExecStart=/usr/local/app/minio/bin/run.sh
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
推送启动minio.service到所有节点
代码语言:shell复制ansible -i minio.hosts minio -m copy -a 'src=/usr/lib/systemd/system/minio.service dest=/usr/lib/systemd/system/minio.service mode=0755'
启动minio
代码语言:shell复制# 启动minio
ansible -i minio.hosts minio -m shell -a 'systemctl daemon-reload'
ansible -i minio.hosts minio -m shell -a 'systemctl enable minio'
ansible -i minio.hosts minio -m shell -a 'systemctl start minio'
ansible -i minio.hosts minio -m shell -a 'systemctl status minio'
检查(查看到running)
代码语言:shell复制systemctl status minio
● minio.service - Minio service
Loaded: loaded (/usr/lib/systemd/system/minio.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2024-04-03 16:45:15 CST; 1 months 2 days ago
Docs: https://docs.minio.io/
Main PID: 38640 (run.sh)
Tasks: 30
Memory: 1.7G
CGroup: /system.slice/minio.service
访问
浏览器输入集群任意节点地址 9000端口,即可访问minio,可创建“bucket”并上传文件测试
http://192.168.1.10:9000
http://192.168.1.11:9000
http://192.168.1.12:9000
http://192.168.1.13:9000
输入账户minio
密码123456
即可访问
Nginx代理
代码语言:shell复制# 搭建nginx 参考https://zhuanlan.zhihu.com/p/639039219
# 由于测试主机80端口被占,nginx这里使用8080端口
docker run -p 8080:80 -p 8081:81 --name nginx-prod --restart=always -v /opt/docker/nginx/conf:/etc/nginx -v /opt/docker/nginx/html:/usr/share/nginx/html -v /var/log/nginx:/var/log/nginx -d nginx:1.25.1
#映射下面目录到宿主机
/opt/docker/nginx/conf # nginx 配置文件目录
/opt/docker/nginx/html # Nginx默认站点目录
/var/log/nginx #Nginx日志目录
nginx配置minio
打开 /opt/docker/nginx/conf/conf.d/minio.conf,编辑
推荐配置
( MinIO Server listening 和 MinIO Console listening分开)
代码语言:shell复制upstream minio {
least_conn;
server 192.168.1.10:9000;
server 192.168.1.11:9000;
server 192.168.1.12:9000;
server 192.168.1.13:9000;
}
upstream minio_console {
least_conn;
server 192.168.1.10:9001;
server 192.168.1.11:9001;
server 192.168.1.12:9001;
server 192.168.1.13:9001;
}
server {
listen 80;
server_name minio;
location / {
proxy_pass http://minio;
proxy_set_header Host $http_host;
#client_max_body_size 1000m;
#添加了websocket支持,解决object browser loading 问题
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /minio/ui/ {
rewrite ^/minio/ui/(.*) /$1 break;
proxy_pass http://minio_console;
proxy_set_header Host $http_host;
#client_max_body_size 1000m;
#添加了websocket支持,解决object browser loading 问题
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
nginx 启停
代码语言:shell复制# 查看配置文件是否正确
docker exec -i nginx-prod /sbin/nginx -t
# 重新加载配置
docker exec -i nginx-prod /sbin/nginx -c /etc/nginx/nginx.conf -s reload
# 重启nginx
docker exec -i nginx-prod /sbin/nginx -c /etc/nginx/nginx.conf -s reopen
访问
http://192.168.1.14:8081
输入账户minio
密码123456
即可访问
参考资料
Minio
Minio Cookbook 中文版
Linux最新版minIO分布式集群部署 高可用
minio官网文档
Ansible
自动化运维工具——ansible详解
Docker
docker资源
Nginx
nginx笔记