EMQX => mqttbroker
docs: https://developer.emqx.io/docs/broker/v3/cn/
Build From Source The EMQ X broker requires Erlang/OTP R21+ to build since 3.0 release.
git clone https://github.com/emqx/emqx-rel.git
cd emqx-rel && make
cd _build/emqx/rel/emqx && ./bin/emqx console
Quick Start
# Start emqx
./bin/emqx start
# Check Status
./bin/emqx_ctl status
# Stop emqx
./bin/emqx stop
修改配置文件之后需要 emqx restart 重启生效
默认访问控制设置
EMQ X 消息服务器默认访问控制,在 etc/emqx.conf 中设置:
## 设置所有 ACL 规则都不能匹配时是否允许访问
## Value: allow | deny
acl_nomatch = allow
## 设置存储 ACL 规则的默认文件
## Value: File Name
acl_file = etc/acl.conf
ACL 规则定义在 etc/acl.conf,EMQ X 启动时加载到内存:
%% 允许 'dashboard' 用户订阅 '$SYS/#'
{allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.
%% 允许本机用户发布订阅全部主题
{allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
%% 拒绝除本机用户以外的其他用户订阅 '$SYS/#' 与 '#' 主题
{deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
%% 允许上述规则以外的任何情形
{allow, all}.
plugins
emqx_auth_username
EMQ X Authentication with Username and Password
Configuration
etc/emqx_auth_username.conf:
## Password hash.
##
## Value: plain | md5 | sha | sha256
auth.user.password_hash = sha256
REST Api
REST API https://developer.emqx.io/docs/emq/v3/en/rest.html
List all usernames
# Request
GET api/v3/auth_username
# Response
{
"code": 0,
"data": ["username1"]
}
Add a username:
# Request
POST api/v3/auth_username
{
"username": "some_name",
"password": "password"
}
# Response
{
"code": 0
}
Update password for a username:
# Request
PUT api/v3/auth_username/$NAME
{
"password": "password"
}
# Response
{
"code", 0
}