Consul的安裝與試用
2016-5-23
一)安裝在RedHat7.2上
1. [email protected] info
[[email protected]]# uname -a
Linuxip-172-30-0-43.ec2.internal 3.10.0-327.el7.x86_64 #1 SMP Thu Oct 2917:29:29 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
[[email protected]]# cat /etc/redhat-release
RedHat Enterprise Linux Server release 7.2 (Maipo)
2. 安裝
主頁https://www.consul.io/
當然 版本
https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip
下載, 然後unzip
解壓, 得到唯一個可執行檔案
wgethttps://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip
unzipconsul_0.6.4_linux_amd64.zip
檢查一下版本
[[email protected]]# ./consul version
Consulv0.6.4
ConsulProtocol: 3 (Understands back to: 1)
3. 以Bootstrap Server
模式 啟動
./consulagent -server -bootstrap-expect=1 -data-dir /tmp/consul
./consulagent -server -bootstrap -data-dir /tmp/consul
輸出如下:
[[email protected]]# ./consul agent -server -bootstrap-expect=1 -data-dir/tmp/consul
==>WARNING: BootstrapExpect Mode is specified as 1; this is the same asBootstrap mode.
==>WARNING: Bootstrap mode enabled! Do not enable unless necessary
==>Starting Consul agent…
==>Starting Consul agent RPC…
==>Consul agent running!
Nodename: ‘ip-172-30-0-43.ec2.internal’
Datacenter:’dc1′
Server:true (bootstrap: true)
ClientAddr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
ClusterAddr: 172.30.0.43 (LAN: 8301, WAN: 8302)
Gossipencrypt: false, RPC-TLS: false, TLS-Incoming: false
Atlas:<disabled>
……(省略)……
4. 檢視,成員info等
[[email protected]]# ./consul members
Node Address Status Type Build Protocol DC
ip-172-30-0-43.ec2.internal 172.30.0.43:8301 alive server 0.6.4 2 dc1
[[email protected]]# ./consul members -detailed
Node Address Status Tags
ip-172-30-0-43.ec2.internal 172.30.0.43:8301 alive bootstrap=1,build=0.6.4:26a0ef8c,dc=dc1,port=8300,role=consul,vsn=2,vsn_max=3,vsn_min=1
[[email protected]]# ./consul info
agent:
check_monitors= 0
check_ttls= 0
checks= 0
services= 1
build:
……(省略)……
二)服務的註冊與發現
1. 節點的基本情況
兩臺Node:
ip-172-30-0-43 RedHat7.2 172.30.0.43Server
ip-172-30-0-89 Amazon(4.1.10)172.30.0.89 Server
2. 執行的主要命令
引數-bootstrap-expect=2指明 是兩臺server
/home/consul/consulagent -server -bootstrap-expect=2 -data-dir /tmp/consul-node=ip-172-30-0-43 -bind=172.30.0.43 -dc=dc1
/home/consul/consulagent -server -bootstrap-expect=2 -data-dir /tmp/consul-node=ip-172-30-0-89 -bind=172.30.0.89 -dc=dc1
/home/consul/consuljoin 172.30.0.89
3. 控制檯輸出
[[email protected]]# /home/consul/consul agent -server -bootstrap-expect=2 -data-dir/tmp/consul -node=ip-172-30-0-43 -bind=172.30.0.43 -dc=dc1
==>WARNING: Expect Mode enabled, expecting 2 servers
==>Starting Consul agent…
==>Starting Consul agent RPC…
==>Consul agent running!
Nodename: ‘ip-172-30-0-43’
Datacenter:’dc1′
Server:true (bootstrap: false)
ClientAddr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
ClusterAddr: 172.30.0.43 (LAN: 8301, WAN: 8302)
Gossipencrypt: false, RPC-TLS: false, TLS-Incoming: false
Atlas:<disabled>
==>Log data will now stream in as it occurs:
2016/05/1601:48:46 [INFO] serf: EventMemberJoin: ip-172-30-0-43 172.30.0.43
2016/05/1601:48:46 [INFO] serf: EventMemberJoin: ip-172-30-0-43.dc1 172.30.0.43
2016/05/1601:48:46 [INFO] raft: Node at 172.30.0.43:8300 [Follower] enteringFollower state
2016/05/1601:48:46 [INFO] consul: adding LAN server ip-172-30-0-43 (Addr:172.30.0.43:8300) (DC: dc1)
2016/05/1601:48:46 [INFO] consul: adding WAN server ip-172-30-0-43.dc1 (Addr:172.30.0.43:8300) (DC: dc1)
2016/05/1601:48:46 [ERR] agent: failed to sync remote state: No cluster leader
2016/05/1601:48:47 [WARN] raft: EnableSingleNode disabled, and no known peers.Aborting election.
2016/05/1601:48:56 [INFO] agent.rpc: Accepted client: 127.0.0.1:41616
2016/05/1601:48:56 [INFO] agent: (LAN) joining: [172.30.0.89]
2016/05/1601:48:56 [INFO] serf: EventMemberJoin: ip-172-30-0-89 172.30.0.89
2016/05/1601:48:56 [INFO] agent: (LAN) joined: 1 Err: <nil>
2016/05/1601:48:56 [INFO] consul: adding LAN server ip-172-30-0-89 (Addr:172.30.0.89:8300) (DC: dc1)
2016/05/1601:48:56 [INFO] consul: Attempting bootstrap with nodes:[172.30.0.43:8300 172.30.0.89:8300]
2016/05/1601:48:57 [INFO] consul: New leader elected: ip-172-30-0-89
2016/05/1601:49:00 [INFO] agent: Synced service ‘consul’
[[email protected]]# /home/consul/consul agent -server -bootstrap-expect=2 -data-dir/tmp/consul -node=ip-172-30-0-89 -bind=172.30.0.89 -dc=dc1
==>WARNING: Expect Mode enabled, expecting 2 servers
==>Starting Consul agent…
==>Starting Consul agent RPC…
==>Consul agent running!
Nodename: ‘ip-172-30-0-89’
Datacenter:’dc1′
Server:true (bootstrap: false)
ClientAddr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
ClusterAddr: 172.30.0.89 (LAN: 8301, WAN: 8302)
Gossipencrypt: false, RPC-TLS: false, TLS-Incoming: false
Atlas:<disabled>
==>Log data will now stream in as it occurs:
2016/05/1605:48:50 [INFO] serf: EventMemberJoin: ip-172-30-0-89 172.30.0.89
2016/05/1605:48:50 [INFO] serf: EventMemberJoin: ip-172-30-0-89.dc1 172.30.0.89
2016/05/1605:48:50 [INFO] raft: Node at 172.30.0.89:8300 [Follower] enteringFollower state
2016/05/1605:48:50 [INFO] consul: adding LAN server ip-172-30-0-89 (Addr:172.30.0.89:8300) (DC: dc1)
2016/05/1605:48:50 [INFO] consul: adding WAN server ip-172-30-0-89.dc1 (Addr:172.30.0.89:8300) (DC: dc1)
2016/05/1605:48:50 [ERR] agent: failed to sync remote state: No cluster leader
2016/05/1605:48:51 [WARN] raft: EnableSingleNode disabled, and no known peers.Aborting election.
2016/05/1605:48:56 [INFO] serf: EventMemberJoin: ip-172-30-0-43 172.30.0.43
2016/05/1605:48:56 [INFO] consul: adding LAN server ip-172-30-0-43 (Addr:172.30.0.43:8300) (DC: dc1)
2016/05/1605:48:56 [INFO] consul: Attempting bootstrap with nodes:[172.30.0.89:8300 172.30.0.43:8300]
2016/05/1605:48:57 [WARN] raft: Heartbeat timeout reached, starting election
2016/05/1605:48:57 [INFO] raft: Node at 172.30.0.89:8300 [Candidate] enteringCandidate state
2016/05/1605:48:57 [INFO] raft: Election won. Tally: 2
2016/05/1605:48:57 [INFO] raft: Node at 172.30.0.89:8300 [Leader] enteringLeader state
2016/05/1605:48:57 [INFO] consul: cluster leadership acquired
2016/05/1605:48:57 [INFO] consul: New leader elected: ip-172-30-0-89
2016/05/1605:48:57 [INFO] raft: pipelining replication to peer 172.30.0.43:8300
2016/05/1605:48:57 [INFO] consul: member ‘ip-172-30-0-89’ joined, markinghealth alive
2016/05/1605:48:57 [INFO] consul: member ‘ip-172-30-0-43’ joined, markinghealth alive
2016/05/1605:48:59 [INFO] agent: Synced service ‘consul’
[[email protected]~]# /home/consul/consul join 172.30.0.89
Successfullyjoined cluster by contacting 1 nodes.
[[email protected]~]# /home/consul/consul members
Node Address Status Type Build Protocol DC
ip-172-30-0-43 172.30.0.43:8301 alive server 0.6.4 2 dc1
ip-172-30-0-89 172.30.0.89:8301 alive server 0.6.4 2 dc1
[[email protected]~]# tree /tmp/consul/
/tmp/consul/
├── checkpoint-signature
├── raft
│ ├── peers.json
│ ├── raft.db
│ └── snapshots
└── serf
├── local.snapshot
└── remote.snapshot
3 directories, 5 files
輸入Ctrl C
後,停止服務, 輸出如下:
^C==>Caught signal: interrupt
==>Gracefully shutting down agent…
2016/05/1603:03:30 [INFO] consul: server starting leave
2016/05/1603:03:30 [INFO] serf: EventMemberLeave: ip-172-30-0-43.dc1172.30.0.43
2016/05/1603:03:30 [INFO] consul: removing WAN server ip-172-30-0-43.dc1 (Addr:172.30.0.43:8300) (DC: dc1)
2016/05/1603:03:31 [INFO] serf: EventMemberLeave: ip-172-30-0-43 172.30.0.43
2016/05/1603:03:31 [INFO] consul: removing LAN server ip-172-30-0-43 (Addr:172.30.0.43:8300) (DC: dc1)
2016/05/1603:03:31 [INFO] raft: Removed ourself, transitioning to follower
2016/05/1603:03:32 [INFO] agent: requesting shutdown
2016/05/1603:03:32 [INFO] consul: shutting down server
2016/05/1603:03:32 [ERR] dns: error starting tcp server: accept tcp127.0.0.1:8600: use of closed network connection
2016/05/1603:03:32 [INFO] agent: shutdown complete
4. 儲存值
利用開啟的8500http服務,儲存某些值。
[[email protected]]#
curl -X PUT -d ‘bar’http://localhost:8500/v1/kv/foo
true[[email protected]]#
[[email protected]]#
curlhttp://localhost:8500/v1/kv/foo
[{“LockIndex”:0,”Key”:”foo”,”Flags”:0,”Value”:”YmFy”,”CreateIndex”:144,”ModifyIndex”:144}][[email protected]]#
[[email protected]]# echo “YmFy” | base64 –decode
bar[[email protected]]#
5. 其他
重啟,但加上-rejoin命令:
如:
/home/consul/consulagent -server -bootstrap-expect=2 -data-dir /tmp/consul-node=ip-172-30-0-43 -bind=172.30.0.43 -dc=dc1 -rejoin
退出, 使用consul leave
命令
三)進一步的思考與問題
1. 幾種一致性演算法或者相關概念
GOSSIP,CONSENSUS, SERF
2. 相關的產品
ZooKeeper, doozerd, etcd
Chef, Puppet, etc.
Nagios, Sensu
SkyDNS
SmartStack
Serf
3. 多資料中心,
延遲? 配置?
如何寫入資料?指令碼 (curl
寫http請求?)
分裂?一個資料中心, 分裂成兩個或多個
4. 某一個server退出(leave命令)重新加入, 有問題,
不能正確選舉leader
?
5. 發現IBM的一些資料如:
藉助Consul和Docker支援即插即用的服務發現(servicediscovery)
準備進一步學習….
写评论
很抱歉,必須登入網站才能發佈留言。