docker部署consol 集群
拉取鏡像
docker pull consul
啟動節點1
docker run -d -e ‘CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}‘ --name=node1 consul agent -server -bind=172.17.0.2 -bootstrap-expect=3 -node=node1
-node:節點的名稱
-bind:綁定的一個地址,用於節點之間通信的地址,可以是內外網,必須是可以訪問到的地址
-server:這個就是表示這個節點是個SERVER
-bootstrap-expect:這個就是表示期望提供的SERVER節點數目,數目一達到,它就會被激活,然後就是LEADER了 (LEADER就是主服務的意思)
啟動節點2
docker run -d -e ‘CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}‘ --name=node2 consul agent -server -bind=172.17.0.3 -join=172.17.0.2 -node-id=$(uuidgen | awk ‘{print tolower($0)}‘) -node=node2
啟動節點3
docker run -d -e ‘CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}‘ --name=node3 consul agent -server -bind=172.17.0.4 -join=172.17.0.2 -node-id=$(uuidgen | awk ‘{print tolower($0)}‘) -node=node3 -client=172.17.0.4
-join:這個表示啟動的時候,要加入到哪個集群內,這裏就是說要加入到節點1的集群
-node-id:這個貌似版本8才加入的,這裏用這個來指定唯一的節點ID,可以查看這個issue
-client:這個表示註冊或者查詢等一系列客戶端對它操作的IP,如果不指定這個IP,默認是127.0.0.1。
啟動節點4
docker run -d -e ‘CONSUL_LOCAL_CONFIG={"leave_on_terminate": true}‘ --name=node4 consul agent -bind=172.17.0.5 -retry-join=172.17.0.2 -node-id=$(uuidgen | awk ‘{print tolower($0)}‘) -node=node4
除了沒有server 其他都一樣,說明這是個client節點
查看集群狀態
docker exec -t node1 consul members
docker部署consol 集群