Mimio 对象存储

## 创建工作目录
mkdir -pv /data/minio/{bin,minio_data}

## 下载二进制文件
wget 'https://dl.min.io/server/minio/release/linux-amd64/minio' -P /data/minio/bin/
chmod 755 /data/minio/bin/minio

## 启动命令如下
./minio server /mnt/data --console-address ":9001"

配置

## 创建启动用户
useradd -r -s /sbin/nologin -M -d /data/minio -c "Minio server" minio
chown -R minio. /data/minio

## 设置环境变量
cat > /data/minio/.minio_env.conf <<'EOF'
## Minio 对象存储配置
# 用户名密码
MINIO_ROOT_USER='admin'
MINIO_ROOT_PASSWORD='123123123'

# 数据目录
MINIO_DATA_ROOT='/data/minio/minio_data'

# 监听端口
MINIO_SERVICE_API='9001'
MINIO_SERVICE_WEB='9002'
EOF

启动

## Unit 文件
cat > /usr/lib/systemd/system/minio.service <<'EOF'
[Unit]
Description=Minio Service
After=network.target

[Service]
Type=notify
User=minio
Group=minio

EnvironmentFile=/data/minio/.minio_env.conf
ExecStart=/data/minio/bin/minio server ${MINIO_DATA_ROOT} \
    --console-address ":${MINIO_SERVICE_WEB}" \
    --address ":${MINIO_SERVICE_API}"

ExecStop=/bin/kill -SIGTERM $MAINPID

Restart=always
RestartSec=20
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
Alias=minio
EOF


systemctl daemon-reload && systemctl enable --now minio.service
systemctl status minio.service

NGINX 代理

## 使用 NGINX 代理也必须开放 Minio 的 PAI 和 WEB 端口否则无法访问
cat > /data/nginx/conf/conf.d/minio.conf <<'EOF'
# 代理 MinIO API 接口
server {
    listen 80;
    server_name api.minio;

    # 允许在标头中使用特殊字符
    ignore_invalid_headers off;
    # 允许上传任何大小的文件
    client_max_body_size 0;
    # 禁用缓存
    proxy_buffering off;
    proxy_request_buffering off;

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://127.0.0.1:9001;
    }
}

# 代理 MinIO Web 控制台
server {
    listen 80;
    server_name web.minio;

    # 允许在标头中使用特殊字符
    ignore_invalid_headers off;
    # 允许上传任何大小的文件
    client_max_body_size 0;
    # 禁用缓存
    proxy_buffering off;
    proxy_request_buffering off;

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # 去除 /minio 前缀
        rewrite ^/minio(/.*)$ $1 break;
        proxy_pass http://127.0.0.1:9002;
    }
}
EOF
/data/nginx/sbin/nginx -c /data/nginx/conf/nginx.conf -t
/data/nginx/sbin/nginx -c /data/nginx/conf/nginx.conf