centos搭建MQTT伺服器Mosquitto
1.安裝工具
yum install gcc gcc-c++
yum install openssl-devel
yum install c-ares-devel
yum install libuuid-devel
yum install wget
yum install cmake
yum install build-essential python quilt devscripts python-setuptools python3
yum install libssl-dev libc-ares-dev uuid-dev daemon openssl-devel
2.下載並編譯安裝libwebsockets
wget https://libwebsockets.org/git/libwebsockets/snapshot/libwebsockets-2.0.2.tar.gz
tar zxvf libwebsockets-2.0.2.tar.gz
cd libwebsockets-2.0.2
mkdir build
cd build
cmake .. -DLIB_SUFFIX=64
make install
ldconfig
3.修正連結庫
vim /etc/ld.so.conf.d/liblocal.conf
/usr/local/lib64
/usr/local/lib
ldconfig
4.下載並編譯安裝mosquitto
wget http://mosquitto.org/files/source/mosquitto-1.4.9.tar.gz
tar -xzvf mosquitto-1.4.9.tar.gz
cd mosquitto-1.4.9
更改configure.mk中
WITH_WEBSOCKETS:=no
為
WITH_WEBSOCKETS:=yes
make
make install
cp mosquitto.conf /etc/mosquitto
5.修改mosquitto.conf檔案
在/etc/mosquitto/mosquitto.conf的Default Listener一節新增如下幾行:
6.執行mosquitto
mosquitto -c /etc/mosquitto/mosquitto.conf
mosquitto -c /etc/mosquitto/mosquitto.conf -v
或mosquitto -c /etc/mosquitto/mosquitto.conf -d
7.本機測試mosquitto
在伺服器上新建兩個shell,A和B
A 訂閱主題:
mosquitto_sub -t topicA
B 推送訊息:
mosquitto_pub -t topicA -h localhost -m "topicA test"
PS:
MQTT監控軟體連結