MinIO多容器配置NGINX代理实践(docker-compose版本)

以下nginx配置

分别将本机的9001端口代理到minio1,minio2,minio3,minio4主机的9001端口。用于minio后台

分别将本机的9000端口代理到minio1,minio2,minio3,minio4主机的9000端口。用于minioApi

events {
    worker_connections 1024;
}

http {
    upstream minio_console {
        server minio1:9001 max_fails=3 fail_timeout=5s;
        server minio2:9001 max_fails=3 fail_timeout=5s;
        server minio3:9001 max_fails=3 fail_timeout=5s;
        server minio4:9001 max_fails=3 fail_timeout=5s;
    }

    upstream minio_api {
        least_conn; #最少连接
        server minio1:9000 max_fails=3 fail_timeout=5s;
        server minio2:9000 max_fails=3 fail_timeout=5s;
        server minio3:9000 max_fails=3 fail_timeout=5s;
        server minio4:9000 max_fails=3 fail_timeout=5s;
    }

    server {
        listen 9001;
        ignore_invalid_headers off;
        client_max_body_size 0;
        proxy_buffering off;

        location / {
            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 Host $http_host;
            proxy_pass http://minio_console;
        }
    }

    server {
        listen 9000;
        ignore_invalid_headers off;
        client_max_body_size 0;
        proxy_buffering off;

        location / {
            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 Host $http_host;
            proxy_pass http://minio_api;
        }
    }
}

docker-compose.yaml配置:

version: '3.7'

networks:  # 定义网络
  minio_network:  # 网络名字

# Settings and configurations that are common for all containers
x-minio-common: &minio-common
  image: quay.io/minio/minio:RELEASE.2023-11-01T18-37-25Z
  command: server --console-address ":9001" http://minio{1...4}/data{1...2}
  expose:
    - "9000"
    - "9001"
  # environment:
    # MINIO_ROOT_USER: minioadmin
    # MINIO_ROOT_PASSWORD: minioadmin
  healthcheck:
    test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
    interval: 30s
    timeout: 20s
    retries: 3

# 开启四个minioserver端容器以及一个nginx容器
# 使用nginx做负载均衡
services:
  minio1:
    <<: *minio-common
    hostname: minio1
    volumes:
      - data1-1:/data1
      - data1-2:/data2
    networks:
      - minio_network
  minio2:
    <<: *minio-common
    hostname: minio2
    volumes:
      - data2-1:/data1
      - data2-2:/data2
    networks:
      - minio_network

  minio3:
    <<: *minio-common
    hostname: minio3
    volumes:
      - data3-1:/data1
      - data3-2:/data2
    networks:
      - minio_network
  minio4:
    <<: *minio-common
    hostname: minio4
    volumes:
      - data4-1:/data1
      - data4-2:/data2
    networks:
      - minio_network
  nginx:
    image: nginx:1.19.2-alpine
    hostname: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "9000:9000"
      - "9001:9001"
    #depends是告诉docker需要先启动以下四个容器才启动本容器
    depends_on:
      - minio1
      - minio2
      - minio3
      - minio4
    networks:
      - minio_network
## By default this config uses default local driver,
## For custom volumes replace with volume driver configuration.
volumes:
  data1-1:
  data1-2:
  data2-1:
  data2-2:
  data3-1:
  data3-2:
  data4-1:
  data4-2:

 services下的各个minio-server的实例中的hostname主要用于nginx配置文件中的配置。

MinIO多容器配置NGINX代理实践(docker-compose版本)_第1张图片

dockercompose的配置文件和Nginx的配置文件放在同一目录。

运行dockercompose

(需安装dockercompose)-ubuntu

apt install -y docker-compose

(需安装dockercompose)-centos

yum install -y docker-compose

docker-compose -f docker-compose.yaml up

访问本机9001端口:

MinIO多容器配置NGINX代理实践(docker-compose版本)_第2张图片

你可能感兴趣的:(nginx,运维)