一、consul:搭建高可用的consul注册中心

简介

如何搭建一个高可用的consul注册中心环境,以保证consul的正常运行,和高容灾。

下载

consul官方下载地址:https://releases.hashicorp.com/consul
版本选择:这里使用的是最新稳定版本(Stable)0.8.1

get https://releases.hashicorp.com/consul/0.8.1/consul_0.8.1_linux_amd64.zip
unzip consul_0.8.1_linux_amd64.zip
mkdir -p /data/consul/config
mkdir -p /data/consul/data
mkdir -p /data/logs/consul

server1配置

{
  "datacenter": "dc1",
  "node_name": "consul-node1",
  "server": true,
  "bootstrap" : true,
  "data_dir": "/data/consul/data",
  "addresses": {"http": "0.0.0.0"}
}
consul agent -config-file=/data/consul/config/server.json > /data/logs/consul/consul.log 2>&1 &
# 等待server2与server3启动后,去除server1的bootstrap,然后leave,最后重启server1
consul leave
{
  "datacenter": "dc1",
  "node_name": "server1",
  "server": true,
  "data_dir": "/data/consul/data",
  "addresses": {"http": "0.0.0.0"},
  "retry_join" : ["***.***.***.***:8301", "**********:8302"]
}
consul agent -config-file=/data/consul/config/server.json > /data/logs/consul/consul.log 2>&1 &
 
extend config
{
  "reconnect_timeout": "72h",
  "retry_interval": "30s",
  "session_ttl_min": "10s"
}

server2配置

{
  "datacenter": "dc1",
  "node_name": "consul-node3",
  "server": true,
  "data_dir": "/data/consul/data",
  "addresses": {"http": "0.0.0.0"},
  "retry_join" : ["***.***.***.***8302", "***********:8301"]
}
consul agent -config-file=/data/consul/config/server.json > /data/logs/consul/consul.log 2>&1 &

server3配置

{
  "datacenter": "dc1",
  "node_name": "consul-node3",
  "server": true,
  "data_dir": "/data/consul/data",
  "addresses": {"http": "0.0.0.0"},
  "retry_join" : ["***.***.***.***8303", "**********:8301"]
}
consul agent -config-file=/data/consul/config/server.json > /data/logs/consul/consul.log 2>&1 &

client1配置


{
  "datacenter": "dc1",
  "node_name": "consul-client01",
  "server": false,
  "data_dir": "/data/consul/data",
  "addresses": {"http": "0.0.0.0"},
  "retry_join" : ["***.***.***.***:8301", "***.***.***.***:8301", "***.***.***.***:8301"]
}
consul agent -config-file=/data/consul/config/client.json > /data/logs/consul/consul.log 2>&1 &

检查配置

consul members

注册服务

curl -XPUT 'http://localhost:8500/v1/agent/service/register' -d '
{
  "ID": "test-id",
  "Name": "test-name",
  "Tags": ["dev", "beta"],
  "Address": "***********",
  "Port": 8080,
  "Check": {
    "HTTP": "http://***.***.***.***:8080/health",
    "Interval": "10s",
    "Timeout": "10s",
    "DeregisterCriticalServiceAfter": "5m"
  }
}

发现服务

curl -XGET ‘http://localhost:8500/v1/catalog/services?wait=2s’

检测服务健康

curl -XGET ‘http://localhost:8500/v1/health/service/test-name’

注销服务

curl -XDELETE ‘http://localhost:8500/v1/agent/service/deregister/test-id’

consul节点切换步骤

1、启动新的consul client和consul server,加入旧的consul cluster
2、配置新的vip给新的consul client
3、修改dns解析,使client.consul.prd.adou.com指向新的vip
4、重启提供服务的应用
5、旧的consul client leave
6、旧的consul server leave

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值