使用的插件是: emq_auth_username
一、启用和配置emq_auth_username
在程序的etc/plugins/emq_auth_username.conf 中开启一个默认用户
##--------------------------------------------------------------------
## Username Authentication Plugin
##--------------------------------------------------------------------
## Examples:
## 用以下用户admin public作为测试使用
auth.user.1.username = admin
auth.user.1.password = public
##auth.user.2.username = feng@emqtt.io
##auth.user.2.password = public
##auth.user.3.username = name~!@#$%^&*()_+
##auth.user.3.password = pwsswd~!@#$%^&*()_+
启用插件:
在程序的 /bin/下执行,注意: 最好不要使用web界面提供的界面化开启和关闭插件的方式
emqttd_ctl plugins load emq_auth_username
二、关闭默认开启的匿名登录
这步才是最坑的,开启上面的emq_auth_username后,你会发现还是可以匿名连接到MQTT代理上,找了一圈最后发现是默认配置的问题
找到etc/emq.conf配置,搜索“Allow Anonymous authentication”关键字,找到如下配置
mqtt.allow_anonymous = true
将true改为false即可,最后重启EMQTT服务生效
mqtt.allow_anonymous = false
网友评论