单机模式部署
mkdir -p /data/docker-compose/minio mkdir -p /data/minio/data{1..4} cat /data/docker-compose/minio/docker-compose.yml version: '3' networks: minio: driver: bridge services: minio: image: "quay.io/minio/minio" container_name: minio restart: always command: server --console-address ":9001" http://minio/data{1...2} environment: - MINIO_ROOT_USER=admin - MINIO_ROOT_PASSWORD=Uenpay@2019 volumes: - /data/minio/data1:/data1 - /data/minio/data2:/data2 ports: - "9000:9000" - "9001:9001" healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 networks: - minio
以上需要注意的几个点:
- 需要暴露的端口有两个,一个是API暴露端口9000,一个是服务管理页面暴露端口9001。启动成功后,访问9001端口即可进入管理页面。
- 单机版部署也可挂载多个磁盘,单个服务挂载超过(等于)4个磁盘,自动启动纠删码模式,可以预防磁盘损坏的情况下,导致文件丢失。
- 最新版本里面已经不使用MINIO_ACCESS_KEY和MINIO_SECRET_KEY两个环境变量了,改由MINIO_ROOT_USER和MINIO_ROOT_PASSWORD替换。
- 启动命令中
--console-address
代表指定服务管理页面暴露的端口,http://minio/data{1...2}代表指定的minio服务下面挂载的目标磁盘为/data1和/data2,否则磁盘挂载不起作用。API暴露端口可通过参数–address指定。
纠删模式部署
cat /data/docker-compose/minio/docker-compose.yml version: '3' networks: minio: driver: bridge services: minio: image: "quay.io/minio/minio" container_name: minio restart: always command: server --console-address ":9001" http://minio/data{1...2} environment: - MINIO_ROOT_USER=admin - MINIO_ROOT_PASSWORD=Uenpay@2019 volumes: - /data/minio/data1:/data1 - /data/minio/data2:/data2 - /data/minio/data3:/data3 - /data/minio/data4:/data4 ports: - "9000:9000" - "9001:9001" healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3 networks: - minio
在单机模式部署的情况下,调整为纠删码模式,我们需要修改两个地方:
- 挂载的磁盘增加到四个
- 启动命令里面补上对应的挂载磁盘
该模式运行其中某个磁盘出现损坏的情况,在磁盘损坏后也能保证文件不会丢失。
分布式部署
version: "3.7" services: minio: image: "quay.io/minio/minio:RELEASE.2022-08-02T23-59-16Z" ports: - "9000:9000" - "9001:9001" volumes: - "./minio/data1:/data1" - "./minio/data2:/data2" - "./minio/data3:/data3" - "./minio/data4:/data4" command: server --console-address ":9001" http://192.168.2.231:9000/data{1...4} http://192.168.2.232:9000/data{1...4} http://192.168.2.233:9000/data{1...4} http://192.168.2.234:9000/data{1...4} environment: - MINIO_ROOT_USER=admin - MINIO_ROOT_PASSWORD=12345678 healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] interval: 30s timeout: 20s retries: 3
在启动命令中,我们需要把集群中所有的服务ip都写进去,这样的话,minio分布式服务才能正常通信。
- 部署负载均衡服务nginx
当四台机器上的服务全部起来后,我们需要提供一个负载均衡服务作为访问minio分布式服务的统一的入口,首当其冲我们就想到了nginx,所以我们在使用docker compose部署一个nginx服务:
version: '3.7' services: nginx: image: nginx:1.19.2-alpine hostname: nginx volumes: - ./nginx.conf:/etc/nginx/nginx.conf:ro ports: - "9000:9000" - "9001:9001"
下面是nginx配置文件:
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 192.168.2.231:9000; server 192.168.2.232:9000; server 192.168.2.233:9000; server 192.168.2.234:9000; } upstream console { ip_hash; server 192.168.2.231:9001; server 192.168.2.232:9001; server 192.168.2.233:9001; server 192.168.2.234:9001; } server { listen 9000; listen [::]:9000; server_name localhost; # To 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; # 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; # To 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; # 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_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://console; } } }
启动nginx服务,这样所有的请求都通过nginx负载均衡到minio服务上。