Minio 环境搭建(单点/集群/Docker)

1. 单点部署

1
2
3
4
5
$ wget https://dl.minio.org.cn/server/minio/release/linux-amd64/minio
$ chmod +x minio
$ sudo mv minio /usr/local/bin/
$ mkdir -p /opt/app/minio/data
$ MINIO_ROOT_USER=admin MINIO_ROOT_PASSWORD=admin123456 minio server /opt/app/minio/data --address "10.4.7.101:9000" --console-address ":9001"
  • 客户端工具 mc
1
2
3
4
5
6
$ wget https://dl.minio.org.cn/client/mc/release/linux-amd64/mc
$ chmod +x mc
$ sudo mv mc /usr/local/bin/

$ mc alias set local http://127.0.0.1:9000 admin admin123456
$ mc admin info local

2. 集群部署

  • Minio 生产至少部署 4 个机器 4 个节点,每个节点 4 driver,挂掉一台机器集群依然可以读写,挂掉两台机器集群依然可读
  • 磁盘挂载:参考 https://www.itcoca.cn/linux/mount-disk.html
  • 环境准备
1
2
3
4
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 2G 0 disk
└─sdb1 8:17 0 2G 0 part /data/minio
  • 集群部署
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
$ vi start.sh
#!/bin/bash
export MINIO_ROOT_USER=admin
export MINIO_ROOT_PASSWORD=admin123456
minio server --config-dir /opt/app/minio/conf \
--address "0.0.0.0:9000" --console-address ":9001" \
http://10.4.7.101/data/minio/data1 http://10.4.7.101/data/minio/data2 \
http://10.4.7.102/data/minio/data1 http://10.4.7.102/data/minio/data2
$ chmod +x start.sh

$ vi /usr/lib/systemd/system/minio.service
[Unit]
Description=Minio service
Documentation=https://docs.minio.io/
[Service]
WorkingDirectory=/opt/app/minio
ExecStart=/opt/app/minio/start.sh
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target

$ systemctl daemon-reload
$ systemctl start minio
$ systemctl status minio

3. Docker 单点部署

1
2
3
4
5
6
7
$ docker run -d -p 9000:9000 -p 9001:9001 --name minio \
--restart always \
-v /opt/app/minio/data:/data \
-e "MINIO_ROOT_USER=admin" \
-e "MINIO_ROOT_PASSWORD=admin123456" \
minio/minio:RELEASE.2023-05-27T05-56-19Z \
server /data --console-address ":9001"

4. Docker-compose 单机器集群

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
version: '3.3'

services:
minio1:
image: minio/minio:RELEASE.2023-05-27T05-56-19Z
command: server --console-address ":9001" http://minio{1...2}/data{1...2}
expose:
- "9000"
- "9001"
environment:
MINIO_ROOT_USER: admin
MINIO_ROOT_PASSWORD: admin123456
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
hostname: minio1
volumes:
- data1-1:/data1
- data1-2:/data2

minio2:
image: minio/minio:RELEASE.2023-05-27T05-56-19Z
command: server --console-address ":9001" http://minio{1...2}/data{1...2}
expose:
- "9000"
- "9001"
environment:
MINIO_ROOT_USER: admin
MINIO_ROOT_PASSWORD: admin123456
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
hostname: minio2
volumes:
- data2-1:/data1
- data2-2:/data2

nginx:
image: nginx:1.19.2-alpine
hostname: nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- "9000:9000"
- "9001:9001"
depends_on:
- minio1
- minio2

volumes:
data1-1:
data1-2:
data2-1:
data2-2:

5. Nginx 负载配置

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
96
user  nginx;
worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 4096;
}

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 minio1:9000;
server minio2:9000;
}

upstream console {
ip_hash;
server minio1:9001;
server minio2:9001;
}

server {
listen 9000;
listen [::]:9000;
server_name localhost;

#允许特殊请求头
ignore_invalid_headers off;
#不限制上传文件大小
client_max_body_size 0;
# To 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;
}
}

server {
listen 9001;
listen [::]:9001;
server_name localhost;

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 X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;

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;
}
}
}

参考