consul平常操做命令

#開發模式運行agent
consul agent -dev
#查看consul 集羣成員 consul members [-detailed]

 

members命令的輸出基於gossip協議,並最終一致。 也就是說,在任什麼時候候,當地代理所看到的可能與服務器上的狀態不徹底一致。 要得到徹底一致,請使用HTTP API再將HTTP請求轉發給Consul服務器:
curl localhost:8500/v1/catalog/nodes
除了HTTP API以外,還能夠使用DNS接口查詢節點。

consul的服務能夠經過提供服務定義或經過對HTTP API進行適當的調用來註冊。node

服務定義步驟:web

1.建立consul配置目錄json

mkdir /etc/consul.d 

2.編寫服務定義配置文件bootstrap

#web service 80port
echo '{"service": {"name": "web", "tags": ["rails"], "port": 80}}' | sudo tee /etc/consul.d/web.json 

3.使用參數  -config-dir=config-path啓動代理程序api

consul agent -dev -config-dir=/etc/consul.d

 

當代理啓動而且服務同步後,咱們能夠使用dns或者http api來查詢服務。服務器

curl http://localhost:8500/v1/catalog/service/webcurl

 

服務定義能夠經過更改配置文件並向代理髮送SIGHUP來更新。 這使您能夠更新服務,而不會出現任何停機或沒法提供服務查詢的狀況。 或者,能夠使用HTTP API動態地添加,刪除和修改服務。url

 

啓動代理    服務器方式spa

consul agent -server -bootstrap-expect=1 -data-dir=/tmp/consul -node=agent-one -bind=192.168.65.135 -enable-script-checks=true -config-dir=/etc/consul.d

啓動代理   客戶端方式.net

consul agent -data-dir=/tmp/consul -node=agent-two -bind=192.168.65.139 -enable-script-checks=true -config-dir=/etc/consul.d/

加入consul集羣

consul join 192.168.65.135

也能夠在啓動節點的時候使用-join選項或者start_join設置來加入集羣

 

 

參考:

consul入門指南  https://blog.csdn.net/y435242634/article/details/78639663

相關文章
相關標籤/搜索