1.每台机器都需要添加hosts,不然服务会报找不到节点
192.168.10.152 app-pro-01
192.168.10.153 app-pro-02
192.168.10.154 app-pro-03
2.在每台机器对应的目录下面执行命令docker-compose up -d
www@app-pro-01:/data//docker-compose/etcd$ ls
docker-compose.yml
www@app-pro-03:/data//docker-compose/etcd$ docker-compose up -d
Pulling etcd (quay.io/coreos/etcd:v3.3.1)...
v3.3.1: Pulling from coreos/etcd
ff3a5c916c92: Pull complete
dec5fcc85a18: Pull complete
3944f16f0112: Pull complete
0b6d29b049fe: Pull complete
d8c39ae91d38: Pull complete
42fcea4864ba: Pull complete
Digest: sha256:454e69370d87554dcb4272833b8f07ce1b5d457caa153bda4070b76d89a1cc97
Status: Downloaded newer image for quay.io/coreos/etcd:v3.3.1
Creating etcd-03 ... done
www@app-pro-03:/data/docker-compose/etcd$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dead17e2982b quay.io/coreos/etcd:v3.3.1 "etcd --name etcd-sr…" 8 seconds ago Up 6 seconds etcd-03
节点:etcd-01
节点ip:192.168.10.152
docker-compose.yml
version: "3"
services:
etcd:
user: "0"
network_mode: "host"
privileged: "true"
image: "quay.io/coreos/etcd:v3.3.1"
container_name: "etcd-01"
restart: always
stdin_open: true
environment:
TZ: Asia/Shanghai
tty: true
command: etcd --name etcd-srv1 --data-dir=/var/lib/etcd/ --initial-cluster-token etcd-cluster --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://192.168.10.152:2379 --initial-advertise-peer-urls http://192.168.10.152:2380 --listen-peer-urls http://0.0.0.0:2380 --initial-cluster-token etcd-cluster --initial-cluster "etcd-srv1=http://192.168.10.152:2380,etcd-srv2=http://192.168.10.153:2380,etcd-srv3=http://192.168.10.154:2380" --initial-cluster-state new
ports:
- "2379:2379"
- "2380:2380"
volumes:
- /data/etcd:/var/lib/etcd
节点:etcd-02
节点ip:192.168.10.153
docker-compose.yml
version: "3"
services:
etcd:
user: "0"
network_mode: "host"
privileged: "true"
image: "quay.io/coreos/etcd:v3.3.1"
container_name: "etcd-02"
restart: always
stdin_open: true
environment:
TZ: Asia/Shanghai
tty: true
command: etcd --name etcd-srv2 --data-dir=/var/lib/etcd/ --initial-cluster-token etcd-cluster --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://192.168.10.153:2379 --initial-advertise-peer-urls http://192.168.10.153:2380 --listen-peer-urls http://0.0.0.0:2380 --initial-cluster-token etcd-cluster --initial-cluster "etcd-srv1=http://192.168.10.152:2380,etcd-srv2=http://192.168.10.153:2380,etcd-srv3=http://192.168.10.154:2380" --initial-cluster-state new
ports:
- "2379:2379"
- "2380:2380"
volumes:
- /data/etcd:/var/lib/etcd
节点:etcd-03
节点ip:192.168.10.154
docker-compose.yml
version: "3"
services:
etcd:
user: "0"
network_mode: "host"
privileged: "true"
image: "quay.io/coreos/etcd:v3.3.1"
container_name: "etcd-03"
restart: always
stdin_open: true
environment:
TZ: Asia/Shanghai
tty: true
command: etcd --name etcd-srv3 --data-dir=/var/lib/etcd/ --initial-cluster-token etcd-cluster --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://192.168.10.154:2379 --initial-advertise-peer-urls http://192.168.10.154:2380 --listen-peer-urls http://0.0.0.0:2380 --initial-cluster-token etcd-cluster --initial-cluster "etcd-srv1=http://192.168.10.152:2380,etcd-srv2=http://192.168.10.153:2380,etcd-srv3=http://192.168.10.154:2380" --initial-cluster-state new
ports:
- "2379:2379"
- "2380:2380"
volumes:
- /data/etcd:/var/lib/etcd
部署完成后可以通过以下命令查看集群状态
docker exec -it 9f44a7c67aaf etcdctl member list
9f44a7c67aaf为容器ID
444589c19e148c28: name=etcd-srv3 peerURLs=http://192.168.10.154:2380 clientURLs=http://192.168.10.154:2379 isLeader=false
98373f1a6625bdd3: name=etcd-srv1 peerURLs=http://192.168.10.152:2380 clientURLs=http://192.168.10.152:2379 isLeader=true
b1c0517b2ecfa896: name=etcd-srv2 peerURLs=http://192.168.10.153:2380 clientURLs=http://192.168.10.153:2379 isLeader=false
网友评论