# Minio

# Minio官网

'' (opens new window)

# docker

版本: RELEASE.2024-07-31T05-46-26Z

mkdir -p /data/minio/data
1
docker run --name minio --network host --restart=always -d -e "MINIO_ACCESS_KEY=singleminio" -e "MINIO_SECRET_KEY=singelminio123" -v /data/server/minio/data:/data  minio/minio:RELEASE.2024-07-31T05-46-26Z server /data --console-address ":9090" -address ":9000"
1

# 搭建集群

分布式 Minio 至少需要 4 个节点(4台服务器),使用分布式 Minio 就 自动引入了纠删码功能。

1、创建所需要的文件夹

run:启动脚本及二进制文件目录 data:数据存储目录 conf:配置文件目录

mkdir -p /minio/{run,data,conf}
1

2、编写启动脚本vim /minio/run/run.sh

#!/bin/bash

# 用户名 长度最小是5个字符
export MINIO_ACCESS_KEY=Minio
# 密码不能设置过于简单,不然minio会启动失败,长度最小是8个字符;
export MINIO_SECRET_KEY=eagleMinio@123
# –config-dir:指定集群配置文件目录
# --console-address: 添加web操作面板并指定访问端口
# 9000是server默认端口 9001是web访问端口
# 记得配置4个集群的ip,并指定每个服务的存储目录

/minio/run/minio server --config-dir /minio/conf --console-address ":9001" \
http://172.30.196.188/minio/data \
http://172.30.196.67/minio/data \
http://172.30.196.173/minio/data \
http://172.30.196.127/minio/data \
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

3、配置为系统服务vim /usr/lib/systemd/system/minio.service

[Unit]
Description=Minio service
Documentation=https://docs.minio.io/

[Service]
WorkingDirectory=/data/minio/run/
ExecStart=/data/minio/run/run.sh

Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13

4、上传或者下载二进制文件到run目录,并给与可运行权限 wget 在线下载

wget https://dl.min.io/server/minio/release/linux-amd64/minio
1

给与权限

$ chmod +x /minio/run/minio && chmod +x /minio/run/run.sh
1

5、启动集群 记得检查防火墙和端口占用

systemctl daemon-reload
1
systemctl enable minio && systemctl start minio
1

4个节点都重复以上4个部署步骤。待4个节点都成功启动后,集群启动成功。

注意:如果只启动了1个节点,那么可能发现9001端口没有启动,继续等到4个节点都启动后再检查9001,会发现就启动成功了。

6、配置nginx负载均衡,建议在开一台机器,进行负载均衡

必须添加了websocket支持,因为MinioWeb界面文件列表是用的ws连接的,不进行配置会刷新不出来

#user  nobody;
worker_processes  1;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #这个参数表示http连接超时时间,默认是65s。要是上传文件比较大,在规定时间内没有上传完成,就会自动断开连接!所以适当调大这个时间。
    keepalive_timeout  100;
    # 读取请求头的超时时间,若超过所设定的大小,返回408错误。
    client_header_timeout 120s;        #调大点
    # 读取请求实体的超时时间,若超过所设定的大小,返回413错误。
    client_body_timeout 120s;          #调大点

    # 限制请求体的大小,若超过所设定的大小,返回413错误。 主要是这个参数,限制了上传文件大大小
    client_max_body_size 100m;
    # Nginx分配给请求数据的Buffer大小,如果请求的数据小于client_body_buffer_size直接将数据先在内存中存储。如果请求的值大于client_body_buffer_size小于client_max_body_size,就会将数据先存储到临时文件中,在哪个临时文件中呢?
    # client_body_temp 指定的路径中,默认该路径值是/tmp/.
    # 所以配置的client_body_temp地址,一定让执行的Nginx的用户组有读写权限。否则,当传输的数据大于client_body_buffer_size,写进临时文件失败会报错。
    # 如果追求效率,就设置 client_max_body_size,client_body_buffer_size相同的值,这样就不会存储临时文件,直接存储在内存了。
    client_body_buffer_size 100m;

    # http请求被容器(tomcat, netty等)处理后,nginx会等待处理结果,也就是容器返回的response。此参数即为服务器响应时间,默认60秒。
    proxy_connect_timeout   300;         #这三个超时时间适量调大点
    # http请求被服务器处理完后,把数据传返回给Nginx的用时,默认60秒。
    proxy_send_timeout      600;
    # http请求被容器(tomcat, netty等)处理后,nginx会等待处理结果,也就是容器返回的response。此参数即为服务器响应时间,默认60秒。
    proxy_read_timeout      600;
    # 关闭缓冲机制, 文件不需要缓冲,
    proxy_buffering off;

    upstream minio{
        server 172.30.196.188:9000;
        server 172.30.196.67:9000;
        server 172.30.196.173:9000;
        server 172.30.196.127:9000;
    }
    upstream minio_console{
        server 172.30.196.188:9001;
        server 172.30.196.67:9001;
        server 172.30.196.173:9001;
        server 172.30.196.127:9001;
    }
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen 9000;
        server_name localhost;
        location / {
            proxy_pass http://minio;

            # 添加了websocket支持
            proxy_http_version      1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_next_upstream     http_500 http_502 http_503 http_504 error timeout invalid_header;
            proxy_set_header        Host  $http_host;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
    server {
        listen 9001;
        server_name localhost;
        location / {
            proxy_pass http://minio_console;

            # 添加了websocket支持
            proxy_http_version      1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_next_upstream     http_500 http_502 http_503 http_504 error timeout invalid_header;
            proxy_set_header        Host  $http_host;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

}

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
Last Updated: 9/9/2024, 7:00:18 PM