标签:$path last lse image 流言 update ges key 注册
Consul中包括的3种不同的角色:Client、Server、Server-Leader。
还有一个在图上没有标出来的角色Agent,一共4个角色。
Agent
是一个守护线程
跟随Consul应用启动而启动
负责检查、维护节点同步
Client
Server
Server-Leader
服务注册的方式
HTTP API
http://{ip}:8500/v1/agent/service/register/:service
JSON 配置文件
{
"services": [
{
"id": "serverId",
"name": "serverName",
"tags": [
"primary"
],
"address": "127.0.0.1",
"port": 9003,
"checks": [
{
"id": "api-servie",
"name": "Service 'xx' check",
"http": "http://127.0.0.1:9003/public/health",
"method": "GET",
"interval": "10s",
"timeout": "1s"
}
]
}
]
启动增加参数: -config-dir
nohup ./consul agent -dev -config-dir=/consul-conf/service.json &
服务发现的方式
HTTP API
获取某个service下健康的服务列表信息
http://{ip}:8500/v1/health/service/:service
DNS Agent
工作流程
这次我们以二进制包方式搭建, 其实还有docker的方式。
我使用的系统为ubuntu18.04LTS
集群规划:node01, node02, node03, node04, node05上都安装
集群前置准备请参考: https://www.cnblogs.com/ronnieyuan/p/11461377.html
上传二进制包并解压到指定目录
unzip consul_1.6.2_linux_amd64.zip -d /usr/bin
解压后直接就是一个可执行文件了
vim ~/.bashrc 修改环境变量
# Consul
export CONSUL_HOME=/usr/bin/consul
export PATH=$PATH:CONSUL_HOME
验证Consul安装是否成功
root@node01:/home/ronnie/soft# consul version
Consul v1.6.2
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)
root@node01:/home/ronnie/soft# vim ~/.bashrc
将二进制文件拷贝至其他几台虚拟机上, 记得修改配置文件
cd /usr/bin/
scp consul root@node02:`pwd`
scp consul root@node03:`pwd`
scp consul root@node04:`pwd`
scp consul root@node05:`pwd`
分别在五台虚拟机上输入以下对应的命令
# node01
consul agent -server -ui -bootstrap-expect=5 -data-dir=/data/consul -node=agent-1 -client=0.0.0.0 -bind=192.168.180.130 -datacenter=dc1
# node02
consul agent -server -ui -bootstrap-expect=5 -data-dir=/data/consul -node=agent-2 -client=0.0.0.0 -bind=192.168.180.131 -datacenter=dc1 -join 192.168.180.130
# node03
consul agent -server -ui -bootstrap-expect=5 -data-dir=/data/consul -node=agent-3 -client=0.0.0.0 -bind=192.168.180.132 -datacenter=dc1 -join 192.168.180.130
# node04
consul agent -server -ui -bootstrap-expect=5 -data-dir=/data/consul -node=agent-4 -client=0.0.0.0 -bind=192.168.180.133 -datacenter=dc1 -join 192.168.180.130
# node05
consul agent -server -ui -bootstrap-expect=5 -data-dir=/data/consul -node=agent-5 -client=0.0.0.0 -bind=192.168.180.134 -datacenter=dc1 -join 192.168.180.130
命令解读:
启动成功案例
==> bind_addr cannot be empty
root@node02:~# consul agent -server -ui -bootstrap-expect=5 -data-dir=/data/consul -node=agent-2 -client=0.0.0.0 -bind=192.168.180.131 -datacenter=dc1 -join 192.168.180.130
bootstrap_expect > 0: expecting 5 servers
==> Starting Consul agent...
Version: 'v1.6.2'
Node ID: '304a1a5a-2987-e7ad-738d-7d21f9dbd887'
Node name: 'agent-2'
Datacenter: 'dc1' (Segment: '<all>')
Server: true (Bootstrap: false)
Client Addr: [0.0.0.0] (HTTP: 8500, HTTPS: -1, gRPC: -1, DNS: 8600)
Cluster Addr: 192.168.180.131 (LAN: 8301, WAN: 8302)
Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false, Auto-Encrypt-TLS: false
==> Log data will now stream in as it occurs:
2019/11/29 22:19:15 [INFO] raft: Initial configuration (index=0): []
2019/11/29 22:19:15 [INFO] raft: Node at 192.168.180.131:8300 [Follower] entering Follower state (Leader: "")
2019/11/29 22:19:15 [INFO] serf: EventMemberJoin: agent-2.dc1 192.168.180.131
2019/11/29 22:19:15 [INFO] serf: EventMemberJoin: agent-2 192.168.180.131
2019/11/29 22:19:15 [INFO] consul: Adding LAN server agent-2 (Addr: tcp/192.168.180.131:8300) (DC: dc1)
2019/11/29 22:19:15 [INFO] agent: Started DNS server 0.0.0.0:8600 (udp)
2019/11/29 22:19:15 [INFO] consul: Handled member-join event for server "agent-2.dc1" in area "wan"
2019/11/29 22:19:15 [INFO] agent: Started DNS server 0.0.0.0:8600 (tcp)
2019/11/29 22:19:15 [INFO] agent: Started HTTP server on [::]:8500 (tcp)
==> Joining cluster...
2019/11/29 22:19:15 [INFO] agent: (LAN) joining: [192.168.180.130]
2019/11/29 22:19:15 [INFO] serf: EventMemberJoin: agent-1 192.168.180.130
2019/11/29 22:19:15 [INFO] agent: (LAN) joined: 1
Join completed. Synced with 1 initial agents
2019/11/29 22:19:15 [INFO] agent: started state syncer
==> Consul agent running!
2019/11/29 22:19:15 [INFO] consul: Adding LAN server agent-1 (Addr: tcp/192.168.180.130:8300) (DC: dc1)
2019/11/29 22:19:15 [INFO] serf: EventMemberJoin: agent-1.dc1 192.168.180.130
2019/11/29 22:19:15 [INFO] consul: Handled member-join event for server "agent-1.dc1" in area "wan"
2019/11/29 22:19:17 [INFO] serf: EventMemberJoin: agent-3.dc1 192.168.180.132
2019/11/29 22:19:17 [INFO] consul: Handled member-join event for server "agent-3.dc1" in area "wan"
2019/11/29 22:19:17 [INFO] serf: EventMemberJoin: agent-3 192.168.180.132
2019/11/29 22:19:17 [INFO] consul: Adding LAN server agent-3 (Addr: tcp/192.168.180.132:8300) (DC: dc1)
2019/11/29 22:19:17 [INFO] serf: EventMemberJoin: agent-4.dc1 192.168.180.133
2019/11/29 22:19:17 [INFO] consul: Handled member-join event for server "agent-4.dc1" in area "wan"
2019/11/29 22:19:18 [INFO] serf: EventMemberJoin: agent-4 192.168.180.133
2019/11/29 22:19:18 [INFO] consul: Adding LAN server agent-4 (Addr: tcp/192.168.180.133:8300) (DC: dc1)
2019/11/29 22:19:18 [INFO] serf: EventMemberJoin: agent-5 192.168.180.134
2019/11/29 22:19:18 [INFO] consul: Adding LAN server agent-5 (Addr: tcp/192.168.180.134:8300) (DC: dc1)
2019/11/29 22:19:18 [INFO] consul: Existing Raft peers reported by agent-5, disabling bootstrap mode
2019/11/29 22:19:18 [INFO] serf: EventMemberJoin: agent-5.dc1 192.168.180.134
2019/11/29 22:19:18 [INFO] consul: Handled member-join event for server "agent-5.dc1" in area "wan"
2019/11/29 22:19:19 [WARN] raft: Failed to get previous log: 1 log not found (last: 0)
2019/11/29 22:19:19 [INFO] agent: Synced node info
2019/11/29 22:19:19 [INFO] consul: New leader elected: agent-1
==> Failed to check for updates: Get https://checkpoint-api.hashicorp.com/v1/check/consul?arch=amd64&os=linux&signature=6977bf57-e750-2607-d65d-fa3ab1444055&version=1.6.2: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
在浏览器上访问node01节点的8500端口
那么本次集群的安装就到此为止了
标签:$path last lse image 流言 update ges key 注册
原文地址:https://www.cnblogs.com/ronnieyuan/p/11960696.html