Mosquitto Build Android Push Service (ii) Mosquitto cluster building

Source: Internet
Author: User

article steel to:

1. Double-server Setup

2. Multi-server Setup

One, Mosquitto distributed cluster deployment

If you need to do a large amount of concurrency when you need to consider doing cluster processing, but I found in the data is not much, so I tidied up a simple mosquitto cluster mode.

First, the cluster requires more than 2 Mosquitto servers. Install the same way.

First understand the logical diagram of the next Mosquitto cluster mode, as follows:

As you can see, subscribers can receive published information regardless of whether they subscribe to the information on that server or publish information on that server. So next we set up the cluster server, in order to facilitate the demonstration of only 2 servers between the cluster building.

A proper noun for cluster deployment is called "Bridging," and implementing bridging requires modifying the CONFIG.MK and mosquitto.conf files. It is worth noting that if there are 10 servers to do the Mosquitto cluster, each server will open the bridge connection, and then only need to change the mosquitto.conf file on one server, the other server mosquitto.conf files do not need to make any changes. Greatly facilitates the maintenance of the cluster. If there is a new server join or delete only need to modify the master server mosquitto.conf.

1. Open the server Bridge connection

Go to the installation directory

CD mosquitto-1.4.9/

Open config.mk File

VI config.mk

Find With_bridge:=yes the Sign "#" to remove the Open bridge connection mode. (Default is on, for an error check)

2. Configuring Bridge connection properties for mosquitto.conf

Enter the ETC directory and open the mosquitto.conf file

cd/etc/mosquitto/

VI mosquitto.conf

Locate the Bridges node and add the following code below:

Connection MyTest
Address 10.19.22.53:1883
Topic room1/# both 2 sensor/myhouse/
Bridge_protocol_version mqttv311
Notifications True
Cleansession true
Try_private true
Start_type Automatic

---------------------------------------------------------------------------------

Connection connection name, you can take it anywhere

Address connection and port number, if you have more than one server, you can write multiple address

Topic theme name, "#" as a wildcard, indicating that the Publisher can follow any text in room1/

Both quality of service, 2 representative only once (you can view the details of MQTT in the first post)

sensor/local prefix identification, can be arbitrarily named

myhouse/remote prefix identification, can be arbitrarily named

Bridge_protocol_version mqttv311 Bridge Connection protocol version MQTT3.11

Notifications whether to publish the bridged status information

Whether to purge messages from the remote server when the Cleansession bridge disconnects

Start_type Bridge mode, there are currently three kinds: automatic, lazy, once

Save and exit after setting up OK.

3. Turn on the server

The first step is to ensure that the server is turned on first, and the second step restarts the Mosquitto service of the primary server. If the configuration is correct, the primary server will automatically connect to all slave servers when it is turned on, as shown below:

MyTest the name of my connection set in the Mosquitto.conf configuration, followed by the address and port number from the server

As shown, the primary server is already bridged with the slave server.

4. Verify Publish/Subscribe

The characteristics of a cluster can be subscribed to and published on any server, and Subscribers can receive messages sent to any server.

Test scenario: When you subscribe to a message from the server and publish a message in the primary server, subscribers from the server can receive messages from the primary server.

(1) Type the command from the server:

mosquitto_sub-t myhouse/room1/#Note: myhouse/is a remote prefix that writes topic in mosquitto.conf. room1/#是topic中的订阅主题(2) Type the command in the primary server:mosquitto_pub-t sensor/room1/temperature-m ' 26.3 'Note: sensor/is the local prefix for writing topic in mosquitto.conf. room1/is a subscription topic in topictemperature equivalent to "#" wildcard charactersIf the mosquitto.conf is configured correctly and the local prefix and the remote prefix are spelled properly, the message is displayed, indicating that the cluster configuration was successfulwhen you subscribe from the server, the primary server is sent, and the Subscriber receives the information from the server:

The above two-cluster configuration is complete. is also relatively simple. in the face of multi-cluster configuration is elaborated. second, multi-cluster deployment

Configuring 3 service clusters is the same as the 3+n theory, so here are 3 service clusters to be configured as demos.

1. Install the server

First, on the basis of the above 2 servers, and then add a server, configuration steps please refer to the second blog post.

2. Configure the server

Let's say 3 servers were

192.168.0.53

192.168.0.88

192.168.0.89

Where 53 is the primary server, 88 and 89 are from the server.

So on 88 and 89 only need to install the Mosquitto service properly, the other does not need to do any configuration.

The focus is on configuring the mosquitto.conf in 53.

Still open mosquitto.conf, find Bridge node, re-review the meaning of each configuration item in the node

#connection <name>
#address [
#topic <topic> [[[Out | in | both] qos-level] Local-prefix Remote-prefix]

I initially mistakenly think that the red font part is configured to use the second server, but the author is wrong. Each connection can have only one IP address, and the address red part is reserved for multiple IPs. (seems to be a backup of the former address, if the former address server hangs can immediately take over the standby server, the author has not confirmed)

If you want to add a server only need to re-added connection, address, topic node. So the bridge node becomes the following form:

 connection mytestaddress  192.168 . 0.88 :  topic room1  / # both 2  sensor/ myhouse/  connection mytest2address 192.168 . Span style= "Font-weight:bold" >0.89 : 1883  topic room1/# both 2  sensor/myhouse/ bridge_protocol_version Mqttv311notifications truecleansession truetry_private truestart_type automatic  

The red part is the newly added server. Restart the Mosquitto server.

3. Test subscription, Release

The test theory is similar to the first section:

Enter MOSQUITTO_SUB-T myhouse/room1/# subscription information in 88 and 89 servers respectively

Enter Mosquitto_pub-t sensor/room1/temperature-m ' 26.3 ' to publish messages in the 53 server

Colleagues 88 and 89 will receive the "26.3" message. If only one server receives the instructions, the configuration is problematic.

Above

The next step is to study the stress test and visual management tools of the cluster.

Mosquitto Build Android Push Service (ii) Mosquitto cluster building

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.