centos6.8下emqtt集群安装配置与测试验证

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xuxile/article/details/78754704
1.简介
emqttd(Erlang MQTT Broker)是基于Erlang/OTP语言平台开发,支持大规模连接和分布式集群,发布订阅模式的开源MQTT消息服务器。
emqttd完整支持MQTT V3.1/V3.1.1版本协议规范,并扩展支持WebSocket、Stomp、CoAP、MQTT-SN或私有TCP协议。emqttd消息服务器
支持单节点100万连接与多节点分布式集群。EMQ 2.0 (Erlang/Enterprise/Elastic MQTT Broker) 是基于 Erlang/OTP 语言平台开发,
支持大规模连接和分布式集群,发布订阅模式的开源 MQTT 消息服务器。2.0 版本开始 emqttd 消息服务器自正式简称为EMQ。
2.下载
建议使用最新稳定版本:http://emqtt.com/downloads
3.环境介绍
节点一:192.168.20.38
节点二:192.168.20.52
节点三:192.168.20.111
4.安装配置
分别在三台机器执行
yum install -y lksctp-tools
将emqttd-centos6.8-v2.2.0.zip上传至/home目录
cd /home
unzip emqttd-centos6.8-v2.2.0.zip
cd emqttd
vi /home/emqttd/etc/emq.conf
node.name = [email protected](对应节点写对应的机器IP)
由于我机器上1883、8080等端口已经被用了,所以我修改了emq.conf中的对应端口配置:
1883->2883,8080->6060,8083->6063,8084->6064
控制台方式启动服务:./bin/emqttd console
后台启动:./bin/emqttd start
关闭服务:./bin/emqttd stop
启动状态查询:./bin/emqttd_ctl status
在192.168.20.52和192.168.20.11机器上分别执行:
./bin/emqttd_ctl cluster join [email protected]
任意节点查看集群状态
./bin/emqttd_ctl cluster status
移除某个节点命令
./bin/emqttd_ctl cluster remove [email protected]
5.管理后台
URL:http://192.168.20.38:18083/
账号:admin  密码:public
可以用命令./bin/emqttd_ctl admins passwd admin 123456修改密码
6.鉴权配置
关闭匿名认证,修改/home/emqttd/etc:
mqtt.allow_anonymous = false
启用 emq_auth_username 插件(不启用则mqtt.allow_anonymous = false不生效):
./bin/emqttd_ctl plugins load emq_auth_username
两种方式添加用户(管理员只能通过命令添加):

直接在 etc/plugins/emq_auth_username.conf 中明文配置默认用户例如:

auth.user.1.username = hthl_pub
auth.user.1.password = 123456
auth.user.2.username = hthl_sub
auth.user.2.password = 123456
auth.user.3.username = hthl_all
auth.user.3.password = 123456


(上面一行留空是因为emqt2.2.0版本有BUG,必须回车,否则最后行无效) 使用 ./bin/emqttd_ctl users 命令添加用户:
./bin/emqttd_ctl users add hthl_pub 123456
./bin/emqttd_ctl users add hthl_sub 123456
./bin/emqttd_ctl users add hthl_all 123456

修改鉴权文件acl.conf:

%% 允许hthl_sub用户订阅hthl/#主题
{allow, {user, "hthl_sub"}, subscribe, ["hthl/#"]}.
%% 允许hthl_pub用户发布hthl/#主题
{allow, {user, "hthl_pub"}, publish, ["hthl/#"]}.
%% 允许hthl_all用户发布订阅$SYS/#和hthl/#主题
{allow, {user, "hthl_all"}, pubsub, ["$SYS/#", "hthl/#"]}.
%% 允许本机发布订阅全部主题
{allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
%% 上述规则无匹配,禁止
{deny, all}.


(上面一行留空是因为emqt2.2.0版本有BUG,必须回车,否则最后行无效) 修改后重启生效:
./bin/emqttd stop
./bin/emqttd start
./bin/emqttd restart(使用此命令无法重新加载配置文件)
7.测试验证
HTTP API必须修改emq.conf文件中的listener.api.mgmt = 127.0.0.1:6060为:listener.api.mgmt = 6060
修改后重启生效:
./bin/emqttd stop
./bin/emqttd start
./bin/emqttd restart(使用此命令无法重新加载配置文件)
发布消息测试命令如下:
curl -v --basic -u hthl_pub:123456 -d "qos=1&retain=0&topic=hthl/hyt&message=hello from http..." -k http://192.168.20.38:6060/mqtt/publish

猜你喜欢

转载自blog.csdn.net/xuxile/article/details/78754704