Introduction and construction of mosquitto under centos6.8 Introduction and construction of mosquitto under centos6.8

 

Introduction and construction of mosquitto under centos6.8

216 people read   comments (0)   collection   report
  Classification:
killed (3 
1. Introduction to Mosquitto
An open source message broker software that implements the message push protocol MQTT v3.1, provides a lightweight, publishable/subscribable message push mode,
making short message communication between devices simple, such as Now widely used in low-power sensors, mobile phones, embedded computers, microcontrollers and other mobile devices.
A typical application case is the remote monitoring and automation implemented at home by Andy Stanford-ClarkMosquitto (one of the founders of the MQTT protocol).
And in the speech at OggCamp, the MQTT protocol was elaborated.
2. Required installation package
libwebsockets-2.4.1.tar.gz , mosquitto-1.4.14.tar.gz
After downloading, upload them to the server/home directory respectively
3. Download address
libwebsockets:https://github.com/warmcat/libwebsockets/releases
mosquitto: https://github.com/eclipse/mosquitto/releases
4. Install dependencies
#yum -y install gcc gcc-c++ openssl-devel c-ares-devel libuuid-devel wget cmake xmlto
5. Add websocket support
cd / home
tar -zxvf libwebsockets-2.4.1.tar.gz
cd libwebsockets-2.4.1
mkdir bulid
cd bulid
cmake ..
make && make install
6. install mosquitto
6.1 unzip
cd / home
tar -zxvf mosquitto-1.4.14.tar.gz
6.2 add websocket support
Modify the config.mk file to make the later compiled mosquitto file support websocket
cd mosquitto-1.4.14
Find the config.mk file in the mosquitto-1.4.14 directory and change WITH_WEBSOCKETS:=no in the config.mk file to yes
# Build with websockets support on the broker.
WITH_WEBSOCKETS:=yes
After modification, save.
6.3 Installation
make && make install
If the installation is over, the error is as follows:
warning: failed to load external entity "/usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl"
compilation error: file manpage.xsl line 3 element import
xsl:import : unable to load /usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl
compilation error: file mosquitto.8.xml line 4 element refentry
xsltParseStylesheetProcess : document is not a stylesheet
make[1]: *** [mosquitto.8] Error 5
make[1]: Leaving directory `/home/mosquitto-1.4.14/man'
make: *** [docs] Error 2
Then modify /home/mosquitto-1.4.14/man/manpage.xsl
将<xsl:import href="/usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl"/>
改为:<xsl:import href="/usr/share/sgml/docbook/xsl-stylesheets-1.75.2/manpages/docbook.xsl"/>
Re-execute: make && make install command
If the library file of libwebsockets cannot be found when executing the program, execute the following command to make a symbolic link for the library)
ln -s /usr/local/lib/libwebsockets.so.6 /usr/lib64/libwebsockets.so.6
groupadd mosquitto
useradd -g
mosquitto mosquitto 6.4 Create mosquitto.conf, pwfile files
cd /etc/mosquitto/
cp mosquitto.conf.example mosquitto.conf
cp pwfile.example pwfile
cp aclfile.example aclfile

6.5 mosquitto.conf modify the configuration as follows:

[html]  view plain copy  
  1. # =================================================================  
  2. # General configuration  
  3. # =================================================================  
  4. # PID of the service process  
  5. pid_file /var/run/mosquitto.pid  
  6. # Service port number  
  7. port 1883  
  8. # websockets port number  
  9. listener 9090  
  10. # Add websockets protocol support  
  11. protocol websockets  
  12. # Maximum number of connections, -1 means no limit  
  13. max_connections -1  
  14. # System user of the service process  
  15. user mosquitto  
  16.   
  17. # =================================================================  
  18. # Security  
  19. # =================================================================  
  20. # Do not allow anonymous users  
  21. allow_anonymous false  
  22. # User/password file, default format: username:password  
  23. password_file /etc/mosquitto/pwfile  
  24. # Configure user access control  
  25. acl_file /etc/mosquitto/aclfile  
  26.   
  27. # =================================================================  
  28. #Persistence configuration  
  29. # =================================================================  
  30. # Interval time for automatic message saving: write to disk once every 30 minutes by default, 0 means that mosquitto is closed before writing to disk  
  31. autosave_interval 1800  
  32. # The switch of the message auto-save function  
  33. autosave_on_changes false  
  34. # Persistence function switch  
  35. persistence true  
  36. # Persist the DB file  
  37. persistence_file mosquitto.db  
  38. # Persistent DB file directory  
  39. persistence_location /usr/mosquitto/  
  40.   
  41. # =================================================================  
  42. # Logging  
  43. # =================================================================  
  44. # 4 log modes: stdout, stderr, syslog, topic  
  45. # Log path: none means no log, this configuration can improve performance  
  46. log_dest file /usr/mosquitto/mosquitto.log  
  47. # Select the level of the log (multiple items can be set)  
  48. log_type error  
  49. # Whether to record client connection information  
  50. #connection_messages true  
  51. # Whether to record log time  
  52. #log_timestamp true  

6.6 Create User and Password

mosquitto_passwd -c /etc/mosquitto/pwfile hthl_pub
After entering the command, the console will prompt to enter the password of the new user. After entering the password twice in a row, a pwfile file will be generated.
Note that the mosquitto_passwd -c command will only generate a file containing only one user at a time. If you want to store multiple users in passwd.conf,
You can use the mosquitto_passwd -b command: 
mosquitto_passwd -b [finally generated password_file] [username] [password]
mosquitto_passwd -b /etc/mosquitto/pwfile hthl_sub 123456
The mosquitto_passwd -D command deletes a user
mosquitto_passwd -D [finally generated password_file] [username]

6.7 aclfile modify the configuration as follows:

[html]  view plain copy  
  1. #This only affects clients with username "hthl_pub".  
  2. user hthl_pub  
  3. topic write hthl/#  
  4. # This only affects clients with username "hthl_sub".  
  5. user hthl_sub  
  6. topic read hthl/#  

6.8 Create a storage directory

mkdir /usr/mosquitto
chown -R mosquitto /usr/
mosquitto 7. Start mqtt
mosquitto -c /etc/mosquitto/mosquitto.conf -d
8. Push test
mosquitto_sub -h 192.168.20.38 -t hthl/hyt -u hthl_sub -P 123456
mosquitto_pub -h 192.168.20.38 -t hthl/hyt -u hthl_pub -P 123456 -m "Hello, world!"
9. Error resolution
During installation, or during testing, you may encounter errors:
mosquitto_sub: error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory
Solution:
# cat /etc/ld.so.conf
# echo "/usr/local/lib">>/etc/ld.so.conf
# ldconfig

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324890113&siteId=291194637