Docker Swarm部署minio集群

需要4台机器

虚拟机搭建及docker swarm搭建这里就不赘述了
参考官方文档:https://docs.minio.io/cn/deploy-minio-on-docker-swarm.html
1、为MinIO创建Docker secret

echo "miniouser" | docker secret create access_key -
echo "miniopwd" | docker secret create secret_key -

2、在主节点操作部署分布式MinIO服务,查看节点信息docker node ls 可以在一个Docker节点上运行多个minio服务。相应地设置标签

docker node update --label-add minio1=true <DOCKER-NODE1>
docker node update --label-add minio2=true <DOCKER-NODE2>
docker node update --label-add minio3=true <DOCKER-NODE3>
docker node update --label-add minio4=true <DOCKER-NODE4>

3、部署分布式minio服务 在Swarm master上下载Docker Compose file ,然后运行下面的命令docker-compose-secrets.yaml见文件末尾

docker stack deploy --compose-file=docker-compose-secrets.yaml minio_stack

在stack成功部署之后,你可以通过MinIO Client mc 或者浏览器访问http://[Node_Public_IP_Address]:[Expose_Port_on_Host]来访问你的MinIO server

4、删除分布式MinIO services

docker stack rm minio_stack

Swarm不会自动删除为MinIO服务创建的host volumes,如果下次新的MinIO服务不熟到swarm上,可能会导致损坏。因此,我们建议手动删除所有MinIO使用的volumes。为此,到每一个swarm的节点上,列出所有的volumes

docker volume ls

然后删除minio_stack volumes

docker volume rm volume_name

nginx代理部署

sudo docker run -d --name minionginx \
-p 9000:9000 \
--restart always \
-v /home/data/tools/minionginx/html:/usr/share/nginx/html:ro  \
-v  /home/data/tools/minionginx/conf.d:/etc/nginx/conf.d  \
-v /home/data/tools/minionginx/logs:/var/log/nginx \
nginx

/home/data/tools/minionginx/conf.d目录的minionginx.conf文件内容

upstream minioserver{
     
#   ip_hash;
    server  172.30.72.200:9001;
    server  172.30.72.201:9002;
    server  172.30.72.202:9003;
    server  172.30.72.203: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;
    }
 
}

docker-compose-secrets.yaml文件内容

version: '3.7'

services:
  minio1:
    image: minio/minio:RELEASE.2021-01-05T05-22-38Z
    hostname: minio1
    volumes:
      - /home/data/tools/minio/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.2021-01-05T05-22-38Z
    hostname: minio2
    volumes:
      - /home/data/tools/minio/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.2021-01-05T05-22-38Z
    hostname: minio3
    volumes:
      - /home/data/tools/minio/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.2021-01-05T05-22-38Z
    hostname: minio4
    volumes:
      - /home/data/tools/minio/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

networks:
  minio_distributed:
    driver: overlay

secrets:
  secret_key:
    external: true
  access_key:
    external: true

原minio数据迁移

1、安装mc客户端,如windows版本mc.exe 下载地址https://dl.min.io/client/mc/release/linux-amd64/mc
2、进入mc.exe目录,进入控制台cmd
3、配置集群信息

mc.exe config host add cluster181 http://192.168.0.181:9100 "miniouser" "miniopwd"
mc.exe config host add cluster182 http://192.168.0.182:9001 "miniouser" "miniopwd"

4、bucket拷贝

mc.exe mirror cluster181/development cluster182/development

浏览器访问minio集群代理地址+9000端口

你可能感兴趣的:(docker,docker,nginx,分布式)