文章目录
- 下载 Minio 二进制文件
- 配置 Minio
- 将Minio设置成服务 配置Systemd服务启动
- 创建minio变量文件:/etc/default/minio
- 创建Service File:/etc/systemd/system/minio.service
- 设置开启自启动
- Nginx反向代理
- nginx配置
下载 Minio 二进制文件
cd /usr/local/bin
# 下载minio
wget https://dl.min.io/server/minio/release/linux-amd64/minio
# 添加执行权限
chmod +x /usr/local/bin/minio
配置 Minio
# 创建数据目录
mkdir /data
# 配置环境变量
export MINIO_ACCESS_KEY=myaccesskey
export MINIO_SECRET_KEY=mysecretkey
将Minio设置成服务 配置Systemd服务启动
创建minio变量文件:/etc/default/minio
[root@minio-server ~]# vim /etc/default/minio
# S3 API端口和MinIO Console 地址端口
MINIO_OPTS="--address :9002 --console-address :9001"
# 访问用户名密码
MINIO_ROOT_USER=minioadmin
MINIO_ROOT_PASSWORD=minioadmin
# 存储路径
MINIO_VOLUMES="/data"
# S3-API 地址 一般用于程序连接 默认即可
# MINIO_SERVER_URL=""
# MinIO Console 访问地址 如果想通过nginx 使用同一个域名同时代理9000和90001端口
# 则需要配置该变量,然后在nginx中的location块指定 /minio/ui 即可
MINIO_BROWSER_REDIRECT_URL="http://minio.tbchip.com/minio/ui"
创建Service File:/etc/systemd/system/minio.service
[root@minio-server ~]# vim /etc/systemd/system/minio.service
[Unit]
Description=MinIO
Documentation=https://docs.min.io
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/bin/minio
[Service]
WorkingDirectory=/data
User=root
Group=root
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
# Built for ${project.name}-${project.version} (${project.name})
参数说明
User、Group: 这里如果想要使用非root用户,则需要新建对应的用户,并且授权数据目录有用户访问权限即可
EnvironmentFile:指定加载的变量文件
address: S3 API端口,一般用来与程序进行对接
console-address: web端访问端口
设置开启自启动
[root@minio-server ~]# systemctl daemon-reload
[root@minio-server ~]# systemctl enable minio.service
[root@minio-server ~]# systemctl start minio.service
Nginx反向代理
这里我们准备一个域名: http://minio.tbchip.com,s3 与 console 端口我们都使用同一个域名进行代理
nginx配置
/etc/nginx/conf.d/minio.conf
server {
listen 80;
listen [::]:80;
server_name minio.tbchip.com;
# 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;
# s3 api 地址
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://172.100.1.94:9000; # This uses the upstream directive definition to load balance
}
# web 访问地址
location /minio/ui/ {
rewrite ^/minio/ui/(.*)$ /$1 break;
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 websockets in MinIO versions released after January 2023
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Some environments may encounter CORS errors (Kubernetes + Nginx Ingress)
# Uncomment the following line to set the Origin request to an empty string
# proxy_set_header Origin '';
chunked_transfer_encoding off;
proxy_pass http://172.100.1.94:9001; # This uses the upstream directive definition to load balance
}
}
注意
location /minio/ui/ 是console访问地址,这里如果想要使用同一个域名进行代理S3的9000和console的9001端口,则必须配置环境变量MINIO_BROWSER_REDIRECT_URL的值,设置的值也必须是真实的访问地址,比如我这边: MINIO_BROWSER_REDIRECT_URL=“http://minio.tbchip.com/minio/ui”
- 当进行以上配置后,我们通过web端访问就不用在指定端口,直接浏览器输入: http://minio.tbchip.com/minio/ui 即可