工作中用到Consul,把基本的概念和使用研究一下。
安装
1 | [root@Automation ~]# cd /usr/local/bin |
验证:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26[root@Automation bin]# consul
Usage: consul [--version] [--help] <command> [<args>]
Available commands are:
agent Runs a Consul agent
catalog Interact with the catalog
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
keyring Manages gossip layer encryption keys
kv Interact with the key-value store
leave Gracefully leaves the Consul cluster and shuts down
lock Execute a command holding a lock
maint Controls node or service maintenance mode
members Lists the members of a Consul cluster
monitor Stream logs from a Consul agent
operator Provides cluster-level tools for Consul operators
reload Triggers the agent to reload configuration files
rtt Estimates network round trip time between nodes
snapshot Saves, restores and inspects snapshots of Consul server state
validate Validate config files/directories
version Prints the Consul version
watch Watch for changes in Consul
运行代理
在Consul安装完成后,要先运行代理。该代理可以以服务器或者客户端模式运行。每个数据中心必须有至少一个服务器,不过一个集群推荐3或5个服务器。
启动代理
通过Docke启动Consul容器1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16[root@Automation bin]# consul agent -dev
==> Starting Consul agent...
==> Consul agent running!
Version: 'v1.0.2'
Node ID: 'a1ed3e1e-d9b2-579b-bdcc-d6fb13a2b3e3'
Node name: 'Automation'
Datacenter: 'dc1' (Segment: '<all>')
Server: true (Bootstrap: false)
Client Addr: [127.0.0.1] (HTTP: 8500, HTTPS: -1, DNS: 8600)
Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false
==> Log data will now stream in as it occurs:
2017/12/25 15:25:25 [DEBUG] Using random ID "a1ed3e1e-d9b2-579b-bdcc-d6fb13a2b3e3" as node ID
2017/12/25 15:25:25 [INFO] raft: Initial configuration (index=1): [{Suffrage:Voter ID:a1ed3e1e-d9b2-579b-bdcc-d6fb13a2b3e3 Address:127.0.0.1:8300}]
集群成员
在另一个终端中运行 consul members ,你能看到Consul集群所有的节点。1
2
3/ # consul members
Node Address Status Type Build Protocol DC Segment
fd383e11f665 127.0.0.1:8301 alive server 1.0.2 2 dc1 <all>
停止代理
这个比较容易,Ctrl+C就搞定了。