https://www.lixiaodong.com/?p=1631.安装需要的包sudo apt-get install libc-ares-dev libcurl4-openssl-dev libmysqlclient-dev2.下载mosquitto源码并编译安装从http://mosquitto.org/download/ 下载源码并解压到某个目录,进入该目录编译安装make mosquittosudo make install3.下载mosquitto-auth-plug源码git clone https://github.com/jpmens/mosquitto-auth-plug.git并使用copy命令生成config.mk文件:cp config.mk.in config.mk编辑config.mk:根据需要选择合适的后台。我这里只使用mysql数据库验证用户,BACKEND_MYSQL这一行是yes,其余行都是no。在MOSQUITTO_SRC一行输入mosquitto的源码路径,比如MOSQUITTO_SRC =/root/mosquitto-1.4.4/。在OPENSSLDIR一行输入openssl的路径,比如OPENSSLDIR = /usr/lib/ssl。可以使用以下命令得到openssl的路径:openssl version -a4.进入mosquitto-auth-plug所在目录,使用make命令生成so文件。5.移动so文件到mosquitto目录(不是源码目录,而是安装后的目录)mv auth-plug.so /etc/mosquitto/6.编辑mosquitto配置文件mosquitto-auth-plug的源码里已经有多种范例配置文件,可以使用这些文件。比如,我用mysql做验证,可以使用 examples目录下的mosquitto-mysql.conf。mv mosquitto.conf mosquitto.conf.origin(保留原始配置文件,供以后使用)mv mosquitto-auth-plug目录/examples/mosquitto-mysql.conf mosquitto目录/mosquitto.conf根据实际情况,编辑文件里的auth_plugin,backend,数据库host,端口,数据库名,用户,密码,sql语句等。7.运行mosquitto并观察输出mosquitto -c mosquitto-conf -v问题:1. 输出显示Unable to load auth plugin ".../auth-plug.so"解决:编辑Mosquitto源码目录下的config.mk:WITH_SRV:=no然后重新编译:make cleanmake生成新的so文件。
How to make Access Control Lists (ACL) work for Mosquitto MQTT Broker with Auth Plugin?
If you planning to strengthening your MQTT service, then access control lists (ACL) are mandatory. Mosquitto broker supports this ACL feature through auth plugins.
One versatile auth-plugin for mosquitto that you should consider using is https://github.com/jpmens/mosquitto-auth-plug. It is very flexible, in that it can support multiple backends as auth provider databases, ranging from CDB, Redis to MySQL and Http. However, getting it compiled and making it start to work is not that straight forward or easy. Hence, this post. It gives some starting point to our students who are venturing into Mosquitto Authentication systems to get started.