转自:https://blog.csdn.net/TingBen/article/details/80946789
docker安装EMQ服务
1.镜像下载: http://emqtt.com/downloads/latest/docker
2.解压 emqttd-docker 镜像包:
unzip emqttd-docker-v2.3.10.zip
3.加载镜像:
docker load < emqttd-docker-v2.3.10
4.启动容器:
docker run -tid –name emq20 -p 1883:1883 -p 8083:8083 -p 8883:8883 -p 8084:8084 -p 18083:18083 emqttd-docker-v2.3.10
进入 Docker 控制台:
docker exec -it emq20 /bin/sh
MySql认证:
1.首先先关闭匿名认证(默认是开启的谁都能够登录)
vi /opt/emqttd/etc/eqm.conf
## Allow Anonymous authentication
mqtt.allow_anonymous = false
2.用户和权限的mysql表
CREATE TABLE mqtt_user (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
username varchar(100) DEFAULT NULL,
password varchar(100) DEFAULT NULL,
salt varchar(20) DEFAULT NULL,
is_superuser tinyint(1) DEFAULT 0,
created datetime DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY mqtt_username (username)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
………………………………………………………………..
CREATE TABLE mqtt_acl (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
allow int(1) DEFAULT NULL COMMENT ‘0: deny, 1: allow’,
ipaddr varchar(60) DEFAULT NULL COMMENT ‘IpAddress’,
username varchar(100) DEFAULT NULL COMMENT ‘Username’,
clientid varchar(100) DEFAULT NULL COMMENT ‘ClientId’,
access int(2) NOT NULL COMMENT ‘1: subscribe, 2: publish, 3: pubsub’,
topic varchar(100) NOT NULL DEFAULT ” COMMENT ‘Topic Filter’,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3.修改mysql配置文件
vi /opt/emqttd/etc/plugins/emq_auth_mysql.conf
auth.mysql.server = xxxxxxxxx:3306
auth.mysql.username = root
auth.mysql.password = xxxxxxxx
auth.mysql.database = emq
可以配置超级管理员(超级管理员会无视ACL规则对所有的topic都有订阅和推送的权限)
update mqtt_user set is_superuser=1 where id=1;
4.重启
/opt/emqttd/bin
emqttd stop
/opt/emqttd/bin
emqttd start
emqttd_ctl plugins load emq_auth_mysql
---------------------
作者:TingBen
来源:CSDN
原文:https://blog.csdn.net/TingBen/article/details/80946789
版权声明:本文为博主原创文章,转载请附上博文链接!