%% 允许 "dashboard" 用户 订阅 "$SYS/#" 主题 {allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}. %% 允许 IP 地址为 "127.0.0.1" 的用户 发布/订阅 "$SYS/#","#" 主题 {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}. %% 拒绝 "所有用户" 订阅 "$SYS/#" "#" 主题 {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}. %% 允许其它任意的发布订阅操作 {allow, all}.
最终在查询了很多资料后,最终在Docker Hub上看到相关的资料 https://hub.docker.com/r/emqx/emqx,其中Persistence中看到,如果需要将数据进行持久化,需要设置/opt/emqx/etc中的文件
docker-compose-emqx.yml
version: '3' services: emqx1: image: emqx/emqx:4.3.10 environment: - "EMQX_NAME=emqx" - "EMQX_HOST=node1.emqx.io" - "EMQX_CLUSTER__DISCOVERY=static" - "EMQX_CLUSTER__STATIC__SEEDS=emqx@node1.emqx.io, emqx@node2.emqx.io" - EMQX_LOADED_MODULES="emqx_mod_acl_internal,emqx_mod_acl_internal/" 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 # - 8081:8081 - 8083:8083 - 8084:8084 - 8883:8883 - 18083:18083 volumes: - ./emqx/acl.conf:/opt/emqx/etc/acl.conf #配置文件 networks: emqx-bridge: driver: bridge
acl.conf
{allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}. {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}. {allow, all, subscribe, ["$SYS/brokers/+/clients/#"]}. {allow, all, subscribe, ["$SYS/#", {eq, "#"}]}. {allow, all}.
原本地Windows或是Linux上使用包安装EMQX,在设置了acl后,需要运行命令 ./bin/emqx_ctl modules reload emqx_mod_acl_internal 但在使用docker时,只需要指定文件就可以了,将进行替换,然后运行EMQX时,会自动加载acl插件,并不需要进行插件的重新加载工作 最终运行效果