搭建 EMQX 集群

参考
https://docs.emqx.com/zh/emqx/latest/deploy/cluster/create-cluster.html

静态节点列表自动集群

在 192.168.10.20

docker run -d \
    --name emqx \
    --restart always \
    -e "EMQX_NODE_NAME=emqx@192.168.10.20" \
    -e "EMQX_CLUSTER__DISCOVERY_STRATEGY=static" \
    -e "EMQX_CLUSTER__STATIC__SEEDS=[emqx@192.168.10.20,emqx@192.168.10.21]" \
    -e "EMQX_NODE__COOKIE=mysecretcookie" \
    -p 4370:4370 \
    -p 5369:5369 \
    -p 1883:1883 \
    -p 8083:8083 \
    -p 8084:8084 \
    -p 8883:8883 \
    -p 18083:18083 \
    emqx/emqx:5.7.0

在 192.168.10.21

docker run -d \
    --name emqx \
    --restart always \
    -e "EMQX_NODE_NAME=emqx@192.168.10.21" \
    -e "EMQX_CLUSTER__DISCOVERY_STRATEGY=static" \
    -e "EMQX_CLUSTER__STATIC__SEEDS=[emqx@192.168.10.20,emqx@192.168.10.21]" \
    -e "EMQX_NODE__COOKIE=mysecretcookie" \
    -p 4370:4370 \
    -p 5369:5369 \
    -p 1883:1883 \
    -p 8083:8083 \
    -p 8084:8084 \
    -p 8883:8883 \
    -p 18083:18083 \
    emqx/emqx:5.7.0

端口说明

参考
https://github.com/emqx/emqx/blob/master/deploy/docker/Dockerfile

# emqx will occupy these port:
# - 1883 port for MQTT
# - 8083 for WebSocket/HTTP
# - 8084 for WSS/HTTPS
# - 8883 port for MQTT(SSL)
# - 18083 for dashboard and API
# - 4370 default Erlang distribution port
# - 5369 for backplane gen_rpc
EXPOSE 1883 8083 8084 8883 18083 4370 5369

环境变量

参考
https://github.com/emqx/emqx/blob/master/deploy/docker/docker-entrypoint.sh

默认情况下,带有 EMQX_ 前缀的环境变量会映射到配置文件中的键值对。

容器中配置文件位置 /opt/emqx/etc/emqx.conf

## See https://www.emqx.io/docs/en/latest/configuration/configuration.html for more details.
## Configuration full example can be found in etc/examples

node {
  name = "emqx@127.0.0.1"
  cookie = "emqxsecretcookie"
  data_dir = "data"
}

cluster {
  name = emqxcl
  discovery_strategy = manual
}

log {
    # file {
    #     level = warning
    # }
    # console {
    #     level = warning
    # }
}
dashboard {
    listeners.http {
        bind = 18083
    }
}

配置文件

参考
https://docs.emqx.com/zh/emqx/latest/configuration/configuration.html

posted @ 2024-06-05 09:41  ioufev  阅读(136)  评论(0)    收藏  举报