文章出處

Consul 概念(摘錄):

Consul 是 HashiCorp 公司推出的開源工具,用于實現分布式系統的服務發現與配置。與其他分布式服務注冊與發現的方案,比如 Airbnb 的 SmartStack 等相比,Consul 的方案更“一站式”,內置了服務注冊與發現框 架、分布一致性協議實現、健康檢查、Key/Value 存儲、多數據中心方案,不再需要依賴其他工具(比如 ZooKeeper 等)。使用起來也較 為簡單。Consul 用 Golang 實現,因此具有天然可移植性(支持 Linux、windows 和 Mac OS X);安裝包僅包含一個可執行文件,方便部署,與 Docker 等輕量級容器可無縫配合。

Consul 功能:

  • 服務發現(Service Discovery):客戶端通過 Consul 提供服務,其他客戶端可以通過 Consul 利用 dns 或者 http 發現依賴服務
  • 健康檢查(Health Checking): Consul 提供任務的健康檢查,可以用來操作或者監控集群的健康,也可以在服務發現時去除失效的服務
  • 鍵值對存儲(Key/Value Store): 存儲層級鍵值對
  • 多數據中心(Multi Datacenter): Consul 支持開箱即用的多數據中心

架構圖:


Mac OS 安裝(使用 homebrew):

$ brew install consul

Ubuntu 安裝:

$ wget https://releases.hashicorp.com/consul/0.7.2/consul_0.7.2_linux_amd64.zip
$ sudo apt-get install unzip

$ ls

$ unzip consul_0.7.2_linux_amd64.zip
$ sudo mv consul /usr/local/bin/consul

$ wget https://releases.hashicorp.com/consul/0.7.2/consul_0.7.2_web_ui.zip
$ unzip consul_0.7.2_web_ui.zip
$ mkdir -p /usr/share/consul
$ mv dist /usr/share/consul/ui

Consul 壓縮包地址:https://www.consul.io/downloads.html

驗證安裝是否成功:

$ consul
usage: consul [--version] [--help] <command> [<args>]

Available commands are:
    agent          Runs a Consul agent
    event          Fire a new event
    exec           Executes a command on Consul nodes
    force-leave    Forces a member of the cluster to enter the "left" state
    info           Provides debugging information for operators
    join           Tell Consul agent to join cluster
    keygen         Generates a new encryption key
    leave          Gracefully leaves the Consul cluster and shuts down
    members        Lists the members of a Consul cluster
    monitor        Stream logs from a Consul agent
    reload         Triggers the agent to reload configuration files
    version        Prints the Consul version
    watch          Watch for changes in Consul

配置 Consul(官方資料):

$ consul agent -dev
$ consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -ui  -config-dir /etc/consul.d -bind=192.168.1.100
$ consul agent -data-dir /tmp/consul -node=ubuntu64 -bind=10.9.10.176

上面三種配置說明:

  1. Sever 模式,快捷配置,一般用于調試模式,不建議使用
  2. Sever 模式
  3. Client 模式

配置參數說明:

  • -server:- Serve 模式(不配置為 Client 模式),數量一般為 3-5 個
  • -bootstrap-expect: - Server 數量
  • -data-dir: - 數據目錄
  • -ui-dir: - UI目錄
  • -node: - Node名稱
  • -bind: - 集群通訊地址

Server 模式后臺訪問地址:http://localhost:8500

其他命令:

  • consul members:查看集群成員
  • consul info:查看當前服務器的狀況
  • consul leave:退出當前服務集群
  • ctrl + c:停止服務

consul members命令示例:

Node                Address            Status  Type    Build  Protocol  DC
server1.consul.com  200.21.1.101:8301  alive   server  0.5.2  2         dc1
agent1.consul.com   200.21.1.201:8301  alive   client  0.5.2  2         dc1
agent2.consul.com   200.21.1.202:8301  alive   client  0.5.2  2         dc1
server2.consul.com  200.21.1.102:8301  alive   server  0.5.2  2         dc1
server3.consul.com  200.21.1.103:8301  alive   server  0.5.2  2         dc1
agent3.consul.com   200.21.1.203:8301  alive   client  0.5.2  2         dc1

參考資料:


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()