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监控软件链接
http://www.jensd.de/apps/mqttfx/1.7.1/