基于docker-compose拉起etcd cluster的配置示例

网上好多都不靠谱不好使。分享一个测试通过的版本,用于在一台宿主机上拉起5个节点的etcd集群,每个节点2379端口分别映射到宿主机不同的端口上e供外部网络访问。

version: '2'
services:
  etcd1:
    image: quay.io/coreos/etcd:v3.0.15
    container_name: etcd1
    tty: true
    network_mode: bridge
    command: 
        etcd
        -name etcd1
        -advertise-client-urls http://11.164.232.46:32373,http://11.164.232.46:32573
        -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
        -listen-peer-urls http://0.0.0.0:2380
        -initial-advertise-peer-urls http://11.164.232.46:32473
        -initial-cluster-token etcd-cluster
        -initial-cluster etcd1=http://11.164.232.46:32473,etcd2=http://11.164.232.46:32474,etcd3=http://11.164.232.46:32475,etcd4=http://11.164.232.46:32476,etcd5=http://11.164.232.46:32477
        -initial-cluster-state new
    ports:
      - '32373:2379'
      - '32473:2380'
      - '32573:4001'

  etcd2:
    image: quay.io/coreos/etcd:v3.0.15
    container_name: etcd2
    tty: true
    network_mode: bridge
    command: 
        etcd
        -name etcd2
        -advertise-client-urls http://11.164.232.46:32374,http://11.164.232.46:32574
        -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
        -listen-peer-urls http://0.0.0.0:2380
        -initial-advertise-peer-urls http://11.164.232.46:32474
        -initial-cluster-token etcd-cluster
        -initial-cluster etcd1=http://11.164.232.46:32473,etcd2=http://11.164.232.46:32474,etcd3=http://11.164.232.46:32475,etcd4=http://11.164.232.46:32476,etcd5=http://11.164.232.46:32477
        -initial-cluster-state new
    ports:
      - '32374:2379'
      - '32474:2380'
      - '32574:4001'

  etcd3:
    image: quay.io/coreos/etcd:v3.0.15
    container_name: etcd3
    tty: true
    network_mode: bridge
    command: 
        etcd
        -name etcd3
        -advertise-client-urls http://11.164.232.46:32375,http://11.164.232.46:32575
        -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
        -listen-peer-urls http://0.0.0.0:2380
        -initial-advertise-peer-urls http://11.164.232.46:32475
        -initial-cluster-token etcd-cluster
        -initial-cluster etcd1=http://11.164.232.46:32473,etcd2=http://11.164.232.46:32474,etcd3=http://11.164.232.46:32475,etcd4=http://11.164.232.46:32476,etcd5=http://11.164.232.46:32477
        -initial-cluster-state new
    ports:
      - '32375:2379'
      - '32475:2380'
      - '32575:4001'

  etcd4:
    image: quay.io/coreos/etcd:v3.0.15
    container_name: etcd4
    tty: true
    network_mode: bridge
    command: 
        etcd
        -name etcd4
        -advertise-client-urls http://11.164.232.46:32376,http://11.164.232.46:32576
        -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
        -listen-peer-urls http://0.0.0.0:2380
        -initial-advertise-peer-urls http://11.164.232.46:32476
        -initial-cluster-token etcd-cluster
        -initial-cluster etcd1=http://11.164.232.46:32473,etcd2=http://11.164.232.46:32474,etcd3=http://11.164.232.46:32475,etcd4=http://11.164.232.46:32476,etcd5=http://11.164.232.46:32477
        -initial-cluster-state new
    ports:
      - '32376:2379'
      - '32476:2380'
      - '32576:4001'  
    
  etcd5:
    image: quay.io/coreos/etcd:v3.0.15
    container_name: etcd5
    tty: true
    network_mode: bridge
    command: 
        etcd
        -name etcd5
        -advertise-client-urls http://11.164.232.46:32377,http://11.164.232.46:32577
        -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
        -listen-peer-urls http://0.0.0.0:2380
        -initial-advertise-peer-urls http://11.164.232.46:32477
        -initial-cluster-token etcd-cluster
        -initial-cluster etcd1=http://11.164.232.46:32473,etcd2=http://11.164.232.46:32474,etcd3=http://11.164.232.46:32475,etcd4=http://11.164.232.46:32476,etcd5=http://11.164.232.46:32477
        -initial-cluster-state new
    ports:
      - '32377:2379'
      - '32477:2380'
      - '32577:4001'

猜你喜欢

转载自www.cnblogs.com/luliAngel/p/etcd.html