The whole process of installing and configuring MQTT server Mosquitto

1, Resource download
Download address: http://mosquitto.org/download/
After downloading, put the compressed package on the Linux server for the next step.


2, Install Mosquitto service
① Unzip the compressed package as follows:

Enter the following command:

tar -xzvf mosquitto-2.0.11.tar.gz 

After decompression, it is as follows:

Enter the following command to enter Mosquitto:

cd mosquitto-2.0.11/

② To compile the code, enter the following command to start the compilation:

make

As follows:

Prompt: the header file of openssl is not found. You need to install openssl manually. The installation steps here are placed in error handling.
Compile again, and the following error occurs, as shown in the figure:

Prompt: the cjson library is not found. You need to install it manually. The installation method is in error handling.
Compile again, and the compilation is completed, as shown below:

Then enter the following command:

make install

This completes the installation.
③ Start service
First execute the following command to switch to the directory where the service is located:

cd /etc/mosquitto/

As shown in the figure below:

Execute the following command to copy a configuration file:

cp mosquitto.conf.example mosquitto.conf 

Since anonymous login is allowed by default in the configuration file, the user name and password are not set here for testing.

The files compiled and installed here are placed in / usr/local/bin / directory, as shown in the following figure:

When starting the service, run the following command:

./mosquitto_ctrl -c /etc/mosquitto/mosquitto.conf

An error was found as follows:

./mosquitto_ctrl: error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory

The following commands are required for soft links:

sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1
sudo ldconfig

Execute the above startup command again and report an error again. The results are as follows:

mosquitto_ctrl: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory

After trying, the problem is solved after recompiling openssl. When running the command again, the following error occurs:

./mosquitto_ctrl: error while loading shared libraries: libcjson.so.1: cannot open shared object file: No such file or directory

After another struggle, we finally found a solution. First, enter the following command:

nano /etc/ld.so.conf

Add a line inside:

/usr/local/lib

Here, you must ensure that there is libcjson in the "/ usr/local/lib" directory so.* This link library is shown in the following figure:

If not, you need to recompile the cJson library.
After adding, enter the following command to refresh the configuration:

ldconfig

Finally, run the service again, and the following message appears:

Error: Module '-c' not supported.

Remove "- c" from the command as follows:

 ./mosquitto_ctrl /etc/mosquitto/mosquitto.conf

Then you see the following results:

mosquitto_ctrl is a tool for administering certain Mosquitto features.
mosquitto_ctrl version 2.0.11 running on libmosquitto 2.0.11.
General usage: mosquitto_ctrl <module> <module-command> <command-options>
For module specific help use: mosquitto_ctrl <module> help
Modules available: dynsec
For more information see:
    https://mosquitto.org/man/mosquitto_ctrl-1.html

As shown in the figure below:

error handling
1. Install openssl
① Download address:

https://www.openssl.org/source/openssl-1.1.1c.tar.gz

After downloading, put it on Linux as follows:

② Unzip the compressed file and enter the following command:

tar zxf openssl-1.1.1c.tar.gz
cd openssl-1.1.1c
./config
make install 

③ Establish soft link

ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1

2. Install cJson
① Download address:

https://github.com/DaveGamble/cJSON

After downloading, put it on the Linux server, as shown below:

② Enter the following command to unzip the zip package:

unzip cJSON-master.zip 

③ Compile and install cJson. The command is as follows:

cd cJSON-master/
mkdir build
cd build/
make
make install

Added by lucifer27 on Thu, 23 Dec 2021 21:21:43 +0200