1.consul安裝
1.1 先安裝go環境
2.2 wget https://releases.hashicorp.com/consul/1.4.0/consul_1.4.0_linux_amd64.zip
unzip consul_1.4.0_linux_amd64.zip
mv consul /usr/local/go/bin/
consul -v //成功
2.開始使用
2.1運行consul agent
consul agent -dev
2.2 查看集羣成員
consul members -- -detailed 可查看詳細信息
curl http://localhost:8500/v1/catalog/nodes
2.3 註冊服務
mkdir /etc/consul.d -- ".d"結尾指目錄包含一組配置文件
vi /etc/consul.d /web.json
{
"service": {
"name": "web",
"tags": ["rails"],
"address": "114.55.40.20",
"port": 80
}
}
consul agent -dev -config-dir=/etc/consul.d --設置配置目錄,啓動代理
結果
2.4 發現服務
dig @127.0.0.1 -p 8600 web.service.consul --使用DNS查詢服務
結果
curl http://localhost:8500/v1/catalog/service/web --api查詢
結果
curl http://localhost:8500/v1/health/service/web --查詢健康實例
結果