所需安装包:c++
libwebsockets-v1.6-stable.tar.gz,mosquitto-1.4.8.tar.gzweb
# yum -y install gcc gcc-c++ openssl-devel c-ares-devel libuuid-devel wget cmakewebsocket
下载websocket,我用的是 libwebsockets-v1.6-stable.tar.gz,socket
解压缩:# tar zxfv libwebsockets-v1.6-stable.tar.gz
测试
# cd libwebsockets-v1.6-stableui
# mkdir bulidspa
# cd bulid.net
# cmake ..ssl
# make && make install部署
下载mqtt,我用的是 mosquitto-1.4.8.tar.gz,
解压缩:# tar zxfv mosquitto-1.4.8.tar.gz
# cd /mosquitto-1.4.8
找到mosquitto-1.4.8目录下的config.mk文件,把config.mk 文件中的 WITH_WEBSOCKETS:=no 改成yes
保存后,执行
# make && make install
# ln -s /usr/local/lib/libwebsockets.so.6 /usr/lib64/libwebsockets.so.6
# groupadd mosquitto
# useradd -g mosquitto mosquitto
# cd /etc/mosquitto/
若是该目录下没有mosquitto.conf 和 pwfile
,
执行
# cp mosquitto.conf.example mosquitto.conf
# cp pwfile.example pwfile
而后修改 文件mosquitto.conf ,
并在文件最后加入
# mosquitto -c /etc/mosquitto/mosquitto.conf
须要打开2个窗口
订阅:
发送消息:
若是订阅窗口打印出hello world ,证实MQTT安装成功。
在安装过程当中,或测试过程当中可能会遇到错误:
mosquitto_sub: error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory
解决方法:
# cat /etc/ld.so.conf
# echo "/usr/local/lib">>/etc/ld.so.conf
# ldconfig