目录
一、环境准备
二、MinIO简介
三、Docker Swarm简介
四、使用Docker Swarm部署 MinIO 集群
五、使用 nginx 进行负载均衡
六、在项目中使用
七、问题总结
八、文件 : docker-compose-secrets.yaml 和 default.conf
节点IP | 节点名称 | 系统 | 安装Docker及版本 |
192.168.51.171 | master171 | CentOS 7 | Docker Engine - Community 19.03.14 |
192.168.51.174 | node174 | CentOS 7 | Docker Engine - Community 19.03.14 |
192.168.51.187 | node187 | CentOS 7 | Docker Engine - Community 19.03.14 |
192.168.51.226 | node226 | CentOS 7 | Docker Engine - Community 19.03.14 |
说明:在四个节点上分别安装Docker, 具体安装步骤可参考: https://blog.csdn.net/DZP_dream/article/details/104670943
官网链接: https://docs.minio.io/cn/minio-quickstart-guide.html
MinIO 是一个基于Apache License v2.0开源协议的对象存储服务。它兼容亚马逊S3云存储服务接口,非常适合于存储大容量非结构化的数据,例如图片、视频、日志文件、备份数据和容器/虚拟机镜像等,而一个对象文件可以是任意大小,从几kb到最大5T不等。
官网链接: https://docs.docker.com/engine/swarm/key-concepts/
Docker Swarm 将一群Docker宿主机变成一个单一的虚拟主机,Swarm使用标准的Docker API接口作为其前端的访问入口, 可以在多个服务器或主机上创建容器集群服务.
官网链接: https://docs.minio.io/cn/deploy-minio-on-docker-swarm.html
1.主节点初始化Swarm (主节点执行)
docker swarm init --advertise-addr 192.168.51.171
2.添加节点到swarm (其他节点执行)
复制上图红色框中的内容,在其他节点运行
docker swarm join --token SWMTKN-1-63d9k30qdewo7r6tzpzp70ncjecbw7kava5psx14s50r04fsij-2no1dz1ayayn6v52a8mghp2xy 192.168.51.171:2377
3.查看节点 (主节点执行)
docker node ls
4.创建Docker secret (主节点执行)
echo "minio" | docker secret create access_key -
echo "12345678" | docker secret create secret_key -
* 根据实际需求设置, secret_key 至少为八位
5.(可选) 删除其中的节点, 命令如下 (主节点执行)
docker node rm --force tre2cxqg0g2esvk9sb9h6g8s5
6.节点添加标签,绑定容器与节点之间一一对应的关系 (主节点执行)
docker node update --label-add minio1=true sxfbtvvt66u7pldnut03r49u8
docker node update --label-add minio2=true vfp5ypqnsttm21q0oco8xegzi
docker node update --label-add minio3=true qdmr8lgywjpfuyzu32kjxelw8
docker node update --label-add minio4=true lzzmbydfy7yntnzrft8vlnder
7.执行以下命令, 部署stack (主节点执行)
docker-compose-secrets.yaml 内容见文末
docker stack deploy --compose-file=docker-compose-secrets.yaml minio_stack
这会将Compose文件中描述的服务部署为Docker堆栈 minio_stack
。
8.查看部署节点 (主节点执行)
docker stack ps minio_stack
或者使用以下命令查看节点信息
docker service ls
也可以通过界面管理工具查看
9.查看节点日志 (主节点执行)
docker service logs (节点ID)
10.(可选)通过以下方式删除分布式MinIO服务和相关网络 (主节点执行)
docker stack rm minio_stack
11.Swarm不会自动删除为服务创建的主机卷。在群集中创建新的MinIO服务时,这可能导致损坏。因此,我们建议手动删除MinIO使用的所有卷。为此,登录到群集中的每个节点并运行 (每个节点执行)
docker volume prune
12.访问MInIO服务
可通过http://192.168.51.171:9001/minio/进行访问, 使用 access_key 和 secret_key 进行登录.
1.编写nginx配置文件default.conf, 内容见文末
2.使用docker创建nginx容器
sudo docker run -d --name minionginx \
-p 9000:9000 \
--restart always \
-v /home/nginx/html:/usr/share/nginx/html:ro \
-v /home/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /home/nginx/logs:/var/log/nginx \
nginx
3.测试访问http://192.168.51.171:9000/, 并登录
4.使用负载均衡地址, 进行文件上传, 在其他节点进行查看, 实现文件同步
1.项目中配置
minio:
minio_url: http://192.168.51.171:9000
minio_name: minio
minio_pass: 12345678
bucketName: data
* minio_url 为 nginx 负载均衡地址
2.通过项目接口进行文件上传测试
可实现文件同步复制
3.至此MinIO集群安装成功
1.问题描述:
在添加节点执行 docker swarm join --token SWMTKN-1-63d9k30qdewo7r6tzpzp70ncjecbw7kava5psx14s50r04fsij-2no1dz1ayayn6v52a8mghp2xy 192.168.51.171:2377 命令时, 出现Error response from daemon: rpc error: code = Unavailable desc = grpc: the connection is unavailable报错,
解决方法: 此问题是由于服务器开启了防火墙, 可以使用 systemctl stop firewalld 命令, 关闭服务器防火墙后, 运行正常
2.问题描述:
在执行docker stack deploy --compose-file=docker-compose-secrets.yaml minio_stack 命令时, 报错: unsupported Compose file version: 3.7
解决方法: docker版本过低, 不支持3.7, 卸载现有版本, 升级docker版本. 卸载和安装方法可参考:https://blog.csdn.net/DZP_dream/article/details/104670943
3.问题描述:
在项目中配置minio的参数为负载均衡路径后, 上传文件时报错. [http-nio-8083-exec-1] ERROR org.jeecg.modules.system.util.MinioUtil:86 - The request signature we calculated does not match the signature you provided. Check your key and signing method. io.minio.errors.ErrorResponseException: The request signature we calculated does not match the signature you provided. Check your key and signing method.
解决方法: 在nginx.conf中添加或修改 proxy_set_header Host $http_host;
1.docker-compose-secrets.yaml内容如下:
version: '3.7'
services:
minio1:
image: minio/minio:RELEASE.2020-12-03T05-49-24Z
hostname: minio1
volumes:
- minio1-data:/export
ports:
- "9001:9000"
networks:
- minio_distributed
deploy:
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
placement:
constraints:
- node.labels.minio1==true
command: server http://minio{1...4}/export
secrets:
- secret_key
- access_key
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
minio2:
image: minio/minio:RELEASE.2020-12-03T05-49-24Z
hostname: minio2
volumes:
- minio2-data:/export
ports:
- "9002:9000"
networks:
- minio_distributed
deploy:
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
placement:
constraints:
- node.labels.minio2==true
command: server http://minio{1...4}/export
secrets:
- secret_key
- access_key
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
minio3:
image: minio/minio:RELEASE.2020-12-03T05-49-24Z
hostname: minio3
volumes:
- minio3-data:/export
ports:
- "9003:9000"
networks:
- minio_distributed
deploy:
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
placement:
constraints:
- node.labels.minio3==true
command: server http://minio{1...4}/export
secrets:
- secret_key
- access_key
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
minio4:
image: minio/minio:RELEASE.2020-12-03T05-49-24Z
hostname: minio4
volumes:
- minio4-data:/export
ports:
- "9004:9000"
networks:
- minio_distributed
deploy:
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
placement:
constraints:
- node.labels.minio4==true
command: server http://minio{1...4}/export
secrets:
- secret_key
- access_key
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
volumes:
minio1-data:
minio2-data:
minio3-data:
minio4-data:
networks:
minio_distributed:
driver: overlay
secrets:
secret_key:
external: true
access_key:
external: true
2.nginx配置文件 default.conf内容如下:
upstream minioserver{
# ip_hash;
server 192.168.51.171:9001;
server 192.168.51.174:9002;
server 192.168.51.187:9003;
server 192.168.51.226:9004;
}
server {
listen 9000;
listen [::]:9000;
server_name localhost;
# gzip config
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
proxy_pass http://minioserver;
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;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
add_header Access-Control-Allow-Origin *;
# index index.jsp index.html index.htm;
rewrite ^/$ /wlsweb;
root /usr/share/nginx/html;
# index index.html index.htm;
# try_files $uri $uri/ /index.html;
}
}
敬请批评指正