运行Consul代理
Consul 是典型的C/S架构,可以运行在 服务模式 或 客户模式
每一个数据中心必须有至少一个服务节点,3到5个服务节点最好,非常不建议只运行一个服务节点,因为在节点失效的情况下数据有极大的丢失风险
其它的所有节点都运行在客户端模式下,一个客户节点是非常轻量的注册服务进程,用来处理健康检查,转发请求到服务节点等事务,代理必须在集群中的每个节点上运行
以开发模式运行 Consul,这个模式可以快速启动一个单节点集群,但是由于并不保存状态,所以不要在生产环境中使用
代码语言:javascript复制[root@h104 consul]# consul agent -dev -bind=0.0.0.0
==> Starting Consul agent...
==> Error starting agent: Failed to get advertise address: Multiple private IPs found. Please configure one.
[root@h104 consul]# consul agent -dev -bind=192.168.100.104
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Consul agent running!
Node name: 'h104'
Datacenter: 'dc1'
Server: true (bootstrap: false)
Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
Cluster Addr: 192.168.100.104 (LAN: 8301, WAN: 8302)
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
Atlas: <disabled>
==> Log data will now stream in as it occurs:
2016/03/18 16:18:56 [INFO] serf: EventMemberJoin: h104 192.168.100.104
2016/03/18 16:18:56 [INFO] serf: EventMemberJoin: h104.dc1 192.168.100.104
2016/03/18 16:18:56 [INFO] raft: Node at 192.168.100.104:8300 [Follower] entering Follower state
2016/03/18 16:18:56 [INFO] consul: adding LAN server h104 (Addr: 192.168.100.104:8300) (DC: dc1)
2016/03/18 16:18:56 [INFO] consul: adding WAN server h104.dc1 (Addr: 192.168.100.104:8300) (DC: dc1)
2016/03/18 16:18:56 [ERR] agent: failed to sync remote state: No cluster leader
2016/03/18 16:18:57 [WARN] raft: Heartbeat timeout reached, starting election
2016/03/18 16:18:57 [INFO] raft: Node at 192.168.100.104:8300 [Candidate] entering Candidate state
2016/03/18 16:18:57 [DEBUG] raft: Votes needed: 1
2016/03/18 16:18:57 [DEBUG] raft: Vote granted from 192.168.100.104:8300. Tally: 1
2016/03/18 16:18:57 [INFO] raft: Election won. Tally: 1
2016/03/18 16:18:57 [INFO] raft: Node at 192.168.100.104:8300 [Leader] entering Leader state
2016/03/18 16:18:57 [INFO] raft: Disabling EnableSingleNode (bootstrap)
2016/03/18 16:18:57 [INFO] consul: cluster leadership acquired
2016/03/18 16:18:57 [DEBUG] raft: Node 192.168.100.104:8300 updated peer set (2): [192.168.100.104:8300]
2016/03/18 16:18:57 [DEBUG] consul: reset tombstone GC to index 2
2016/03/18 16:18:57 [INFO] consul: member 'h104' joined, marking health alive
2016/03/18 16:18:57 [INFO] consul: New leader elected: h104
2016/03/18 16:18:59 [INFO] agent: Synced service 'consul'
2016/03/18 16:20:48 [DEBUG] agent: Service 'consul' in sync
2016/03/18 16:21:53 [DEBUG] agent: Service 'consul' in sync
2016/03/18 16:23:02 [INFO] agent.rpc: Accepted client: 127.0.0.1:41645
2016/03/18 16:23:32 [DEBUG] agent: Service 'consul' in sync
...
...
...