Construction of MQTT environment on Linux

It is not difficult to build an mqtt server on linux. The main reason is to use the message broker service software mosquitto.

It adopts the publish/subscribe mode transmission mechanism, which is lightweight, simple, open and easy to implement, and is widely used in the Internet of Things



My linux version is centos6.7_x86


1. Install the software

Enter the following commands to install one by one:

yum install gcc-c++
yum install cmake
yum install openssl-devel

Create a new software folder, download mosquitto, the next version that is neither high nor low, and unzip it:

mkdir software
cd software
wget http://mosquitto.org/files/source/mosquitto-1.4.10.tar.gz
tar -xzvf mosquitto-1.4.10.tar.gz

But you can't compile and install mosquitto here

The following three extensibility software will not be installed and will not affect the use of mosquitto:

Install c-areas (a library that supports asynchronous DNS lookups):

wget http://c-ares.haxx.se/download/c-ares-1.10.0.tar.gz
tar xvf c-ares-1.10.0.tar.gz
cd c-ares-1.10.0
./configure
make
sudo make install

Install lib-uuid (support to generate unique uuid for each connecting client) :

yum install libuuid-devel

Install libwebsockets (supports applications that require websockets):

wget https://github.com/warmcat/libwebsockets/archive/v1.3-chrome37-firefox30.tar.gz
tar zxvf v1.3-chrome37-firefox30.tar.gz
cd libwebsockets-1.3-chrome37-firefox30
mkdir build
cd build
cmake .. -DLIB_SUFFIX=64
make install

The above may not be installed successfully, especially the third one, but it is not a big problem, but there is no corresponding function


Let's modify the configuration of mosquitto:

cd mosquitto-1.4.10
vim config.mk
Comment out WITH_SRV:=yes and WITH_UUID:=yes with #


Next, compile and install mosquitto:

make
sudo make install

Note: If you cannot find libmosquitto.so.1 during subsequent use, enter the following command under software to modify the location of libmosquitto.so:

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


2. Start the test

Create user:

sudo groupadd mosquitto
sudo useradd -g mosquitto mosquitto

If there is any problem here, it must be your copy wrong.

Program configuration:

mv /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf

starting program:

mosquitto -c /etc/mosquitto/mosquitto.conf -d

The default port is 1883


Finally, we open another server window and enter in a (subscription) window:

mosquitto_sub -t hello
Another (publish) window input:
mosquitto_pub -t hello -h localhost -m "hello world!"

Program screenshot:




In this way, we have successfully subscribed to the message with the topic hello

I have also built this process on the Raspberry Pi. You need to add a few more sudos to operate successfully.

If not, please continue from the make step without error

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325580989&siteId=291194637