Consul 安装使用

此生再无相见时 提交于 2020-03-20 18:33:55

3 月,跳不动了?>>>

Consul 安装使用

简介

Consul,服务注册发现 及 kv存储(配置中心)

文档介绍Consul部署及基本使用操作

基本概念

安装及启动

下载目录https://www.consul.io/downloads.html

安装文档https://learn.hashicorp.com/consul/datacenter-deploy/deployment-guide

架构文档https://learn.hashicorp.com/consul/datacenter-deploy/reference-architecture

1 解压zip文件放到/usr/bin 完成安装,解压后consul文件即可执行文件 运行consu -v查看释放安装完成

2 server agent启动

121主机 leader节点
nohup ./consul agent -server -ui -bootstrap -data-dir=/data/consul -node=agent-1 -client=0.0.0.0 -bind=10.46.235.121 -datacenter=dc1 &
122主机 
nohup ./consul agent -server -ui -data-dir=/data/consul -node=agent-2 -client=0.0.0.0 -bind=10.46.235.122 -datacenter=dc1 -join 10.46.235.121 &
123主机
nohup ./consul agent -server -ui -data-dir=/home/codeadmin/hell/consul-datadir -node=agent-3 -client=0.0.0.0 -bind=10.46.235.123 -datacenter=dc1 -join 10.46.235.121 &

Leader 节点挂了后会重新选举leader,重新启动不需要重新join,会基于早期日志数据自动加入集群

3 client agent 启动

124节点 client
nohup ./consul agent -data-dir /data/consul -node=client-1 -bind=10.46.235.124 -client 0.0.0.0 -log-level debug -datacenter dc1 -join 10.46.235.121 &
125节点 cleint
nohup ./consul agent -data-dir /data/consul -node=client-2 -bind=10.46.235.125 -client 0.0.0.0 -log-level debug -datacenter dc1 -join 10.46.235.121 &

命令行参数配置文档详见 https://www.consul.io/docs/agent/options.html#command-line-options

生产环境部署建议:

server agent 3台,每个主机一个agent 或 每个应用一个agent ?

consul支持两种agent部署方式,agent 宕机下面管理的应用都会被标记失效

基于consul 架构方式,建议使用每个物理机一个consul client agent方式,减少agent 进程数量,减少agents gossip成本

看github这边开发人员阐述的普通部署建议也是针对主机这边部署

https://github.com/hashicorp/consul/issues/1916

https://cloud.spring.io/spring-cloud-consul/reference/html/#spring-cloud-consul-install

端口占用

Name Port Flag Description
Server RPC 8300 Used by servers to handle incoming requests from other agents. TCP only.
Serf LAN 8301 Used to handle gossip in the LAN. Required by all agents. TCP and UDP.
Serf WAN 8302 -1 to disable (available in Consul 1.0.7) Used by servers to gossip over the LAN and WAN to other servers. TCP and UDP.
HTTP API 8500 -1 to disable Used by clients to talk to the HTTP API. TCP only.
DNS Interface 8600 -1 to disable

基础命令

查询consul成员信息

consul members
curl localhost:8500/v1/catalog/nodes

DNS interface

dig @127.0.0.1 -p 8600 Judiths-MBP.node.consul

关闭agent 优雅关闭

consul leave

注册中心

常用API

取消注册:

/catalog/deregister

EXAMPLE

curl -X PUT -H "Content-type: application/json" http://10.46.235.124:8500/v1/catalog/deregister -d '{"Datacenter":"dc1","Node":"client-1","CheckID":"service:consul-rest-server-dev-8512"}' -i

该命令移除了consul注册信息,但consul上面应用并没有立即感知到这边服务被下线,并且在下次agent 检测成功后注册上去,不适合作为正常服务重启下线方式

https://www.consul.io/api/catalog.html

配置中心

命令行读取配置:

/v1/kv/{path}?raw=trrue

http://localhost:8500/v1/kv/config/consul-kv/data?raw=true

dev模式数据存储在内存中,开发调试使用

问题

日志错误问题

[ERROR] agent: Failed to check for updates: error="Get https://checkpoint-api.hashicorp.com/v1/check/consul?arch=amd64&os=linux&signature=5565eebd-613b-1737-815f-92245a3dd9df&version=1.7.2: dial tcp: lookup checkpoint-api.hashicorp.com on 10.124.129.187:53: server misbehaving"

待处理

稳定性测试

Agent 宕机不影响client继续使用,agent 下的节点宕机,负载均衡可以迅速感知

spring cloud consul 服务发现拉取周期

目前没有看到拉取周期的配置项,consul agents 参与gossip做状态同步和服务发现,可能这块时间以来gossip周期时间,和Eureka 下services直接从Eureka server拉取不同

todo

Consul 数据存储在磁盘哪里?

The datastore itself is located on the Consul servers in the data directory. To ensure data is not lost in the event of a complete outage, use the consul snapshot feature to backup the data.

client agent 作用

客户端节点参与基于八卦的健康检查,该检查分发健康检查的工作,而不像集中式心跳,这成为可扩展性挑战

为啥需要client

https://www.zhihu.com/question/68005259

http://www.mamicode.com/info-detail-2567902.html?cf_chl_jschl_tk=8c494d9e99d66666e9b321d628bc5b53835cbeaf-1582796949-0-AQI8-4Nfqe0jC56CzDHikPIc8OFb_bUrbfiGCX0xbAOJH5RPjxDDSZAUAOOk6LaLO0TuApCvk2268AMzPwcoISXl1d66PWyjbxSeZfyFoaQ4URyh8_ECgqo2NIP6njuhtDX_4wLwNzCNU5tdQW-6uvuksc16jK26K4h4KB3v0TmrZ4JGSlFEyTG_pR3IM_aZv7IODwIcBWe-x7p1VprA6Et0cFCfVQv7eQV6SzhSQ_fb6Q8WUn6t4OfVOIllVxCBx0LCKxmZlxG4JHJfOXFBOwgdc0mzI30Np0-A_BVyGde8HWtPou16S1NZO9InCO4T6Q

参考文档

https://learn.hashicorp.com/consul/datacenter-deploy/deployment-guide

https://learn.hashicorp.com/consul/datacenter-deploy/reference-architecture

https://www.jianshu.com/p/87f03c025281

https://www.jianshu.com/p/b2355dbd1753

https://juejin.im/post/5cfa03485188256b2f31febf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!