CentOS 安裝Mosquitto及測試


 

系統信息,阿里雲服務器
CentOS 安裝Mosquitto及測試 - allegro_tyc - allegro_tyc的博客

 

安裝工具
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
 
下載並編譯安裝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
 
修正鏈接庫
vim /etc/ld.so.conf.d/liblocal.conf
/usr/local/lib64
/usr/local/lib
 
ldconfig
 
下載並編譯安裝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
 
修改mosquitto.conf文件
在/etc/mosquitto/mosquitto.conf的Default Listener一節添加如下幾行:
CentOS 安裝Mosquitto及測試 - allegro_tyc - allegro_tyc的博客
 
運行mosquitto
mosquitto -c /etc/mosquitto/mosquitto.conf
mosquitto -c /etc/mosquitto/mosquitto.conf -v
或mosquitto -c /etc/mosquitto/mosquitto.conf -d
 
本機測試mosquitto
在服務器上新建兩個shell,A和B
A 訂閱主題:
mosquitto_sub -t topicA
B 推送消息:
mosquitto_pub -t topicA -h localhost -m "topicA test"
CentOS 安裝Mosquitto及測試 - allegro_tyc - allegro_tyc的博客
 
遠程測試
下載安裝MQTT.fx,下圖設置服務器地址
CentOS 安裝Mosquitto及測試 - allegro_tyc - allegro_tyc的博客
 下圖設置訂閱的topic
CentOS 安裝Mosquitto及測試 - allegro_tyc - allegro_tyc的博客
下圖是服務器發布,MQTT.fx和本機訂閱收到的信息
CentOS 安裝Mosquitto及測試 - allegro_tyc - allegro_tyc的博客
下圖是MQTT.fx發布,服務器上訂閱收到的信息
CentOS 安裝Mosquitto及測試 - allegro_tyc - allegro_tyc的博客
至此已經將MQTT服務器初步搭建成功。感謝網絡上的一些文字的幫助
http://www.cnblogs.com/littleatp/p/4835879.html
http://blog.csdn.net/qhdcsj/article/details/45042515
 
 
 
 

./mosquitto_sub: error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory

 

 

執行命令:

sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1

ldconfig

即可


免責聲明!

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



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