etcd docker-compose 크로스 머신 3 노드 집단 배치 수동 가입 노드

세 대의 서버가 하나의 집단을 구성하는데 IP는 각각 10.100.46.6 10.100.46.7 10.100.46.10이다.
시작 순서는 10.100.46.10 = 10.100.46.6 = 10.100.46.7
마스터 도커-compose 파일
10.100.46.10의docker-compose.yml
version: '2'
services:
  etcd:
    container_name: etcd-offline-10
    image: registry.cn-hangzhou.aliyuncs.com/coreos_etcd/etcd:v3
    network_mode: "host"
    ports:
      - "2379:2379"
      - "2380:2380"
    environment:
      - TZ=CST-8
      - LANG=zh_CN.UTF-8
    command:
      /usr/local/bin/etcd
      -name etcd-offline-10
      -data-dir /etcd-data
      -advertise-client-urls http://10.100.46.10:2379
      -listen-client-urls http://10.100.46.10:2379,http://127.0.0.1:2379
      -initial-advertise-peer-urls http://10.100.46.10:2380
      -listen-peer-urls http://10.100.46.10:2380
      -initial-cluster-token xingchen
      -initial-cluster-state new
    volumes:
      - "/data/etcd/data:/etcd-data"

명령 docker-compose up 사용 후 시작
그리고 로컬 etcdctl를 사용하여 노드를 추가하는 동작을 합니다. (주의: 그룹에 노드를 추가하고 노드를 시작합니다)
46.10의 작업 기록
[root@localhost etcd]# ./etcdctl member add etcd-offline-6 http://10.100.46.6:2380
Added member named etcd-offline-6 with ID 3bf8c1715d31b529 to cluster
 
ETCD_NAME="etcd-offline-6"
ETCD_INITIAL_CLUSTER="etcd-offline-6=http://10.100.46.6:2380,etcd-offline-10=http://10.100.46.10:2380"
ETCD_INITIAL_CLUSTER_STATE="existing"

그리고 프롬프트에 따라 46.6에서 docker-compose 파일 추가 -name etcd-offline-6-initial-cluster etcd-offline-6=http://10.100.46.6:2380,etcd-offline-10=http://10.100.46.10:2380-initial-cluster-state existing 10.100.46.6의 docker-compose.yml
version: '2'
services:
  etcd:
    container_name: etcd-offline-6
    image: registry.cn-hangzhou.aliyuncs.com/coreos_etcd/etcd:v3
    network_mode: "host"
    ports:
      - "2379:2379"
      - "2380:2380"
    environment:
      - TZ=CST-8
      - LANG=zh_CN.UTF-8
    command:
      /usr/local/bin/etcd
      -name etcd-offline-6
      -data-dir /etcd-data
      -advertise-client-urls http://10.100.46.6:2379
      -listen-client-urls http://10.100.46.6:2379,http://127.0.0.1:2379
      -initial-advertise-peer-urls http://10.100.46.6:2380
      -listen-peer-urls http://10.100.46.6:2380
      -initial-cluster-token xingchen
      -initial-cluster etcd-offline-6=http://10.100.46.6:2380,etcd-offline-10=http://10.100.46.10:2380
      -initial-cluster-state existing
    volumes:
      - "/data/etcd/data:/etcd-data"

그리고 docker-compose up 시작 노드를 실행하여 46.10에서 그룹 상태 보기 etcdctl member list
노드 상태
[root@localhost etcd]# ./etcdctl --endpoint http://10.100.46.6:2379 member list
3bf8c1715d31b529: name=etcd-offline-6 peerURLs=http://10.100.46.6:2380 clientURLs=http://10.100.46.6:2379 isLeader=false
51430d988a335e3c: name=etcd-offline-10 peerURLs=http://10.100.46.10:2380 clientURLs=http://10.100.46.10:2379 isLeader=true

집단에 두 개의 노드가 있는 것을 볼 수 있고 46.7을 늘려서 집단에 들어가는 것을 볼 수 있다
46.7 증가
[root@localhost etcd]# ./etcdctl member add etcd-offline-7 http://10.100.46.7:2380
Added member named etcd-offline-7 with ID f61051e7f96e81f2 to cluster
 
ETCD_NAME="etcd-offline-7"
ETCD_INITIAL_CLUSTER="etcd-offline-6=http://10.100.46.6:2380,etcd-offline-10=http://10.100.46.10:2380,etcd-offline-7=http://10.100.46.7:2380"
ETCD_INITIAL_CLUSTER_STATE="existing"

46.7에서 설정을 수정하고docker 용기docker-compose up을 시작합니다
version: '2'
services:
  etcd:
    container_name: etcd-offline-7
    image: registry.cn-hangzhou.aliyuncs.com/coreos_etcd/etcd:v3
    network_mode: "host"
    ports:
      - "2379:2379"
      - "2380:2380"
    environment:
      - TZ=CST-8
      - LANG=zh_CN.UTF-8
    command:
      /usr/local/bin/etcd
      -name etcd-offline-7
      -data-dir /etcd-data
      -advertise-client-urls http://10.100.46.7:2379
      -listen-client-urls http://10.100.46.7:2379,http://127.0.0.1:2379
      -initial-advertise-peer-urls http://10.100.46.7:2380
      -listen-peer-urls http://10.100.46.7:2380
      -initial-cluster-token xingchen
      -initial-cluster etcd-offline-6=http://10.100.46.6:2380,etcd-offline-7=http://10.100.46.7:2380,etcd-offline-10=http://10.100.46.10:2380
      -initial-cluster-state existing
    volumes:
      - "/data/etcd/data:/etcd-data"

46.10에서 새로운 집단 상태를 보니 이미 세 노드였다.
3 노드 상태
[root@localhost etcd]# ./etcdctl --endpoint http://10.100.46.6:2379 member list
3bf8c1715d31b529: name=etcd-offline-6 peerURLs=http://10.100.46.6:2380 clientURLs=http://10.100.46.6:2379 isLeader=false
51430d988a335e3c: name=etcd-offline-10 peerURLs=http://10.100.46.10:2380 clientURLs=http://10.100.46.10:2379 isLeader=true
f61051e7f96e81f2: name=etcd-offline-7 peerURLs=http://10.100.46.7:2380 clientURLs=http://10.100.46.7:2379 isLeader=false

단일 노드를 시작할 때 쓴 데이터는 전체 그룹에 자동으로 동기화됩니다!
끝!

좋은 웹페이지 즐겨찾기