Mqtt--linux installation Deployment (CentOS)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.