minio教程

minio 的搭建和使用.

docker 版本:

1
2
3
4
5
6
7
8
9
# 数据存在容器/data目录
# 端口 api接口/9000 ui操作/9001
# 默认 minioadmin/minioadmin
docker run --rm -d \
 --name minio \
 -p 9000:9000 -p 9001:9001 \
 -e "MINIO_ACCESS_KEY=admin" -e "MINIO_SECRET_KEY=admin" \
 -v /data/minio/data:/data -v /data/minio/config:/root/.minio \
 minio/minio server /data --console-address ":9001"

或者二进制版本:

1
2
3
wget https://dl.min.io/server/minio/release/linux-amd64/minio
chmod +x minio
MINIO_ROOT_USER=admin MINIO_ROOT_PASSWORD=password ./minio server /mnt/data --console-address ":9001"

[!info] 官方快速验证文档地址

我有 2 个机器。给每个节点加上一个 DNS 解析记录, 最好有统一的名称:

1
2
minio1.kentxxq.com
minio2.kentxxq.com

除了系统盘外,每个节点还有 2 个空的数据盘 (必须)。把数据盘挂载到系统/mnt/minio{1,2} 目录

用户和目录准备:

1
2
3
4
groupadd -r minio-user
useradd -M -r -g minio-user minio-user
# 模拟2个硬盘,2个节点
chown minio-user:minio-user /mnt/minio{1,2}

安装 minio, 官网安装页面

1
2
3
wget https://dl.min.io/server/minio/release/linux-amd64/minio
chmod +x minio
mv minio /usr/local/bin/

环境配置文件 /etc/default/minio

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 用户名和密码,集群之间是通过这个来校验的
MINIO_ROOT_USER=myminioadmin
MINIO_ROOT_PASSWORD=minio-secret-key-change-me
# api/9001 console-ui/9091
MINIO_OPTS="--address :9001 --console-address :9091"

# 2个节点互相发现,2个磁盘(除开系统盘)
MINIO_VOLUMES="http://minio{1...2}.kentxxq.com:9000/mnt/minio{1...2}"
# 或者空格间隔
# MINIO_VOLUMES="http://minio1.kentxxq.com:9001/mnt/vdb1 http://minio2.kentxxq.com:9002/mnt/vdc1 http://minio3.kentxxq.com:9003/mnt/vdd1 http://minio4.kentxxq.com:9004/mnt/vde1"

# 请求地址
MINIO_SERVER_URL="https://minio-api.kentxxq.com"
MINIO_BROWSER_REDIRECT_URL="https://minio-ui.kentxxq.com"

官方推荐Systemd 守护配置存在位置 /etc/systemd/system/minio.service

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[Unit]
Description=MinIO
Documentation=https://min.io/docs/minio/linux/index.html
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

# MinIO RELEASE.2023-05-04T21-44-30Z adds support for Type=notify (https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type=)
# This may improve systemctl setups where other services use `After=minio.server`
# Uncomment the line to enable the functionality
# Type=notify

# 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

# Built for ${project.name}-${project.version} (${project.name})

启动

1
systemctl enable minio --now
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
upstream minio_s3 {
    least_conn;
    server 10.0.1.152:9001;
    server 10.0.1.152:9002;
    server 10.0.1.152:9003;
    server 10.0.1.152:9004;
}

upstream minio_console {
    least_conn;
    server 10.0.1.152:9091;
    server 10.0.1.152:9092;
    server 10.0.1.152:9093;
    server 10.0.1.152:9094;
}

server {
    listen 80;
    server_name minio-api.kentxxq.com;
    return 301 https://$server_name$request_uri;
    include /usr/local/nginx/conf/options/normal.conf;
    access_log /usr/local/nginx/conf/hosts/logs/minio-api.kentxxq.com.log k-json;
}

server {
    http2 on;
    listen 443 ssl;
    server_name minio-api.kentxxq.com;
    include /usr/local/nginx/conf/options/ssl_kentxxq.conf;
    access_log /usr/local/nginx/conf/hosts/logs/minio-api.kentxxq.com.log k-json;
    # 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;
    # Disable buffering
    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 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_s3;
    }
}

# ui
server {
    listen 80;
    server_name minio-ui.kentxxq.com;
    return 301 https://$server_name$request_uri;
    include /usr/local/nginx/conf/options/normal.conf;
    access_log /usr/local/nginx/conf/hosts/logs/minio-ui.kentxxq.com.log k-json;
}

server {
    http2 on;
    listen 443 ssl;
    server_name minio-ui.kentxxq.com;

    include /usr/local/nginx/conf/options/ssl_kentxxq.conf;
    access_log /usr/local/nginx/conf/hosts/logs/minio-ui.kentxxq.com.log k-json;

    # 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;
    # Disable buffering
    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 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://minio_console/;
    }
}
  1. 浏览器打开登录 minio-ui.kentxxq.com 端口, 输入用户名和密码
  2. 查看集群信息
  3. 边栏 bucket 创建 demo1
  4. 边栏 access keys 创建 ak

[!info] 默认地域 us-east-1