kong結合consul


  • 早期版本

./etcdctl ls / --recursive

/name
/name1
/name1/wyc
/name1/wu
/name1/chao
/name1/chao/age

./etcdctl -o extended get /name1/wyc

Key: /name1/wyc
Created-Index: 8
Modified-Index: 8
TTL: 0
Index: 9

11

./etcdctl watch /name1/wyc

當修改這個鍵的時候,watch就會輸出最新的值並退出
--forever 一直監測直到用戶按CTRL+C退出



curl -L http://localhost:2379/v2/keys/name

=========

kong

負載均衡

1.基於dns的負載均衡,后端服務的注冊在kong之外完成,kong只接收來自dns服務器的更新。dns的ttl(time to live)決定了信息被刷新的頻率,


kong with consul:

use consul as a dns server, then you'll have to live with TTL expiry times. Alternatively run a script on changes (services added/removed) to add a target entity through the Kong management api。

consul角色
1.agent是在consul集群中每個機器成員中運行的一個常駐進程。可以當做server或者server的身份運行。所有agent都可以運行dns或者http接口,並且執行健康檢查和保持服務信息的同步。
2.client是一個agent,將rpc調用轉向對應的服務。client是無狀態的。唯一的在后台執行的邏輯就是加入Gossip同步池。
3.server同樣是一個agent,職責包括實現集群的一致性,維護集群狀態,響應rpc請求,與其他數據中心交換數據。

consul發現服務
consul提供了dns和http兩種查詢服務的方式。DNS 服務的默認端口設置為8600。Consul 服務被放置在 .consul 的命名空間下,DNS 查詢的基礎規則為 SERVICENAME.service.consul。其中 service 子域表示查詢服務,SERVICENAME正是查詢服務的名稱。除了通過 DNS API,HTTP 服務也可用於服務查詢。

consul使用

  1. 啟動consul服務 consul agent -server -bootstrap -data-dir /tmp/consul -node=consul1 -bind 172.0.0.10
  2. 啟動consul服務 consul agent -server -data-dir /tmp/consul -node=consul2 -bind 172.0.0.11 -join 172.0.0.10
  3. 啟動業務服務(監聽8045) consul agent -data-dir /tmp/consul -node=service1 -config-dir /etc/consul.d -bind 172.0.0.13 -join 172.0.0.10
    在節點啟動腳本中,我們已經將業務服務的定義信息寫入/etc/consul.d/mysvc.json文件。這樣在 Consul 客戶端服務啟動之后,就能將服務的信息同步到集群中的所有節點。
    mysvc.json:
{
    "service": {
        "name": "my-svc",
        "tags": [
            "microservice"
        ],
        "port": 8045,
        "check": {
            "script": "curl localhost:8045/status | grep OK || exit 2",
            "interval": "5s"
        }
    }
}

{
  "service": {
    "name": "web3",
    "tags": ["master"],
    "address": "127.0.0.1",
    "port": 10000,
    "checks": [
      {
        "http": "http://localhost:10000/health",
        "interval": "10s"
      }
    ]
  }
}

4.機器節點,用於查看集群狀態 consul agent -client=172.0.0.12 -ui-dir /vagrant/web/ -data-dir /tmp/consul -node=status -bind 172.0.0.12 -join 172.0.0.10

ui

http://localhost:8500/ui/#/dc1/nodes



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM