1.前期准备
1) 参数说明
-h HOSTNAME 或者 --hostname=HOSTNAME: 设定容器的主机名,它会被写到容器内的 /etc/hostname 和 /etc/hosts。
2) 创建自定义网络
docker netowork create node1
3) 目标三个Sever,两个Client
4) 官网地址
2.部署第1个Server节点:
1) docker pull consul
2) 运行实例
docker run -d --name=node1 --restart=always \
-e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt":true}' \
-p 8300:8300 \
-p 8301:8301 \
-p 8301:8301/udp \
-p 8302:8302 \
-p 8302:8302/udp \
-p 8400:8400 \
-p 8501:8500 \
-p 8600:8600 \
-h host-node1 \
consul agent -server -bind=0.0.0.0 -bootstrap-expect=3 -node=consul-server1 \
-data-dir=/tmp/data-dir -client 0.0.0.0 -ui
3.部署第2个Server节点:
docker run -d --name=node2 --restart=always \
-e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}' \
-p 9300:8300 \
-p 9301:8301 \
-p 9301:8301/udp \
-p 9302:8302/udp \
-p 9302:8302 \
-p 9400:8400 \
-p 8502:8500 \
-p 9600:8600 \
-h host-node2 \
consul agent -server -bind=0.0.0.0 \
-join=192.168.4.130 -node-id=$(uuidgen | awk '{print tolower($0)}') \
-node=consul-server2 \
-data-dir=/tmp/data-dir -client 0.0.0.0 -ui
4.部署第3个Server节点:
docker run -d --name=node3 --restart=always \
-e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}' \
-p 10300:8300 \
-p 10301:8301 \
-p 10301:8301/udp \
-p 10302:8302/udp \
-p 10302:8302 \
-p 10400:8400 \
-p 8503:8500 \
-p 10600:8600 \
-h host-node3 \
consul agent -server -bind=0.0.0.0 \
-join=192.168.4.130 -node-id=$(uuidgen | awk '{print tolower($0)}') \
-node=consul-server3 \
-data-dir=/tmp/data-dir -client 0.0.0.0 -ui
5.部署第1个Client节点:
docker run -d --name=client1 --restart=always \
-e 'CONSUL_LOCAL_CONFIG={"leave_on_terminate": true}' \
-p 11300:8300 \
-p 11301:8301 \
-p 11301:8301/udp \
-p 11302:8302/udp \
-p 11302:8302 \
-p 11400:8400 \
-p 8500:8500 \
-p 11600:8600 \
-h host-client1 \
consul agent -bind=0.0.0.0 -retry-join=192.168.4.130 \
-node-id=$(uuidgen | awk '{print tolower($0)}') \
-node=consul-client1 \
-client 0.0.0.0 -ui
6.命令
#查看节点
docker exec -t node1 consul members
#查看主从信息
docker exec -t node1 consul operator raft list-peers