centos6.5 mqtt安裝


CentOs 6.5 MQTT 安裝部署

所需安裝包:

libwebsockets-v1.6-stable.tar.gz,mosquitto-1.4.8.tar.gz

1、安裝依賴

# yum -y install gcc gcc-c++ openssl-devel  c-ares-devel libuuid-devel wget cmake

2、為mosquitto增加websocket支持,需要安裝websocket庫文件

下載websocket,我用的是 libwebsockets-v1.6-stable.tar.gz,

解壓縮:# tar zxfv libwebsockets-v1.6-stable.tar.gz 

3、運行 websocket

 

# cd libwebsockets-v1.6-stable

# mkdir bulid

# cd bulid

# cmake ..

# make && make install

4、安裝mosquitto

 

下載mqtt,我用的是 mosquitto-1.4.8.tar.gz,

解壓縮:# tar zxfv mosquitto-1.4.8.tar.gz 

5、修改config.mk文件以使后面編譯的mosquitto文件支持websocket。

# 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

6、創建mosquitto.conf、pwfile文件

# cd /etc/mosquitto/

如果該目錄下沒有mosquitto.conf 和 pwfile

,

執行

# cp mosquitto.conf.example mosquitto.conf

# cp pwfile.example pwfile

然后修改 文件mosquitto.conf ,


並在文件最后加入

7、啟動 mqtt

# mosquitto -c /etc/mosquitto/mosquitto.conf

8、測試

需要打開2個窗口

訂閱:

發送消息:


如果訂閱窗口打印出hello world ,證明MQTT安裝成功。

9、錯誤解決

在安裝過程中,或測試過程中可能會遇到錯誤:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM