所需安裝包: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