1、安裝Consul
# 下載Consul
# wget https://releases.hashicorp.com/consul/0.7.2/consul_0.7.2_linux_amd64.zip -O consul.zip
# cd /opt/
# unzip consul_0.7.2_linux_amd64.zip
# 將解壓的二進制文件Consul移動到 /usr/bin/
# mv consul /usr/bin/
2、啓動Consul集羣
推薦 Consul集羣使用 3 臺或 5 臺 serverAgent。
# serverAgent 啓動
# [root@localhost bin]# nohup consul agent -server -data-dir=/tmp/consul -node=server-12 -bind=192.168.56.101 -bootstrap-expect 1 -client 0.0.0.0 -ui -dc=zjgdc &
#clientAgent-1 啓動
# [root@localhost bin]# nohup consul agent -data-dir=/tmp/consul -node=client-13 -bind=192.168.56.103 -join=192.168.56.101 -dc=zjgdc &
#clientAgent-2 啓動
# [root@localhost bin]# nohup consul agent -data-dir=/tmp/consul -node=client-14 -bind=192.168.56.102 -join=192.168.56.101 -dc=zjgdc &
各命令和選項含義
# consul agent : 表示該命令會啓動一個 consulAgent
#-server :表示 agent 是一個 serverAgent,不添加這個選項的話,表示是一個 clientAgent
# -data-dir:表示相關數據存儲的目錄位置,在 serverAgent 上該目錄下會存儲集羣的狀態信息,而在 clientAgent 上主要混在其上註冊的服務信息以及這些服務的健康檢查信息。
# -node:指定該 agent 節點的名稱,該,名稱在集羣中必須是唯一的(默認採用機器 host)。
# -bind:指定該 agent 的 ip。
# -bootstrap-expect 1 :該命令通知 Consul 我們仙子阿準備加入的 server 節點個數,該參數是爲了延遲日誌複製的啓動,知道指定數量的 sever 節點成功後才啓動。
# -client 0.0.0.0 -ui:啓動 Consul-ui,如果不添加“-client 0.0.0.0”選項,則UI只能在本機器上訪問。
# -dc:指定該 agent 加入哪一個數據中心,默認是 dc1.
# -join:將節點加入集羣。
3、查看各個節點是否正常
# consul members
# 成功結果
[root@localhost ~]# consul members
Node Address Status Type Build Protocol DC
client-13 192.168.56.103:8301 alive client 0.7.2 2 zjgdc
client-14 192.168.56.102:8301 alive client 0.7.2 2 zjgdc
server-12 192.168.56.101:8301 alive server 0.7.2 2 zjgdc