我首先为mosquitto创建了一个用户:
sudo adduser --system -no-create-home mosquitto
然后我安装了一些依赖项:
sudo apt-get install libc-ares-dev libcurl4-openssl-dev libmysqlclient-dev
然后我安装了mosquitto:
wget http://mosquitto.org/files/source/mosquitto-1.3.5.tar.gz //download mosquitto-1.3.5
tar xvzf mosquitto-1.3.5.tar.gz //unzip tar file
然后cd mosquitto-1.3.5
然后我使用
将config.mk置于编辑模式 sudo nano config.mk
然后我按 Ctrl + W 搜索SRV
已更改With_SRV:=no
Ctrl + O 后跟 Enter 以保存
Ctrl + X 退出文件
现在我需要安装Openssl来构建mosquitto。
所以我使用这个命令安装了Openssl:
wget http://www.openssl.org/source/openssl-1.0.0c.tar.gz
下载md5文件以生成md5代码
wget http://www.openssl.org/source/openssl-1.0.0c.tar.gz.md5
生成md5sum
md5sum openssl-1.0.0c.tar.gz
生成md5代码
cat openssl-1.0.0c.tar.gz.md5
如果两个代码匹配,则完全下载文件
解压缩tar文件
tar -xvzf openssl-1.1.0c.tar.gz 54. cd openssl-1.1.0c
在编译之前配置openssl
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
编译openssl
make
安装Openssl
sudo make install
以上行给出错误,因此下面的代码行:
sudo make install_sw
验证openssl是否已成功安装
/usr/local/openssl/bin/openssl version //get the version number of openssl
走出目录,进入mosquitto目录:
cd
cd mosquitto-1.3.5
安装mosquitto的另一个依赖
sudo apt-get install libssl-dev
编译Mosquitto
sudo make
安装Mosquitto:
sudo make install
从github下载mosquitto auth插件
git clone https://github.com/jpmens/mosquitto-auth-plug.git
下载hiredis
git clone https://github.com/redis/hiredis.git
转到hiredis目录并编译并安装
cd hiredis
make
sudo make install
转到mosquitto auth插件目录
cd
cd mosquitto-1.3.5
cd mosquitto-auth-plug
将config.mk.in的内容复制到config.mk
cp config.mk.in config.mk
在编辑模式下打开config.mk
sudo nano config.mk
更改以下代码行:
MOSQUITTO_SRC = /home/pi/mosquitto-1.3.5
OPENSSLDIR = /usr/local/openssl
保存文件并退出
Ctrl + O 后跟 Enter 然后 Ctrl + X 退出
然后我尝试编译mosquitto-auth-plug:
make
此时我收到此错误:
Selected backends: MySQL
Using mosquitto source dir: /home/pi/mosquitto-1.3.5
OpenSSL install dir: /usr/local/openssl
If you changed the backend selection, you might need to 'make clean' first
CFLAGS: -I/home/pi/mosquitto-1.3.5/src/ -I/home/pi/mosquitto-1.3.5/lib/ -fPIC -Wall -Werror -DBE_MYSQL -I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -g -DNDEBUG -I/src -DDEBUG=1 -I/usr/local/openssl/include
LDFLAGS: -L/home/pi/mosquitto-1.3.5/lib/
LDADD: -L/usr/lib/arm-linux-gnueabihf -lmysqlclient -lpthread -lz -lm -ldl -L/usr/local/openssl/lib -lcrypto -lmosquitto
cc -I/home/pi/mosquitto-1.3.5/src/ -I/home/pi/mosquitto-1.3.5/lib/ -fPIC -Wall -Werror -DBE_MYSQL `mysql_config --cflags` -I/src -DDEBUG=1 -I/usr/local/openssl/include -c -o cache.o cache.c
cache.c: In function ‘sha_hash’:
cache.c:48:3: error: implicit declaration of function ‘EVP_MD_CTX_new’ [-Werror=implicit-function-declaration]
EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
^
cache.c:48:23: error: initialization makes pointer from integer without a cast [-Werror]
EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
^
cache.c:53:3: error: implicit declaration of function ‘EVP_MD_CTX_free’ [-Werror=implicit-function-declaration]
EVP_MD_CTX_free(mdctx);
^
cc1: all warnings being treated as errors
<builtin>: recipe for target 'cache.o' failed
make: *** [cache.o] Error 1
所以,我删除了openssl-1.0.0c并安装了openssl-1.1.0c版本
然后成功完成了mosquitto-auth-plug的编译
然后按如下方式移动文件:
sudo mv auth-plug.so /etc/mosquitto
sudo mv /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf
编辑mosquitto .conf文件
sudo nano /etc/mosquitto/mosquitto.conf
按 Ctrl + W 进行搜索
在auth_plugin第二次出现后搜索auth_plugin并编写下面提到的命令
auth_plugin /etc/mosquitto/auth-plug.so
auth_opt_backends mysql
auth_opt_redis_host localhost
auth_opt_redis_port 12885
auth_opt_host localhost
auth_opt_port 3306
auth_opt_dbname HAC
auth_opt_user mqtt_user
auth_opt_pass ###YOUR_PASSWORD###
auth_opt_userquery SELECT pw FROM mqtt_users WHERE username = '%s'
auth_opt_superquery SELECT COUNT(*) FROM mqtt_users WHERE username = '%s' AND super = 1
auth_opt_aclquery SELECT topic FROM mqtt_acls WHERE (username = '%s') AND (rw >= %d)
auth_opt_anonusername AnonymouS
然后按 Ctrl + O 然后 Enter
保存文件要退出文件,请按 Ctrl + X
然后当我运行此命令时:
/ usr / local / sbin / mosquitto -c /etc/mosquitto/mosquitto.conf
我收到以下错误:
1486888881: mosquitto version 1.3.5 (build date 2017-02-11 22:22:57+0000) starting
1486888881: Config loaded from /etc/mosquitto/mosquitto.conf.
1486888881: Error: Unable to load auth plugin "/etc/mosquitto/auth-plug.so".
有人可以帮帮我吗?
我已经浪费了4天时间来搜索此错误的解决方案。
更新
我卸载了mosquitto并安装了最新版本。仍然得到相同的错误,但这次更具描述性。现在它说:
mosquitto version 1.4.10 (build date 2017-02-13 22:22:57+0000) starting
Config loaded from /etc/mosquitto/mosquitto.conf.
Error: Unable to load auth plugin "/etc/mosquitto/auth-plug.so".
Load Error: /etc/mosquitto/auth-plug.so: Undefined Symbol: EVP_MD_CTX_reset