Classification:
killed (3
1. Install MQTT
Please refer to "Introduction and Construction of MQTT under CentOs 6.8" for installation, which will not be described here.
2. Environment introduction
192.168.20.38 master node
192.168.20.52 slave node
192.168.20.111 slave node
3. Cluster purpose
No matter which server is subscribed to the information, no matter which server the information is published on, the subscribers can receive the published information. There is a
proper called "bridging", and the way to achieve bridging requires modifying the config.mk and mosquitto.conf files. It is worth noting that if there are 10 servers in a
mosquitto cluster, the bridge connection is opened on each server, and then only the mosquitto.conf file on one server needs to be changed, and
the do not need to be changed. . Greatly facilitates cluster maintenance. If a new server is added or deleted, just modify
the .
4. Open the server bridge connection
Execute the following commands on the three servers respectively:
cd /home/mosquitto-1.4.14
vi config.mk
Find WITH_BRIDGE:=yes and remove the "#" sign from the signature to enable bridge connection mode. (It is enabled by default, in order to check it correctly)
WITH_BRIDGE:=yes
5. Create bridge client user and password
Execute the following commands on all three nodes:
mosquitto_passwd -b /etc/mosquitto/pwfile hthl_bridge 123456
6. Modify access control
Append to the aclfiles of the three nodes:
# This is a bridge user.
user hthl_bridge
topic #
Then restart the services individually.
7. Configure the bridge connection properties of mosquitto.conf
Note: Do not add this information to other nodes, otherwise the message will loop infinitely.
7. Test
7.1 Subscription
Execute on 38 nodes: mosquitto_sub -h 192.168.20.38 -t hthl/hyt -u hthl_sub -P 123456
Execute on node 52: mosquitto_sub -h 192.168.20.52 -t hthl/hyt -u hthl_sub -P 123456
Execute on node 111: mosquitto_sub -h 192.168.20.111 -t hthl/hyt -u hthl_sub -P 123456
7.2 Release
Execute on node 38: mosquitto_pub -h 192.168.20.38 -t hthl/hyt -u hthl_pub -P 123456 -m "Hello, world 38!"
Execute on node 52: mosquitto_pub -h 192.168.20.52 -t hthl/hyt -u hthl_pub -P 123456 -m "Hello, world 52!"
Execute on node 111: mosquitto_pub -h 192.168.20.111 -t hthl/hyt -u hthl_pub -P 123456 -m "Hello, world 111!"
The three windows of the subscription service will print the received messages respectively, realizing that no matter which server the information is subscribed to or the information is published on which server,
Subscribers can receive the published information! ok, the cluster is successful!
Please refer to "Introduction and Construction of MQTT under CentOs 6.8" for installation, which will not be described here.
2. Environment introduction
192.168.20.38 master node
192.168.20.52 slave node
192.168.20.111 slave node
3. Cluster purpose
No matter which server is subscribed to the information, no matter which server the information is published on, the subscribers can receive the published information. There is a
proper called "bridging", and the way to achieve bridging requires modifying the config.mk and mosquitto.conf files. It is worth noting that if there are 10 servers in a
mosquitto cluster, the bridge connection is opened on each server, and then only the mosquitto.conf file on one server needs to be changed, and
the do not need to be changed. . Greatly facilitates cluster maintenance. If a new server is added or deleted, just modify
the .
4. Open the server bridge connection
Execute the following commands on the three servers respectively:
cd /home/mosquitto-1.4.14
vi config.mk
Find WITH_BRIDGE:=yes and remove the "#" sign from the signature to enable bridge connection mode. (It is enabled by default, in order to check it correctly)
WITH_BRIDGE:=yes
5. Create bridge client user and password
Execute the following commands on all three nodes:
mosquitto_passwd -b /etc/mosquitto/pwfile hthl_bridge 123456
6. Modify access control
Append to the aclfiles of the three nodes:
# This is a bridge user.
user hthl_bridge
topic #
Then restart the services individually.
7. Configure the bridge connection properties of mosquitto.conf
- Modify the /etc/mosquitto/mosquitto.conf file of the master node 192.168.20.38 and add the following information:
- # =================================================================
- # bridge
- # =================================================================
- # bridge name
- connection broker52
- # node address
- address 192.168.20.52:1883
- # message subject
- topic # both 2 "" ""
- # bridge connection username
- remote_username hthl_bridge
- # bridge connection password
- remote_password 123456
- # bridge name
- connection broker111
- # node address
- address 192.168.20.111:1883
- # message subject
- topic # both 2 "" ""
- # bridge connection username
- remote_username hthl_bridge
- # bridge connection password
- remote_password 123456
- # Bridge connection protocol version MQTT3.11
- bridge_protocol_version mqttv311
- # Whether to publish bridge status information
- notifications true
- # Whether to clear the message in the remote server when the bridge is disconnected
- cleansession true
- # Check whether the bridge connection is available or not
- try_private true
- # bridge mode
- start_type automatic
7. Test
7.1 Subscription
Execute on 38 nodes: mosquitto_sub -h 192.168.20.38 -t hthl/hyt -u hthl_sub -P 123456
Execute on node 52: mosquitto_sub -h 192.168.20.52 -t hthl/hyt -u hthl_sub -P 123456
Execute on node 111: mosquitto_sub -h 192.168.20.111 -t hthl/hyt -u hthl_sub -P 123456
7.2 Release
Execute on node 38: mosquitto_pub -h 192.168.20.38 -t hthl/hyt -u hthl_pub -P 123456 -m "Hello, world 38!"
Execute on node 52: mosquitto_pub -h 192.168.20.52 -t hthl/hyt -u hthl_pub -P 123456 -m "Hello, world 52!"
Execute on node 111: mosquitto_pub -h 192.168.20.111 -t hthl/hyt -u hthl_pub -P 123456 -m "Hello, world 111!"
The three windows of the subscription service will print the received messages respectively, realizing that no matter which server the information is subscribed to or the information is published on which server,
Subscribers can receive the published information! ok, the cluster is successful!