Linux环境下Docker安装Emqx

一、下载(pull)EMQX镜像

docker pull emqx/emqx

二、创建EMQX容器

docker run -d --name emqx -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 --restart=always emqx/emqx
#创建一个名为emqx的容器,并将emqx的端口映射到主机上的相应端口。1883用于MQTT,8083用于MQTT over WebSocket,8883用于MQTT over SSL/TLS,8084用于MQTT over TCP/TLS,18083用于EMQ X Dashboard。

三、检查容器是否成功运行

docker ps
or
docker ps -a
①.成功

②.失败

四、EMQX 获取客户端上下线状态

(一)、复制acl.conf到宿主机
docker cp <容器名称或容器ID>:/opt/emqx/etc/acl.conf acl.conf 
例如:docker cp emqx:/opt/emqx/etc/acl.conf acl.conf 
(二)、编写宿主机acl.conf文件
①.进去acl.conf文件编辑
vim acl.conf
②.修改acl.conf文件 

复制一下内容或添加{allow, all, subscribe, ["$SYS/brokers/+/clients/#"]}.

%%--------------------------------------------------------------------
%% -type(ipaddr() :: {ipaddr, string()}).
%%
%% -type(ipaddrs() :: {ipaddrs, [string()]}).
%%
%% -type(username() :: {user | username, string()} | {user | username, {re, regex()}}).
%%
%% -type(clientid() :: {client | clientid, string()} | {client | clientid, {re, regex()}}).
%%
%% -type(who() :: ipaddr() | ipaddrs() | username() | clientid() |
%%                {'and', [ipaddr() | ipaddrs() | username() | clientid()]} |
%%                {'or',  [ipaddr() | ipaddrs() | username() | clientid()]} |
%%                all).
%%
%% -type(action() :: subscribe | publish | all).
%%
%% -type(topic_filters() :: string()).
%%
%% -type(topics() :: [topic_filters() | {eq, topic_filters()}]).
%%
%% -type(permission() :: allow | deny).
%%
%% -type(rule() :: {permission(), who(), action(), topics()} | {permission(), all}).
%%--------------------------------------------------------------------

{allow, {username, {re, "^dashboard$"}}, subscribe, ["$SYS/#"]}.

{allow, {ipaddr, "127.0.0.1"}, all, ["$SYS/#", "#"]}.

{allow, all, subscribe, ["$SYS/brokers/+/clients/#"]}.

{deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.

{allow, all}.
(三)、复制acl.conf到Docker
docker cp acl.conf  <容器名称或容器ID>:/opt/emqx/etc/acl.conf 
例如:docker cp acl.conf emqx:/opt/emqx/etc/acl.conf 
(四)、重启EMQX容器
docker restart <容器名称或容器ID>
例如,docker restart emqx or docker restart b85f3084b39c

最后,重复第三步查询是否启动成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dec.18

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值