1、简介
Minio是GlusterFS创始人之一Anand Babu Periasamy发布新的开源项目。基于Apache License v2.0开源协议的对象存储项目,采用Golang实现,客户端支Java,Python,Javacript, Golang语言。
其设计的主要目标是作为私有云对象存储的标准方案。主要用于存储海量的图片,视频,文档等。非常适合于存储大容量非结构化的数据,例如图片、视频、日志文件、备份数据和容器/虚拟机镜像等,而一个对象文件可以是任意大小,从几kb到最大5T不等。
2、环境
IP | 主机名 | 数据目录 |
10.0.0.1 | minio001 | /data/minio |
10.0.0.2 | minio002 | /data/minio |
10.0.0.3 | minio003 | /data/minio |
10.0.0.4 | minio004 | /data/minio |
3、下载
cd /usr/local/src; wget https://dl.minio.io/server/minio/release/linux-amd64/minio
cp minio /usr/bin/; chmod u+x minio
4、集群部署(所有节点相同操作)
创建目录
mkdir -pv /data/minio /opt/minio
编写启动脚本
vi /opt/minio/start.sh
#!/bin/bash
export MINIO_ROOT_USER=test
export MINIO_ROOT_PASSWORD=test
/usr/bin/minio server --address ":9000" --console-address ":9001" http://minio001/data/minio http://minio002/data/minio http://minio003/data/minio http://minio004/data/minio > /opt/minio/minio.log 2>&1 &
# –address “:9000”,可配置minio的API访问端口
# –console-address “:9001”,可配置minio的WEB管理界面的访问端口
# –config-dir /opt/minio/config是指定配置文件路径的,如果没有指定这个参数,那么默认就会在~/.minio下生成相关的文件
授权并启动
chmod u+x /opt/minio/start.sh
./start.sh
5、访问
输入集群任意节点地址,如需负载可配置nginx,如果地址访问不通,请关闭防火墙或者开放9000端口
6、配置负载均衡
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
# include /etc/nginx/conf.d/*.conf;
upstream minio {
server 172.16.0.1:9000;
server 172.16.0.2:9000;
server 172.16.0.3:9000;
server 172.16.0.4:9000;
}
upstream console {
ip_hash;
server 10.0.0.1:9001;
server 10.0.0.2:9001;
server 10.0.0.3:9001;
server 10.0.0.4:9001;
}
server {
listen 9000;
listen [::]:9000;
server_name localhost;
# To allow special characters in headers
ignore_invalid_headers off;
# Allow any size file to be uploaded.
# Set to a value such as 1000m; to restrict file size to a specific value
client_max_body_size 0;
# To disable buffering
proxy_buffering off;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 300;
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;
proxy_pass http://minio;
}
}
server {
listen 9001;
listen [::]:9001;
server_name localhost;
# To allow special characters in headers
ignore_invalid_headers off;
# Allow any size file to be uploaded.
# Set to a value such as 1000m; to restrict file size to a specific value
client_max_body_size 0;
# To disable buffering
proxy_buffering off;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
# This is necessary to pass the correct IP to be hashed
real_ip_header X-Real-IP;
proxy_connect_timeout 300;
# To support websocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
chunked_transfer_encoding off;
proxy_pass http://console;
}
}
}
7、注意
minio数据目录,一旦初始化后,增加或减少数据目录,会报错:已被使用。需要删除数据目录重建;
例如:1服务器进行单机部署调试,调试成功后,进行1、2、3、4集群部署时,minio目录必须删除重建。
8、集群某节点故障修复
# 启动命令
/usr/local/bin/minio server --console-address :9001 http://minio001:9000/data/minio http://minio002:9000/data/minio http://minio003:9000/data/minio http://minio004:9000/data/minio
# 新建相同IP或相同域名的主机,并安装minio
拷贝命令文件:scp -r mc minio minio004:/usr/local/bin/
拷贝配置文件:scp minio minio004:/etc/default/
MINIO_VOLUMES="http://minio001:9000/data/minio http://minio002:9000/data/minio http://minio003:9000/data/minio http://minio004:9000/data/minio"
MINIO_OPTS="--console-address :9001"
MINIO_ROOT_USER=herlly
MINIO_ROOT_PASSWORD=Asdf1234
MINIO_PROMETHEUS_URL=http://prometheus:9090
MINIO_PROMETHEUS_JOB_ID=minio-job
#MINIO_PROMETHEUS_AUTH_TYPE=public
#MINIO_PROMETHEUS_AUTH_TYPE="public"
拷贝启动文件:scp minio.service minio004:/etc/systemd/system/
[Unit]
Description=MinIO
Documentation=https://docs.min.io
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/bin/minio
[Service]
WorkingDirectory=/usr/local
User=minio-user
Group=minio-user
ProtectProc=invisible
EnvironmentFile=-/etc/default/minio
ExecStartPre=/bin/bash -c "if [ -z \"${MINIO_VOLUMES}\" ]; then echo \"Variable MINIO_VOLUMES not set in /etc/default/minio\"; exit 1; fi"
ExecStart=/usr/local/bin/minio server $MINIO_OPTS $MINIO_VOLUMES
# Let systemd restart this service always
Restart=always
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
# Specifies the maximum number of threads this process can create
TasksMax=infinity
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=infinity
SendSIGKILL=no
[Install]
WantedBy=multi-user.target
# 拷贝mc配置文件:scp ~/.mc/config.json minio004:~/.mc/
{
"version": "10",
"aliases": {
"gcs": {
"url": "https://storage.googleapis.com",
"accessKey": "YOUR-ACCESS-KEY-HERE",
"secretKey": "YOUR-SECRET-KEY-HERE",
"api": "S3v2",
"path": "dns"
},
"local": {
"url": "http://localhost:9000",
"accessKey": "lnso",
"secretKey": "12345",
"api": "S3v4",
"path": "auto"
},
"play": {
"url": "https://localhost:9000",
"accessKey": "lnso",
"secretKey": "12345",
"api": "S3v4",
"path": "auto"
},
"s3": {
"url": "https://s3.amazonaws.com",
"accessKey": "YOUR-ACCESS-KEY-HERE",
"secretKey": "YOUR-SECRET-KEY-HERE",
"api": "S3v4",
"path": "dns"
}
}
}
# 创建minio用户
useradd -s /sbin/nologin minio-use
# 创建目录并授权,保持集群一致
mkdir -pv /data/minio
chown -R minio-user.minio-user /data/minio/
# 启动并设置开机自启
systemctl enable --now minio
# 等待数据同步完成即可