minio 搭建集群并动态扩容

准备nginx配置文件

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    # include /etc/nginx/conf.d/*.conf;

    upstream minio9000 {
        server minio1:9000;
        server minio2:9000;
    }

     upstream minio9001 {
        server minio1:9001;
        server minio2:9001;
    }

    # main minio
    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;

        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://minio9000;
        }
    }

    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;

        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://minio9001;
        }
    }
}

准备docker-compose配置文件

version: '3'
services:
  minio1:
    image: minio/minio:RELEASE.2022-03-26T06-49-28Z
    container_name: minio1
    hostname: minio1
    restart: always
    environment:
      - MINIO_ROOT_USER=minio
      - MINIO_ROOT_PASSWORD=minioadmin
    volumes:
      - ./data/minio1/data1:/data1
      - ./data/minio1/data2:/data2

    command: server http://minio{1...2}/data{1...2} --console-address ":9001"

  minio2:
    image: minio/minio:RELEASE.2022-03-26T06-49-28Z
    container_name: minio2
    hostname: minio2
    restart: always
    environment:
      - MINIO_ROOT_USER=minio
      - MINIO_ROOT_PASSWORD=minioadmin
    volumes:
      - ./data/minio2/data1:/data1
      - ./data/minio2/data2:/data2

    command: server http://minio{1...2}/data{1...2} --console-address ":9001"

  nginx:
    image: nginx:1.19.2-alpine
    container_name: minio-nginx
    hostname: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "9900:9000"
      - "9001:9001"
    depends_on:
      - minio1
      - minio2


networks:
  default:
    external:
      name: minio

启动服务

启动之前需要创建网络

docker network create minio
docker-compose up -d

在这里插入图片描述

扩容

将启动命令修改为server http://minio{1...2}/data{1...2} http://minio{3...4}/data{1...2},即将原来的集群扩展为包含4个实例的集群。

最终的配置文件如下

docker-compose

version: '3'
services:
  minio1:
    image: minio/minio:RELEASE.2022-03-26T06-49-28Z
    container_name: minio1
    hostname: minio1
    restart: always
    environment:
      - MINIO_ROOT_USER=minio
      - MINIO_ROOT_PASSWORD=minioadmin
    volumes:
      - ./data/minio1/data1:/data1
      - ./data/minio1/data2:/data2

    command: server http://minio{1...2}/data{1...2} http://minio{3...4}/data{1...2}  --console-address ":9001"

  minio2:
    image: minio/minio:RELEASE.2022-03-26T06-49-28Z
    container_name: minio2
    hostname: minio2
    restart: always
    environment:
      - MINIO_ROOT_USER=minio
      - MINIO_ROOT_PASSWORD=minioadmin
    volumes:
      - ./data/minio2/data1:/data1
      - ./data/minio2/data2:/data2

    command: server http://minio{1...2}/data{1...2} http://minio{3...4}/data{1...2} --console-address ":9001"

  minio3:
    image: minio/minio:RELEASE.2022-03-26T06-49-28Z
    container_name: minio3
    hostname: minio3
    restart: always
    environment:
      - MINIO_ROOT_USER=minio
      - MINIO_ROOT_PASSWORD=minioadmin
    volumes:
      - ./data/minio3/data1:/data1
      - ./data/minio3/data2:/data2

    command: server http://minio{1...2}/data{1...2} http://minio{3...4}/data{1...2}  --console-address ":9001"

  minio4:
    image: minio/minio:RELEASE.2022-03-26T06-49-28Z
    container_name: minio4
    hostname: minio4
    restart: always
    environment:
      - MINIO_ROOT_USER=minio
      - MINIO_ROOT_PASSWORD=minioadmin
    volumes:
      - ./data/minio4/data1:/data1
      - ./data/minio4/data2:/data2

    command: server http://minio{1...2}/data{1...2} http://minio{3...4}/data{1...2}  --console-address ":9001"

  nginx:
    image: nginx:1.19.2-alpine
    container_name: minio-nginx
    hostname: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "9900:9000"
      - "9001:9001"
    depends_on:
      - minio1
      - minio2
      - minio3
      - minio4


networks:
  default:
    external:
      name: minio

nginx

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    # include /etc/nginx/conf.d/*.conf;

    upstream minio9000 {
        server minio1:9000;
        server minio2:9000;
        server minio3:9000;
        server minio4:9000;
    }

     upstream minio9001 {
        server minio1:9001;
        server minio2:9001;
        server minio3:9001;
        server minio4:9001;
    }

    # main minio
    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;

        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://minio9000;
        }
    }

    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;

        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://minio9001;
        }
    }
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

llc的足迹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值