在三台服务器上搭建emqx集群
Emqx集群
- 拉取镜像
docker pull emqx/emqx:v4.0.0
在主机为192.168.86.58部署emqx01
docker run -it --network host --name emqtt-master1-1 \
-p 1883:1883 \
-p 18083:18083 \
-p 8083:8083 \
-p 8883:8883 \
-p 8080:8080 \
-e EMQX_NAME="master1" \
-e EMQX_HOST=192.168.86.58 \
-e EMQX_LISTENER__TCP_EXTERNAL=1883 \
-e EMQX_WAIT_TIME=30 \
-e EMQX_CLUSTER__DISCOVERY="static" \
-e EMQX_JOIN_CLUSTER="master1@192.168.86.58" \
-e EMQX_CLUSTER__STATIC__SEEDS="master1@192.168.86.58,master2@192.168.86.19,master3@192.168.86.43" \
emqx/emqx:v4.0.0
在主机为192.168.86.19部署emqx02
docker run -it --network host --name emqtt-master2-1 \
-p 1883:1883 \
-p 18083:18083 \
-p 8083:8083 \
-p 8883:8883 \
-p 8080:8080 \
-e EMQX_NAME="master2" \
-e EMQX_HOST=192.168.86.19 \
-e EMQX_LISTENER__TCP_EXTERNAL=1883 \
-e EMQX_WAIT_TIME=30 \
-e EMQX_CLUSTER__DISCOVERY="static" \
-e EMQX_JOIN_CLUSTER="master2@192.168.86.19" \
-e EMQX_CLUSTER__STATIC__SEEDS="master1@192.168.86.58,master2@192.168.86.19,master3@192.168.86.43" \
emqx/emqx:v4.0.0
在主机为192.168.86.43部署emqx03
docker run -it --network host --name emqtt-master3-1 \
-p 1883:1883 \
-p 18083:18083 \
-p 8083:8083 \
-p 8883:8883 \
-p 8080:8080 \
-e EMQX_NAME="master2" \
-e EMQX_HOST=192.168.86.43 \
-e EMQX_LISTENER__TCP_EXTERNAL=1883 \
-e EMQX_WAIT_TIME=30 \
-e EMQX_CLUSTER__DISCOVERY="static" \
-e EMQX_JOIN_CLUSTER="master3@192.168.86.43" \
-e EMQX_CLUSTER__STATIC__SEEDS="master1@192.168.86.58,master2@192.168.86.19,master3@192.168.86.43" \
emqx/emqx:v4.0.0
使用docker-compose部署emqx
在192.168.86.58上的docker-compose
version: "3"
services:
emqx01:
image: emqx/emqx:v4.0.0
restart: always
container_name: emqx01
hostname: emqx01
ports:
- 8083:8083
- 8080:8080
- 8883:8883
- 1883:1883
- 18083:18083
environment:
- "EMQX_NAME=emqx01"
- "EMQX_HOST=192.168.86.58"
- "EMQX_LISTENER__TCP_EXTERNAL=1883"
- "EMQX_WAIT_TIME=30"
- "EMQX_CLUSTER__DISCOVERY=static"
- "EMQX_JOIN_CLUSTER=emqx01@192.168.86.58"
- "EMQX_CLUSTER__STATIC__SEEDS=emqx01@192.168.86.58,emqx02@192.168.86.19,emqx03@192.168.86.43"
healthcheck:
test: ["CMD","/opt/emqx/bin/emqx_ctl","status"]
interval: 5s
timeout: 25s
retries: 5
network_mode: host
在192.168.86.19上的docker-compose
version: "3"
services:
emqx01:
image: emqx/emqx:v4.0.0
restart: always
container_name: emqx01
hostname: emqx01
ports:
- 8083:8083
- 8080:8080
- 8883:8883
- 1883:1883
- 18083:18083
environment:
- "EMQX_NAME=emqx01"
- "EMQX_HOST=192.168.86.19"
- "EMQX_LISTENER__TCP_EXTERNAL=1883"
- "EMQX_WAIT_TIME=30"
- "EMQX_CLUSTER__DISCOVERY=static"
- "EMQX_JOIN_CLUSTER=emqx01@192.168.86.58"
- "EMQX_CLUSTER__STATIC__SEEDS=emqx01@192.168.86.58,emqx02@192.168.86.19,emqx03@192.168.86.43"
healthcheck:
test: ["CMD","/opt/emqx/bin/emqx_ctl","status"]
interval: 5s
timeout: 25s
retries: 5
network_mode: host
在192.168.86.43上的docker-compose
version: "3"
services:
emqx01:
image: emqx/emqx:v4.0.0
restart: always
container_name: emqx01
hostname: emqx01
ports:
- 8083:8083
- 8080:8080
- 8883:8883
- 1883:1883
- 18083:18083
environment:
- "EMQX_NAME=emqx01"
- "EMQX_HOST=192.168.86.43"
- "EMQX_LISTENER__TCP_EXTERNAL=1883"
- "EMQX_WAIT_TIME=30"
- "EMQX_CLUSTER__DISCOVERY=static"
- "EMQX_JOIN_CLUSTER=emqx01@192.168.86.58"
- "EMQX_CLUSTER__STATIC__SEEDS=emqx01@192.168.86.58,emqx02@192.168.86.19,emqx03@192.168.86.43"
healthcheck:
test: ["CMD","/opt/emqx/bin/emqx_ctl","status"]
interval: 5s
timeout: 25s
retries: 5
network_mode: host
然后在网页打开ip:18083
账号:admin
密码:public