OS Environment: CentOS6.5
1. Installation dependent
Yum-y install gcc gcc-c++ openssl-devel c-ares-devel libuuid-devel wget cmake
2, add websocket support for Mosquitto, install text socket library file , unzip
# tar ZXFV libwebsockets-v1.6-stable.tar.gz
3. Running WebSocket
# CD libwebsockets-v1.6-stable# mkdir bulid# CD bulid# cmake. # Make && make install
4, Installation Mosquitto
Download mqtt---mosquitto-1.4.8.tar.gz, unzip
# tar ZXFV mosquitto-1.4.8.tar.gz
5. Modify the Config.mk file to enable the subsequent compiled Mosquitto file support WebSocket
Config.mk file in the mosquitto-1.4.8 directory, change the with_websockets:=no in the Config.mk file to Yes
After saving, execute
# make && make install# ln-s/usr/local/lib/libwebsockets.so.6/usr/lib64/libwebsockets.so.6# groupadd mosquitto# useradd-g Mosquitto Mosquitto
6. Create mosquitto.conf, pwfile files
# cd/etc/mosquitto/
If the directory does not have mosquitto.conf and Pwfile
Perform
# CP Mosquitto.conf.example mosquitto.conf# CP pwfile.example Pwfile
Then modify the file mosquitto.conf,
511 allow_anonoymous True ... 537 Password_file/etc/mosquitto/pwfile
and add it at the end of the document
Port 1883listener 8080protocol websockets
7. Start Mqtt
# mosquitto-c/etc/mosquitto/mosquitto.conf
8. Testing
Open two additional terminals
Terminal One:
? This is actually a subscription to a message with the topic "MQTT". "Mqtt" is the main title, and if a client publishes a message with the subject "MQTT", the terminal will receive the content of the message.
Mosquitto_sub-t Mqtt
Terminal two:
? Here is a message with the topic "MQTT" with the content "Hello Mqtt".
Mosquitto_pub-h localhost-t mqtt-m "Hello Mqtt"
At this point the terminal will receive:hello mqtt
9. Error resolution
During the installation or during the test, you may encounter errors:
Mosquitto_sub:error while loading shared libraries:libmosquitto.so.1:cannot open Shared object file:no such file or di Rectory
Workaround:
# cat/etc/ld.so.conf# echo "/usr/local/lib" >>/etc/ld.so.conf# ldconfig
Mqtt--linux installation Deployment (CentOS)