Installation and configuration of CentOS7.0 Mosquitto __mqtt

Source: Internet
Author: User
Join Yum Source

Create a new Mosquitto.repo file in the/etc/yum.repos.d/directory that writes:

[Home_oojah_mqtt]
  Name=mqtt (centos_centos-7)
  type=rpm-md
  baseurl=http://download.opensuse.org/repositories/home:/oojah:/ mqtt/centos_centos-7/
  gpgcheck=1
  gpgkey=http://download.opensuse.org/repositories/home:/oojah:/mqtt/ Centos_centos-7//repodata/repomd.xml.key
  enabled=1
Installing the client and service side
Yum Search all Mosquitto

mosquitto-clients.x86_64:mosquitto command line publish/subscribe clients
Mosquitto-debuginfo.x86_64:debug Information for package Mosquitto
libmosquitto-devel.x86_64:mqtt C Client Librar Y Development Files
libmosquitto1.x86_64:MQTT C client library
LIBMOSQUITTOPP-DEVEL.X86_64:MQTT C + + client Lib  Rary Development Files
Libmosquittopp1.x86_64:MQTT C + + client library
Mosquitto.x86_64:MQTT version 3.1/3.1.1 Compatible message broker



Yum install mosquitto-clients.x86_64
yum install mosquitto.x86_64

Focus on the installation of the client and the service side can be, the rest can choose to install according to their own needs! Configure Mosquitto

cd/etc/mosquitto/
important configuration file is mosquitto.conf
# Place your local configuration in/etc/mosquitto/conf.d/   
 pid_file/var/run/mosquitto.pid

 Persistence True
 persistence_location/var/lib/mosquitto/

  #log_dest file/var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d
The custom profile is placed in the/etc/mosquitto/conf.d/folder and the file is extended with. conf. Detailed Configuration parameter Reference Mosquitto.conf.example
# ================================================================= # General Configuration # ====================== =========================================== # Client heartbeat interval Time #retry_interval 20 # System State Refresh Time #sys_interval 10 # system resources Payback time, 0 means processing #store_clean_interval 10 # The PID of the service process #pid_file/var/run/mosquitto.pid # service Process System User #user Mosquitto # Customer Maximum concurrent number of end heartbeat messages #max_inflight_messages 10 # Client Heartbeat message Cache queue #max_queued_messages 100 # used to set the expiration time for client long connections, and never expire by default #persistent_cli Ent_expiration # ================================================================= # Default Listener # ============= ==================================================== # Service-bound IP address #bind_address # service-bound port number #port 1883 # Maximum number of connections allowed,- 
1 means no Limit #max_connections-1 # CAFILE:CA certificate file # CAPATH:CA certificate Directory # CERTFILE:PEM certificate # KEYFILE:PEM key file #cafile #capath #certfile #keyfile # A certificate must be provided to ensure data security #require_certificate false # If Require_certificate value is True,use_identity_as_username must also be true # Use_identity_as_username false # Enable PSK (Pre-shAred-key) Support #psk_hint # SSL/TSL encryption algorithm, you can use the "OpenSSL ciphers" command to get the # as the output of that command. #ciphers # ================================================================= # persistence # ======================= ========================================== # Messages are automatically saved at intervals #autosave_interval 1800 # Message automatic save function switch #autosave_on_changes False # Switch Persistence true # Persistent db file #persistence_file mosquitto.db # Persistent DB file directory #persistence_location/var/lib/mosq uitto/# ================================================================= # Logging # ============================= ==================================== # 4 Log modes: stdout, stderr, syslog, topic # None means no log, this configuration can promote a little bit of performance log_dest None # Select the level of the log (multiple items can be set) #log_type error #log_type warning #log_type Notice #log_type information # whether to log client connection information #connection_message s true # whether log time is logged #log_timestamp true # ================================================================= # security # = = =============================================================== # prefix limit for client ID,Can be used to guarantee security #clientid_prefixes # Allow anonymous users to #allow_anonymous true # User/password file, default format: Username:password #password_file # PSK format password file, Default format: Identity:key #psk_file # pattern Write Sensor/%u/data # ACL permissions configuration, commonly used syntax as follows: # User restrictions: Users <username> # Topic Restrictions: Topic [RE Ad|write] <topic> # Regular limit: pattern write sensor/%u/data #acl_file # ============================================== =================== # Bridges # ================================================================= # allows "bridging" to be used between services Mode (available for distributed deployment) #connection <name> #address  
Start (two ways two choose one) 
Mosquitto-c/etc/mosquitto/mosquitto.conf-d
Sudo/etc/init.d/mosquitto start
Test

One, open another terminal window, run the Subscriber mosquitto_sub:

Attention:

Message push publications and subscriptions have themes, options [-t] topics, namely: Mosquitto-t themes

To specify the user name, add the option [-i] username, which is: mosquitto_sub-t theme-I subscriber

Mosquitto_sub-t Mqtt

Second, open another terminal window, run the release program Mosquitto_pub:

Specify the subject of the message push, the Publisher end user name, and the message:

Mosquitto_pub-t Theme-I publishing end-h host-M Hello

* Note: If there are spaces in the middle of the message, enclose the message in quotation marks.

Mosquitto_pub-h localhost-t mqtt-m "Hello World."

At this point the previous subscription window will receive the word "Hello World". Overall, there are no problems with the installation configuration, and the installation and testing work can be done smoothly

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.