当前位置:首页 > 编程笔记 > 正文
已解决

docker搭建EMQX集群+nginx转发TCP

来自网友在路上 176876提问 提问时间:2023-11-09 01:55:09阅读次数: 76

最佳答案 问答题库768位专家为你答疑解惑

一、三台机器安装
1、三台都拉取镜像

docker pull emqx/emqx:5.0.26

2、三台分别运行镜像
第一台

docker run -itd --network host --name emqx --restart  always \-p 1883:1883 \-p 18083:18083 \-p 8083:8083 \-p 8883:8883 \-p 8080:8080 \-e EMQX_NAME="master1" \-e EMQX_HOST=localhost1 \-e EMQX_LISTENER__TCP_EXTERNAL=1883 \-e EMQX_WAIT_TIME=30 \-e EMQX_CLUSTER__DISCOVERY="static" \-e EMQX_JOIN_CLUSTER="master1@localhost1" \-e EMQX_CLUSTER__STATIC__SEEDS="master1@localhost1,master2@localhost2,master3@localhost3" \emqx/emqx:5.0.26

第二台

docker run -itd --network host --name emqx --restart  always \-p 1883:1883 \-p 18083:18083 \-p 8083:8083 \-p 8883:8883 \-p 8080:8080 \-e EMQX_NAME="master2" \-e EMQX_HOST=localhost2 \-e EMQX_LISTENER__TCP_EXTERNAL=1883 \-e EMQX_WAIT_TIME=30 \-e EMQX_CLUSTER__DISCOVERY="static" \-e EMQX_JOIN_CLUSTER="master2@localhost2" \-e EMQX_CLUSTER__STATIC__SEEDS="master1@localhost1,master2@localhost2,master3@localhost3" \emqx/emqx:5.0.26

第三台

docker run -itd --network host --name emqx --restart  always \-p 1883:1883 \-p 18083:18083 \-p 8083:8083 \-p 8883:8883 \-p 8080:8080 \-e EMQX_NAME="master3" \-e EMQX_HOST=localhost3 \-e EMQX_LISTENER__TCP_EXTERNAL=1883 \-e EMQX_WAIT_TIME=30 \-e EMQX_CLUSTER__DISCOVERY="static" \-e EMQX_JOIN_CLUSTER="master3@localhost3" \-e EMQX_CLUSTER__STATIC__SEEDS="master1@localhost1,master2@localhost2,master3@localhost3" \emqx/emqx:5.0.26

3、如何就行集群加入,选择一台主节点,对两个从节点执行如下
这里面我选择localhost1作为主节点

docker exec -it emqx shbin/emqx_ctl  cluster join master1@localhost1

4、登录皆可以了
二、做nginx TCP转发
1、首先在安装nginx 的时候,添加straem模块

./configure  --with-stream

2、修改/usr/local/nginx/nginx.conf文件,与http同级新增如下

stream {upstream emqx_tcp {server localhost1:1883 weight=1;server localhost2:1883 weight=1;server localhost3:1883 weight=1;}server {listen 1886;proxy_pass emqx_tcp;proxy_buffer_size 8k;tcp_nodelay on;}}
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"docker搭建EMQX集群+nginx转发TCP":http://eshow365.cn/6-35751-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!