mosquitto distributed cluster under centos6.8 mosquitto distributed cluster under centos6.8

 

mosquitto distributed cluster under centos6.8

343 people read   comments (0)   collection   report
  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
[html]  view plain copy  
  1. Modify the /etc/mosquitto/mosquitto.conf file of the master node 192.168.20.38 and add the following information:    
  2. # =================================================================  
  3. # bridge  
  4. # =================================================================  
  5. # bridge name  
  6. connection broker52  
  7. # node address  
  8. address 192.168.20.52:1883  
  9. # message subject  
  10. topic # both 2 "" ""  
  11. # bridge connection username  
  12. remote_username hthl_bridge  
  13. # bridge connection password  
  14. remote_password 123456  
  15. # bridge name  
  16. connection broker111  
  17. # node address  
  18. address 192.168.20.111:1883  
  19. # message subject  
  20. topic # both 2 "" ""  
  21. # bridge connection username  
  22. remote_username hthl_bridge  
  23. # bridge connection password  
  24. remote_password 123456  
  25. # Bridge connection protocol version MQTT3.11  
  26. bridge_protocol_version mqttv311  
  27. # Whether to publish bridge status information  
  28. notifications true  
  29. # Whether to clear the message in the remote server when the bridge is disconnected  
  30. cleansession true  
  31. # Check whether the bridge connection is available or not  
  32. try_private true  
  33. # bridge mode  
  34. start_type automatic  
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!

Guess you like

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