- Cluster overview
- Environment
- Configuration steps
Cluster overview Through the distributed nature of Erlang (through the Magic Cookie Authentication node) for the RabbitMQ cluster, each RabbitMQ service is a peer node, that is, each node provides services to the client connection for sending and receiving messages. These nodes replicate the message queue structure through the RabbitMQ HA queue (mirror queue). In this scenario, 3 nodes are built, and all are disk nodes (all node states are consistent and nodes are fully equal), so long as any one node can work, the RabbitMQ cluster can provide services to the outside. Environment
- CentOS 6.4, 64-bit
- RabbitMQ 3.1.5
- HAProxy 1.4.22
The RabbitMQ cluster is installed on 3 nodes: 192.168.1.1, 192.168.1.2, 192.168.1.3;haproxy are installed on the 192.168.1.4 to provide RabbitMQ equalization externally. Download the required installation package. Configuration steps
1. Installing Erlang, RABBITMQInstall on the 192.168.1.1, 192.168.1.2, 192.168.1.3 three nodes, and then turn on the RabbitMQ monitoring plugin:
rabbitmq-plugins enable rabbitmq_management |
2. Modify/etc/hostsDescription of the 3 nodes added to the cluster:
192.168.1.1 node1 192.168.1.2 node2 192.168.1.3 node3 |
3. Setting Up Erlang CookiesErlang Cookie file:/var/lib/rabbitmq/.erlang.cookie. Here will node1 the file copy to Node2, Node3, because this file permissions is 400, so you need to first modify the Node2, node3 the file permission is 777:
# chmod 777 /var/lib/rabbitmq/.erlang.cookie |
Then copy the file in Node1 to Node2, NODE3, and finally modify the permissions and the owning user/group back:
# chmod 400 /var/lib/rabbitmq/.erlang.cookie # chown rabbitmq /var/lib/rabbitmq/.erlang.cookie # chgrp rabbitmq /var/lib/rabbitmq/.erlang.cookie |
4. Run each node using the-detached parameter
# rabbitmqctl stop # rabbitmq-server -detached |
5. Forming a clusterNode2, Node3, and Node1 are organized into clusters:
node2 # rabbitmqctl stop_app node2 # rabbitmqctl join_cluster [email protected] node2 # rabbitmqctl start_app node3 # rabbitmqctl stop_app node3 # rabbitmqctl join_cluster [email protected] node3 # rabbitmqctl start_app |
At this point Node2 and Node3 also automatically establish a connection, and if you want to use a memory node, you can use Node2 # Rabbitmqctl Join_cluster
--ram[Email protected] Join the cluster. After the cluster is configured, you can perform rabbitmqctl cluster_status on any node of RabbitMQ to see if the cluster configuration is successful.
6. Set the mirroring queue policyExecute on any of the nodes:
# rabbitmqctl set_policy ha-all "^" ‘{"ha-mode":"all"}‘ |
All queues are set to the mirror queue, that is, the queues are copied to each node, and the state of each node remains. After completing these 6 steps, the RabbitMQ high-availability cluster has been set up, and the last step is to build the equalizer.
7. Install and configure the HAProxyInstall HAProxy on 192.168.1.4, and then modify the/etc/haproxy/haproxy.cfg:
listen rabbitmq_cluster 0.0.0.0:5672 mode tcp balance roundrobin server node1 192.168.1.1:5672 check inter 2000 rise 2 fall 3 server node2 192.168.1.2:5672 check inter 2000 rise 2 fall 3 server node2 192.168.1.3:5672 check inter 2000 rise 2 fall 3 |
----EOF----
Go RabbitMQ clusters with highly available configurations