consule服務註冊和發現 安裝 部署

安裝部署參考

http://blog.sina.com.cn/s/blog_8ea8e9d50102wwlf.html

http://www.techweb.com.cn/network/system/2016-01-28/2270190.shtml


api連接參考 

https://github.com/JoergM/consul-examples


端口介紹

8500,客戶端http api接口
8600,客戶端DNS服務端口
8400,客戶端RPC通信端口
8300,集羣server RPC通信接口
8301,集羣DC內部通信接口
8302,集羣DC之間通信接口


consul的主要接口是RESTful HTTP API,該API可以用來增刪查改nodes、services、checks、configguration



所有的endpoints主要分爲以下類別:

kv - Key/Value存儲
agent - Agent控制
catalog - 管理nodes和services
health - 管理健康監測
session - Session操作
acl - ACL創建和管理event - 用戶Events
status - Consul系統狀態


agent endpoints:agent endpoints用來和本地agent進行交互,一般用來服務註冊和檢查註冊,支持以下接口

/v1/agent/checks : 返回本地agent註冊的所有檢查(包括配置文件和HTTP接口)
/v1/agent/services : 返回本地agent註冊的所有 服務
/v1/agent/members : 返回agent在集羣的gossip pool中看到的成員
/v1/agent/self : 返回本地agent的配置和成員信息/v1/agent/join/<address> : 觸發本地agent加入node/v1/agent/force-leave/<node>>: 強制刪除node
/v1/agent/check/register : 在本地agent增加一個檢查項,使用PUT方法傳輸一個json格式的數據/v1/agent/check/deregister/<checkID> : 註銷一個本地agent的檢查項/v1/agent/check/pass/<checkID> : 設置一個本地檢查項的狀態爲passing/v1/agent/check/warn/<checkID> : 設置一個本地檢查項的狀態爲warning/v1/agent/check/fail/<checkID> : 設置一個本地檢查項的狀態爲critical
/v1/agent/service/register : 在本地agent增加一個新的服務項,使用PUT方法傳輸一個json格式的數據/v1/agent/service/deregister/<serviceID> : 註銷一個本地agent的服務項

catalog endpoints:catalog endpoints用來註冊/註銷nodes、services、checks

/v1/catalog/register : Registers a new node, service, or check/v1/catalog/deregister : Deregisters a node, service, or check/v1/catalog/datacenters : Lists known datacenters
/v1/catalog/nodes : Lists nodes in a given DC
/v1/catalog/services : Lists services in a given DC
/v1/catalog/service/<service> : Lists the nodes in a given service
/v1/catalog/node/<node> : Lists the services provided by a node

health endpoints:health endpoints用來查詢健康狀況相關信息,該功能從catalog中單獨分離出來

/v1/healt/node/<node>: 返回node所定義的檢查,可用參數?dc=
/v1/health/checks/<service>: 返回和服務相關聯的檢查,可用參數?dc=
/v1/health/service/<service>: 返回給定datacenter中給定node中service
/v1/health/state/<state>: 返回給定datacenter中指定狀態的服務,state可以是"any", "unknown", "passing", "warning", or "critical",可用參數?dc=


session endpoints:session endpoints用來create、update、destory、query sessions

/v1/session/create: Creates a new session
/v1/session/destroy/<session>: Destroys a given session
/v1/session/info/<session>: Queries a given session
/v1/session/node/<node>: Lists sessions belonging to a node
/v1/session/list: Lists all the active sessions


acl endpoints:acl endpoints用來create、update、destory、query acl

/v1/acl/create: Creates a new token with policy
/v1/acl/update: Update the policy of a token
/v1/acl/destroy/<id>: Destroys a given token
/v1/acl/info/<id>: Queries the policy of a given token
/v1/acl/clone/<id>: Creates a new token by cloning an existing token
/v1/acl/list: Lists all the active tokens


status endpoints:status endpoints用來或者consul 集羣的信息

/v1/status/leader : 返回當前集羣的Raft leader
/v1/status/peers : 返回當前集羣中同事


服務註冊:

 1. http方式

直接調用/v1/agent/service/register接口註冊即可,需要注意的是:http method爲PUT提交方式

curl -X PUT -d '{"id": "jetty","name": "test1111","address": "localhost","port": 8500,"tags": ["dev"],"checks": [{"http": "http://localhost:8500/","interval": "5s"}]}'     http://localhost:8500/v1/agent/service/register


2:通過配置文件的方式靜態註冊
    創建文件夾/etc/consul.d 
    .d代表有許多配置文件在裏面
   vim /consul.d/jetty.json  內容如下:


{  
  "service":{  
    "id": "jetty",  
    "name": "jetty",  
    "address": "192.168.1.200",  
    "port": 8080,  
    "tags": ["dev"],  
    "checks": [  
        {  
            "http": "http://192.168.1.200:8080/health",  
            "interval": "5s"  
        }  
    ]  
  }  
}

3. 使用python api 註冊

http://python-consul.readthedocs.io/en/v0.7.0/




4.  中文consul翻譯幫助文檔

http://consul.la/intro/what-is-consul


5. consul 服務模板

https://github.com/hashicorp/consul-template




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章