EMQTT

来自Jack's Lab
(版本间的差异)
跳转到: 导航, 搜索
(以“== 开启认证 == === 关闭匿名认证 === 默认开启,需要手动关闭匿名认证 1. 进入安装目录下 /etc,打开 emqx.conf文件 cd /opt/emqt...”为内容创建页面)
 
 
第91行: 第91行:
 
<source lang=bash>
 
<source lang=bash>
 
</source>
 
</source>
 +
 +
* https://docs.emqx.io/broker/latest/cn/advanced/acl.html
 +
 +
<br><br>
 +
 +
== Reference ==
 +
 +
* https://docs.emqx.io/broker/v3/cn/plugins.html#http-api-cli
 +
* https://docs.emqx.io/broker/latest/cn/advanced/acl.html
 +
* https://www.bbsmax.com/A/8Bz8bGDk5x/
  
 
<br><br>
 
<br><br>

2020年3月28日 (六) 06:44的最后版本

目录

[编辑] 1 开启认证

[编辑] 1.1 关闭匿名认证

默认开启,需要手动关闭匿名认证

1. 进入安装目录下 /etc,打开 emqx.conf文件

 cd /opt/emqtt/etc
 vim emqx.conf

2. 找到这一行: allow_anonymous = true

将 true 改为 false,保存、退出,就关闭了匿名认证


[编辑] 1.2 添加 Username 插件 emq_auth_username

1. bin 目录下执行下面命令,加载 emq_auth_username 插件

  ./emqttd_ctl plugins load emq_auth_username

2. 执行下面命令,添加一个用户名和密码

 ./emqttd_ctl users add test 123456

3 使用下面命令可以执行所需的操作,大功告成

./emqx_ctl users
users list                                      # List users
users add <Username> <Password>                 # Add User
users update <Username> <NewPassword>           # Update User
users del <Username>                            # Delete User


[编辑] 2 ACL

支持基于 etc/acl.conf 或 MySQL,PostgreSQL 等插件的访问控制

## ACL nomatch. Enum: allow, deny
acl_nomatch = allow

## Default ACL File
acl_file = etc/acl.conf

## Enable ACL cache. Enum: on, off
enable_acl_cache = on

## Default ACL cache size
acl_cache_max_size = 32

## Default time-to-live of
cache size acl_cache_ttl = 1m

上面标黄得那个我们配置的关键,当acl规则没有匹配到的时候就会找的这个参数,如果为true,则会通过验证,为false就会不通过验证


官方说明:

%% 允许'dashboard'用户订阅 '$SYS/#'
{allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.

%% 允许本机用户发布订阅全部主题
{allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.

%% 拒绝用户订阅'$SYS#'与'#'主题
{deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.

%% 上述规则无匹配,允许
{allow, all}.

 

注意:

  • 注释使用 %%
  • 不要忘了每个规则后面的 '.'
  • subscribe 和 pubsub 配合使用


参考配置:





[编辑] 3 Reference



个人工具
名字空间

变换
操作
导航
工具箱