What is RABBITMQ? MQ (Message queue) message middleware, which is generally deployed in cluster mode, mainly provides the receiving and sending of messages, and realizes the synchronization of messages between each micro-service. Principle Introduction RABBITMQ is based on the distributed nature of Erlang (RABBITMQ is implemented by the Erlang architecture, so rabbitmqctl initiates the Erlang node, And based on the Erlang node to connect the RABBITMQ node using the Erlang system, the correct Erlang cookie and node name are required during the connection, and the Erlang node is implemented by exchanging Erlang cookies for authentication. Therefore, when deploying RABBITMQ distributed cluster, we should install Erlang first and copy the cookie of one service to the other node RABBITMQ cluster, each RABBITMQ as peer node, that is, each node is provided to the client connection to receive and send the message. Nodes are divided into memory nodes and disk nodes, in general, should be established as disk nodes, in order to prevent the machine restarts after the message disappears; RABBITMQ's cluster cluster mode is generally divided into two types, normal mode and mirror mode. Message Queuing for Message Queuing entity replication via RABBITMQ ha mirror queue 1. In normal mode, take two nodes (rabbit01, rabbit02) as an example to illustrate. For a queue, the message entity exists only in one of the nodes rabbit01 (or rabbit02), rabbit01 and rabbit02 two nodes have only the same metadata, that is, the structure of the queue. When the message enters the queue of the RABBIT01 node, consumer consumes from the rabbit02 node, RABBITMQ temporarily transmits the message between rabbit01 and rabbit02, takes the message entity in a and sends it to consumer by B. So consumer should try to connect to each node and fetch messages from it. That is, for the same logical queue, a physical queue is established on multiple nodes. Otherwise, regardless of consumer even rabbit01 or rabbit02, the export always in rabbit01, will produce bottleneck. 2. In mirroring mode, the queue that needs to be consumed becomes the mirror queue, which exists on multiple nodes, so that ha high availability of RABBITMQ can be achieved. The effect is that the message entity is actively synchronizing between the mirrored nodes, rather than being temporarily read when consumer consuming data, as in normal mode. The disadvantage is that synchronous communication within the cluster consumes a large amount of network bandwidth. Structure diagram of RABBITMQ
Environment deployment
IP Address |
Host name |
Operating System |
Use |
192.168.92.145 |
Mq01 |
CentOS 7.4x86_64 |
Disk node |
192.168.92.156 |
Mq02 |
CentOS 7.4x86_64 |
Memory nodes |
192.168.92.157 |
Mq03 |
CentOS 7.4x86_64 |
Memory nodes |
Start deployment 1. Turn off firewall and SELinux (3 servers are off)
systemctl stop firewalld.servicesetenforce 0
2. Modify Host Name
1.MQ01 Server
hostnamectl set-hostname mq01.localdomain
2.MQ02 Server
hostnamectl set-hostname mq02.localdomain
3.MQ03 Server
hostnamectl set-hostname mq03.localdomain
3. Modify the three node hosts file to add the following to each of the three servers.
192.168.92.145 mq01192.168.92.156 mq02192.168.92.157 mq03
4. Three nodes configure Epel source, install RABBITMQ package
yum install epel-release -yyum install rabbitmq-server -y
5. Establishing a soft connection
ln -s /usr/lib/rabbitmq/bin/* /usr/bin
6. View the plugin's information
rabbitmq-plugins list
7. Enable the Rabbitmq_management service
rabbitmq-plugins enable rabbitmq_management
8. Start the RABBITMQ service
systemctl start rabbitmq-server.service
9. Use the following command to check three cluster states, currently independent of each other, without forming a cluster
rabbitmqctl cluster_status
10. Use the following command to view the port opening instructions correctly. (15672 and 55672 are RABBITMQ management ports, and 5672 are ports that communicate with producers and consumers.) )
netstat -ntap | grep 5672
11. Stop three servers
systemctl stop rabbitmq-server.service
12. Copy the mq01 cookie value to the MQ02 and MQ03 servers
vim /var/lib/rabbitmq/.erlang.cookie
13. Open 3 RABBITMQ Services
systemctl start rabbitmq-server.service
14. The following operations operate only on MQ02 servers and MQ03 servers
1. Close the RABBITMQ application
rabbitmqctl stop_app
2. Connect mq02, mq03 as Memory node and MQ01 disk node on MQ02 server, mq03 server respectively.
rabbitmqctl join_cluster --ram [email protected]
3. Start the RABBITMQ application
rabbitmqctl start_app
View the status of 3 RABBITMQ servers separately
Access RABBITMQ via browser input http://192.168.175.132:15672 (default user name: Guest Password: Guest)
RABBITMQ Message Queuing cluster configuration