# docker 部署consul集群 [root@localhost ~]# docker pull consul:latest docker pull consul:latest 2 創(chuàng)建node1 3 docker logs -f node1 4 http://192.168.3.230:8500/ docker run -d -p 8500:8500 --name=consul consul agent -server -bootstrap -ui -node=consul_node1 -client='0.0.0.0' mkdir /tmp/data-dir cd /tmp/data-dir chmod 777 /tmp/data-dir #集群server端 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/udp -p 8302:8302 -p 8400:8400 -p 8500:8500 -p 8600:8600 -h node1 consul agent -server -bind=0.0.0.0 -bootstrap-expect=3 -node=node1 -data-dir=/tmp/data-dir -client 0.0.0.0 -ui 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 9500:8500 -p 9600:8600 -h node2 consul agent -server -bind=0.0.0.0 -join=192.168.32.128 -node-id=$(uuidgen | awk '{print tolower($0)}') -node=node2 -data-dir=/tmp/data-dir -client 0.0.0.0 -ui 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 10500:8500 -p 10600:8600 -h node2 consul agent -server -bind=0.0.0.0 -join=192.168.32.128 -node-id=$(uuidgen | awk '{print tolower($0)}') -node=node3 -data-dir=/tmp/data-dir -client 0.0.0.0 -ui #集群 client 端 docker run -d --name=node4 --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 11500:8500 -p 11600:8600 -h node4 consul agent -bind=0.0.0.0 -retry-join=192.168.32.128 -node-id=$(uuidgen | awk '{print tolower($0)}') -node=node4 -client 0.0.0.0 -ui docker run -d --name=node5 --restart=always -e 'CONSUL_LOCAL_CONFIG={"leave_on_terminate": true}' -p 12300:8300 -p 12301:8301 -p 12301:8301/udp -p 12302:8302/udp -p 12302:8302 -p 12400:8400 -p 12500:8500 -p 12600:8600 -h node4 consul agent -bind=0.0.0.0 -retry-join=192.168.32.128 -node-id=$(uuidgen | awk '{print tolower($0)}') -node=node5 -client 0.0.0.0 -ui http://192.168.3.230:8500/ http://192.168.3.230:9500/ http://192.168.3.230:10500/ http://192.168.3.230:11500/ http://192.168.3.230:12500/ 4查看集群狀態(tài) --清理全部容器實(shí)例 docker stop $(docker ps -q) & docker rm $(docker ps -aq) --查看節(jié)點(diǎn) docker exec -t node1 consul members --查看主從信息 docker exec -t node1 consul operator raft list-peers --集群參數(shù)get/set測試 docker exec -t node1 consul kv put eleven 11 docker exec -t node2 consul kv get eleven docker exec -t node4 consul kv get eleven docker exec -t node4 consul kv put seven 7 --關(guān)閉leader docker stop id 查看狀態(tài) docker logs -f node2 kill還有2個(gè)時(shí)可以選舉,只剩1個(gè)就集群失敗,數(shù)據(jù)不丟失的,可以重新挨個(gè)兒啟動(dòng) firewall-cmd --zone=public --add-port=8500/tcp --permanent systemctl restart firewalld.service firewall-cmd --reload firewall-cmd --list-ports #重啟 Docker 服務(wù):有時(shí)候,重啟 Docker 服務(wù)可能能解決這個(gè)問題。你可以使用以下命令來重啟 Docker 服務(wù): sudo systemctl restart docker --查看節(jié)點(diǎn) docker exec -t node1 consul members --查看主從信息 docker exec -t node1 consul operator raft list-peers --啟停節(jié)點(diǎn)做測試查看 docker stop node1 docker start node1 docker exec -t node2 consul operator raft list-peers #安裝nginx mkdir /mydata/consulnginx cd /mydata/consulnginx chmod 777 /mydata/consulnginx docker run -d -p 15500:80 -v /mydata/consulnginx/:/var/log/nginx/ -v /mydata/consulnginx/nginx.conf:/etc/nginx/nginx.conf --name consulnginx nginx |
|