使用docker快速搭建consul集群

环境准备

节点名称ip地址
consul-s1192.168.130.20
consul-s2192.168.130.19
consul-s3192.168.130.21
consul-c1192.168.130.21

3个server 1个client

安装docker

单机

创建目录

mkdir -p /root/consul_sg/conf
mkdir -p /root/consul_sg/data

启动

docker run -d --net=host --name consul-s1 \
-v  /root/consul_sg/data:/consul/data \
-v /root/consul_sg/conf:/consul/config \
docker.io/consul:1.5.0 consul agent -server \
-bind=192.168.130.20 \
-client 0.0.0.0 \
-data-dir /consul/data \
-config-dir /consul/config \
-ui

集群

创建目录

创建配置目录和数据目录(consul-s1\consul-s2\consul-s3节点都执行)

mkdir -p /root/consul/conf

mkdir -p /root/consul/data

启动server

consul-s1

docker run -d --net=host --name consul-s1 \
-v  /root/consul/data:/consul/data \
-v /root/consul/conf:/consul/config \
docker.io/consul:1.5.0 consul agent -server \
-bind=192.168.130.20 \
-client 0.0.0.0 \
-bootstrap-expect=2 \
-data-dir /consul/data \
-config-dir /consul/config \
-ui

consul-s2

docker run -d --net=host --name consul-s2 \
-v  /root/consul/data:/consul/data \
-v /root/consul/conf:/consul/config \
docker.io/consul:1.5.0 consul agent -server \
-bind=192.168.130.19 \
-join=192.168.130.20 \
-client 0.0.0.0 \
-bootstrap-expect=2 \
-data-dir /consul/data \
-config-dir /consul/config \
-ui

consul-s3

docker run -d --net=host --name consul-s3 \
-v  /root/consul/data:/consul/data \
-v /root/consul/conf:/consul/config \
docker.io/consul:1.5.0 consul agent -server \
-bind=192.168.130.21 \
-join=192.168.130.20 \
-client 0.0.0.0 \
-bootstrap-expect=2 \
-data-dir /consul/data \
-config-dir /consul/config \
-ui

启动client

进入到consul-c1
创建数据和配置目录

mkdir -p /root/consul_client/data
mkdir -p /root/consul_client/conf

由于和server公用一台机器,为了端口不冲突,修改一下默认监听

cd /root/consul_client/conf
vi basic.json

内容如下

{

     "ports": {

        "http":18501,

        "dns":18601,

        "serf_lan":18301,

        "serf_wan":18302,

        "server":18300
    }
}

启动client1

docker rm -f consul-c1 
docker run -d --net=host --name consul-c1 \
-v /root/consul_client/data:/consul/data \
-v /root/consul_client/conf:/consul/config \
docker.io/consul:1.5.0 consul agent \
-node kont004ecs \
-bind=192.168.130.21 \
-data-dir /consul/data \
-config-dir /consul/config \
-join 192.168.130.20:8301

检查集群状态

进入server节点,查看集群状态

docker exec consul-s1 consul members
Node        Address               Status  Type    Build  Protocol  DC   Segment
kont001ecs  192.168.130.20:8301   alive   server  1.5.0  2         dc1  <all>
kont002ecs  192.168.130.19:8301   alive   server  1.5.0  2         dc1  <all>
kont003ecs  192.168.130.21:8301   alive   server  1.5.0  2         dc1  <all>
kont004ecs  192.168.130.21:18301  alive   client  1.5.0  2         dc1  <default>

也可以打开浏览器查看
http://192.168.130.20:8500/ui/dc1/nodes

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值