download
Enter the software installation directory:
cd /usr/software
Download the latest version of the source package:
wget http://mosquitto.org/files/source/mosquitto-1.4.13.tar.gz
Unzip
tar -zxvf mosquitto-1.4.13.tar.gz
Compile and install
Create a software installation directory:
mkdir mosquitto
Enter the unzipped folder:
cd mosquitto-1.4.13
First install other dependent libraries:
yum install -y c-ares-devel e2fsprogs-devel uuid-devel libuuid-devel
yum install -y openssl-devel #依赖头文件
Compile and install, specify the installation location:
make prefix=/root/source/mosquitto && make install
Create a link to the directory and update the dynamic link library
sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1
sudo ldconfig
Configuration
Open configuration file
vim /etc/mosquitto/mosquitto.conf
Add users: (root)
user root
Save
start up
mosquitto -c /etc/mosquitto/mosquitto.conf -d
Subscribe to topic news
There
must be a topic for publishing and subscribing to open the message push of terminal 1 , option [-t] topic, namely:
mosquitto -t 主题
If you need to specify a user name, add option [-i] user name, namely:
mosquitto_sub -t 主题 -i 订阅端
./mosquitto_sub -t mqtt
Publish topic message
Specify the topic of the message push, the user name and message of the publishing end:
mosquitto_pub -t 主题 -i 发布端 -h 主机 -m 你好
./mosquitto_pub -h localhost -t mqtt -m "hello world."
————————————————
Copyright Statement: This article is an original article by CSDN blogger “jeikerxiao”, following the CC 4.0 BY-SA copyright agreement, please attach the original source link and this statement for reprint .
Original link: https://blog.csdn.net/jeikerxiao/article/details/74005584