consul的集部署
consul的原理
Consul包含多个组件,但是作为⼀个整体,为你的基础设施提供服务发现和服务配置的⼯具.他提供以下关键特性:
服务发现以及注册:
当服务Producer 启动时,会将⾃⼰的Ip/host等信息通过发送请求告知 Consul,Consul 接收到 Producer 的注册信息后,每隔⼀段时间会向 Producer 发送⼀个健康检查的请求,检验Producer是否健康。
服务调⽤:
当 Consumer 请求Product时,会先从 Consul 中拿到存储Product服务的 IP 和 Port 的临时表(temp table),从temp table表中任选⼀个· Producer 的 IP 和 Port, 然后根据这个IP和Port,发送访问请求;temp table表只包含通过了健康检查的 Producer 信息,并且每隔⼀段时间更新
consul --hlep查看启动指令:
acl            与 Consul 的ACL进⾏交互
agent          运⾏⼀个 Consul agent
catalog        与 Consul 的⽬录进⾏交互
config        与 Consul 的配置进⾏交互
connect        与 Consul 的Connect⼦系统进⾏交互
debug          记录 Consul operators 的调试归档
event          触发⼀个新事件
exec          在 Consul 节点上执⾏命令
force-leave    强制⼀个集成员进⼊离开状态,⼀般⽤来强制删除发⽣故障或已关闭且没有正常离开的节点
info          对 Consul operators 提供调试的信息
intention      与通过Connect对服务的访问控制交互
join          将 Consul agent 加⼊集
keygen        ⽣成新的加密密钥
keyring        检查和修改 gossip 池中使⽤的加密密钥
kv            与 k/v 存储进⾏交互
leave          Consul agent 正常离开集并关闭
lock          在 k/v 存储中的给定前缀处创建⼀个锁
login          使⽤所请求的auth⽅法将提供的第三⽅凭据交换为新创建的 Consul ACL令牌
logout        销毁从 consul login 命令中创建的 Consul 令牌
maint          提供对节点或服务的维护模式的控制
members        列出 Consul 集的所有成员
monitor        ⽤于连接并追踪正在运⾏的 Consul agent 的⽇志
operator      为 Consul operators 提供集级别的⼯具
reload        触发 agent 配置⽂件的重载
rtt            估计两个节点之间的⽹络往返时间
services      与注册的服务进⾏交互
snapshot      保存、还原和检查 Consul Server 状态以进⾏灾难恢复
tls            内置帮助创建Consul TLS的CA和证书
validate      对 Consul 的配置⽂件或⽬录执⾏完整性测试
version        显⽰ Consul 版本信息
watch          监视 Consul 特定数据视图(节点列表,服务成员,k/v等)中的更改
consul的启动
单机启动dev模式
consul agent -dev -client=172.16.110.11
单机模式,不具有⾼可⽤性,下⾯介绍集模式
consul的集安装
主机ip⾓⾊
node-4172.16.110.10client
node-1172.16.110.11server
node-2172.16.110.12server
node-3172.16.110.13server
主机ip⾓⾊
创建 consul server:
mkdir -p /usr/local/consul/{config,data,log}
nohup consul agent -server -bootstrap-expect=3  -data-dir=/usr/local/consul/data -config-dir=/usr/local/consul/config  -node=agent11 -bind=172.16.110.11 -client 0.0.0.0 -ui &> /usr/local/consul/log/consul.log &
参数:
-node:节点的名称
-bind:绑定的⼀个地址,⽤于节点之间通信的地址,可以是内外⽹,必须是可以访问到的地址
-server:表⽰这个节点是个Server
-bootstrap-expect:表⽰期望提供的Server节点数⽬。数⽬⼀达到,它就会被激活,然后就是leader了
-data-dir:Agent⽤于存储状态的数据⽬录,这是所有Agent所必需的
-datacenter:指明数据中⼼的名字,默认是"dc1"。同⼀数据中⼼中的节点应位于单个LAN上
-client:将Client接⼝(包括HTTP和DNS服务器)绑定到的地址
-ui:启动UI
其他两台机器也创建 consul server,与 172.21.110.11 类似。
mkdir -p /usr/local/consul/{config,data,log}
nohup consul agent -server -bootstrap-expect=3  -data-dir=/usr/local/consul/data -config-dir=/usr/local/consul/config  -node=agent12 -bind=172.16.110.12 -client 0.0.0.0 -ui &> /usr/local/consul/log/consul.log &
connect和join的区别mkdir -p /usr/local/consul/{config,data,log}
nohup consul agent -server -bootstrap-expect=3  -data-dir=/usr/local/consul/data -config-dir=/usr/loca
l/consul/config  -node=agent13 -bind=172.16.110.13 -client 0.0.0.0 -ui &> /usr/local/consul/log/consul.log &
创建 consul client
mkdir -p /usr/local/consul/client/{config,log}
consul agent -data-dir=//usr/local/consul/client/ \
-node=agent10 -bind=172.16.110.10 \
-enable-script-checks=true -config-dir=/usr/local/consul/client/config \
-client 0.0.0.0 -ui &> /usr/local/consul/client/log/consul.log &
加⼊集
除172.16.110.11 外的其他机器加⼊集
#另外3台机器都要加⼊,执⾏以下指令
consul join 172.16.110.11
可以看得,集中有3个server和1个client,它们在数据中⼼dc1中。实际中我们只有3台机器,如下所⽰,可以看到3个server,但是该三台机器也可以充当client。
API形式注册数据
curl -X PUT -d '{"id": "redis","name": "redis-service","address": "172.16.110.13","port": 9121,"tags": ["redis"],"meta": {"idc":"senhua"},"checks": [{"http": "http:/ /172.16.110.13:9121/metrics", "interval": "5s"}]}'  172.16.110.10:8500/v1/agent/service/register
API形式注销数据
curl -X PUT  172.16.110.10:8500/v1/agent/service/deregister/{id}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。