1.在任意目录创建 docker-compose.yml 文件,内容如下:
version: '3.7'
services:
emqx1:
image: emqx:5.1.3
container_name: emqx1
environment:
- "EMQX_NODE_NAME=emqx@node1.emqx.io"
- "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
- "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.io,emqx@node2.emqx.io]"
healthcheck:
test: ["CMD", "/opt/emqx/bin/emqx ctl", "status"]
interval: 5s
timeout: 25s
retries: 5
networks:
emqx-bridge:
aliases:
- node1.emqx.io
ports:
- 1883:1883
- 8083:8083
- 8084:8084
- 8883:8883
- 18083:18083
# volumes:
# - $PWD/emqx1_data:/opt/emqx/data
emqx2:
image: emqx:5.1.3
container_name: emqx2
environment:
- "EMQX_NODE_NAME=emqx@node2.emqx.io"
- "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
- "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.io,emqx@node2.emqx.io]"
healthcheck:
test: ["CMD", "/opt/emqx/bin/emqx ctl", "status"]
interval: 5s
timeout: 25s
retries: 5
networks:
emqx-bridge:
aliases:
- node2.emqx.io
# volumes:
# - $PWD/emqx2_data:/opt/emqx/data
networks:
emqx-bridge:
driver: bridge
2.通过命令行切换 docker-compose.yml 文件所在目录,然后输入以下命令启动 EMQX 集群:
docker-compose up -d
3查看集群状态
$ docker exec -it emqx1 sh -c "emqx ctl cluster status"
Cluster status: #{running_nodes => ['emqx@node1.emqx.com','emqx@node2.emqx.com'],
stopped_nodes => []}
4.下载mqttx 进行测试
https://mqttx.app/zh
下载对应的版本安装
4-1.发送端
![](https://img.haomeiwen.com/i11379314/290411892f90e0f3.png)
4-2.订阅端接收
![](https://img.haomeiwen.com/i11379314/d0103afd3f36a53c.png)
5.登录查看部署结果
http://192.168.1.112:18083/
![](https://img.haomeiwen.com/i11379314/8a45dea3b26afdc8.png)
网友评论