Docker 部署 emqx4.3.12 集群

docker 部署 emqx 集群 自己调研一个周.感觉这个 emqx 集群也是相当价值去研究的,首先安装docker,这里就不在介绍.接下来都在一台服务器上执行的

1.docker 中创建网桥

docker network create -d bridge --subnet=192.168.174.0/16 emqx_bridge

2.执行创建emqx集群脚本

第一台

docker run -d \
--hostname emqx01 \
--name emqx01 \
--network emqx_bridge \
--ip 192.168.0.10 \
		-p 60001:1883 \
		-p 60004:8083 \
		-p 60010:8883 \
		-p 60007:8084 \
		-p 60016:18083 \
		-p 60013:11883 \
		-v /etc/localtime:/etc/localtime:ro emqx/emqx:v4.3.12

第二台

docker run -d \
--hostname emqx02 \
--name emqx02 \
--network emqx_bridge \
--ip 192.168.0.11 \
		-p 60002:1883 \
		-p 60005:8083 \
		-p 60011:8883 \
		-p 60008:8084 \
		-p 60017:18083 \
		-p 60014:11883 \
		-v /etc/localtime:/etc/localtime:ro emqx/emqx:v4.3.12

第三台

docker run -d \
--hostname  emqx03 \
--name emqx03 \
--network emqx_bridge \
--ip 192.168.0.12 \
		-p 60003:1883 \
		-p 60006:8083 \
		-p 60012:8883 \
		-p 60009:8084 \
		-p 60018:18083 \
		-p 60015:11883 \
		-v /etc/localtime:/etc/localtime:ro emqx/emqx:v4.3.12

3. 创建集群


docker exec -it emqx02 sh
./emqx_ctl  cluster join emqx01@192.168.0.10

docker exec -it emqx03 sh
./emqx_ctl  cluster join emqx01@192.168.0.10

4.haproxy代理使用

为什么使用haproxy? 经过多次测试,我们直接去拿着192.168.0.10 去访问web ui 反而拒绝,这是因为192.168.0.10 是docker里的网段,无法访问,这里和k8s里的原理挺像的

5. 安装haproxy   默认是1.5.8版本的

yum -y install haproxy 

修改配置文件haproxy.cfg

# Global settings
#---------------------------------------------------------------------
global
    log         127.0.0.1 local0

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                     tcp
    log                     global
    option                  httplog
    option                  dontlognull
    option                  http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  main *:5555   

#---------------------------------------------------------------------
# round robin balancing between the various backends
#--------------------------------------------------------------------
 backend              mqtt_backend
    balance           leastconn
    server  eqmx01 192.168.0.10:1883 check inter 10000 fall 2 rise 5 weight 1
    server  eqmx02 192.168.0.11:1883 check inter 10000 fall 2 rise 5 weight 1
    server  eqmx03 192.168.0.12:1883 check inter 10000 fall 2 rise 5 weight 1

listen admin_stats
	mode    http
	stats   enable
	bind    *:8888
	stats   refresh 30s
	stats   uri /admin
	stats   realm haproxy
	stats   auth root:root
	stats   hide-version

重启 haproxy即可

systemctl haproxy restart

说明下: 5555 这个端口是数据转发的端口 8888 这个端口是web ui 页面访问的

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值