Tags: dev verify mysql database Opens SQL git database load hub
1. Install the required packages
sudo apt-get install Libc-ares-dev libcurl4-openssl-dev Libmysqlclient-dev
2. Download the Mosquitto source code and compile the installation
Download the source code from http://mosquitto.org/download/and unzip it to a directory to compile and install the directory.
sudo make install
3. Download Mosquitto-auth-plug Source code
git clone https://github.com/jpmens/mosquitto-auth-plug.git
and use the Copy command to generate the Config.mk file: CP config.mk.in CONFIG.MK
Edit CONFIG.MK: Select the appropriate background as needed. I only use MySQL database to authenticate the user, Backend_mysql this line is yes, the remaining lines are no. Enter the Mosquitto source path in the MOSQUITTO_SRC line, such as Mosquitto_src =/root/mosquitto-1.4.4/
。 Enter the path to OpenSSL on the Openssldir line, such as Openssldir =/usr/lib/ssl.
The path to OpenSSL can be obtained using the following command: OpenSSL version-a
4. Enter the directory where the Mosquitto-auth-plug is located and use the make command to generate the so file.
5. Move the so file to the Mosquitto directory (not the source directory, but the installed directory)
6. Edit the Mosquitto configuration file
Mosquitto-auth-plug has a variety of sample configuration files in the source code, you can use these files. For example, I use MySQL to verify that you can use the mosquitto-mysql.conf in the examples directory.
MV Mosquitto.conf Mosquitto.conf.origin (retains the original configuration file for later use)
MV Mosquitto-auth-plug directory/examples/mosquitto-mysql.conf mosquitto directory/mosquitto.conf
According to the actual situation, edit the files in the Auth_plugin,backend, database host, port, database name, user, password, SQL statements and so on.
7. Run the Mosquitto and observe the output
1. Output shows unable to load auth plugin ".../auth-plug.so"
Edit the Config.mk:with_srv:=no under the Mosquitto source directory
And then recompile:
Generate a new so file.
Go: Use Mosquitto-auth-plugin to authenticate an MQTT client