We want to hear from you!Take our 2020 Community Survey!

Docker Compose

Docker Compose适合创建分布式的测试环境。

  1. 创建配置文件
  2. 执行命令创建Acepan集群

创建的Acepan实例运行在同一主机的多个Docker容器中,你可以用以开发,测试分布式Acepan集群。

setup

创建Acepan docker-compose配置文件

tee acepan-compose.yaml <<EOF
version: '3.0'

# starts 4 docker containers with each running one acepan instance.
# using nginx reverse proxy load balancing.
services:
  acepan1:
    image: acepan/acepan:RELEASE.2021-02-12T05-22-42Z
    volumes:
      - data1-1:/data1
      - data1-2:/data2
      - data1-3:/data3
      - data1-4:/data4
    expose:
      - "10000"
    environment:
      ACEPAN_ROOT_USER: alice
      ACEPAN_ROOT_PASSWORD: pwd12345678
    command: server http://host{1...4}/data{1...4}
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:10000/acepan/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  acepan2:
    image: acepan/acepan:RELEASE.2021-02-12T05-22-42Z
    volumes:
      - data2-1:/data1
      - data2-2:/data2
      - data2-3:/data3
      - data2-4:/data4
    expose:
      - "10000"
    environment:
      ACEPAN_ROOT_USER: alice
      ACEPAN_ROOT_PASSWORD: pwd12345678
    command: server http://host{1...4}/data{1...4}
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:10000/acepan/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  acepan3:
    image: acepan/acepan:RELEASE.2021-02-12T05-22-42Z
    volumes:
      - data3-1:/data1
      - data3-2:/data2
      - data3-3:/data3
      - data3-4:/data4
    expose:
      - "10000"
    environment:
      ACEPAN_ROOT_USER: alice
      ACEPAN_ROOT_PASSWORD: pwd12345678
    command: server http://host{1...4}/data{1...4}
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:10000/acepan/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  acepan4:
    image: acepan/acepan:RELEASE.2021-02-12T05-22-42Z
    volumes:
      - data4-1:/data1
      - data4-2:/data2
      - data4-3:/data3
      - data4-4:/data4
    expose:
      - "10000"
    environment:
      ACEPAN_ROOT_USER: alice
      ACEPAN_ROOT_PASSWORD: pwd12345678
    command: server http://host{1...4}/data{1...4}
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:10000/acepan/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  nginx:
    image: nginx:1.18.0
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "10000:10000"
    depends_on:
      - acepan1
      - acepan2
      - acepan3
      - acepan4

volumes:
  data1-1:
  data1-2:
  data1-3:
  data1-4:
  data2-1:
  data2-2:
  data2-3:
  data2-4:
  data3-1:
  data3-2:
  data3-3:
  data3-4:
  data4-1:
  data4-2:
  data4-3:
  data4-4:
EOF

创建nginx.conf文件

tee nginx.conf <<EOF
user  www-data;
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;
    keepalive_timeout  65;

    upstream acepan_object {
        server acepan1:10000;
        server acepan2:10000;
        server acepan3:10000;
        server acepan4:10000;
    }

    server {
        listen       10000;
        listen  [::]:10000;
        server_name  localhost;

        ignore_invalid_headers off;
        client_max_body_size 8192m;
        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 500;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            chunked_transfer_encoding off;

            proxy_pass http://acepan_object;
        }
    }
}
EOF

启动Acepan Docker实例

docker-compose pull
docker-compose up

最后,您可以访问http://localhost:10000查看acepan运行状态。