Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Configure RabbitMQ 3.6.3 clusters and high availability on CentOS7

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Configuring RabbitMQ 3.6.3 Clusters and High Availability Clusters on CentOS 7 Overview RabbitMQ clustering is performed through Erlang's distributed feature (magic cookie authentication node), and each RabbitMQ service is a peer node, that is, each node provides services for client connections, sending and receiving messages.

These nodes replicate the message queue structure through RabbitMQ HA queues (mirror queues). In this article, three nodes are set up, and all of them are disk nodes (all nodes maintain the same state, nodes are completely equal). As long as any node can work, RabbitMQ cluster can provide services to the outside world.

CentOS 7, 64-bit RabbitMQ 3.6.3HAProxy 1.6.0

RabbitMQ cluster is installed on 3 nodes: 192.168.1.1, 192.168.1.2, 192.168.1.3; HAProxy is installed on www.example.com to provide RabbitMQ Load Balancer service externally. Configuration Step 1. Modify/etc/hosts and configure ssh mutual secret login [root@node1~]#vi/etc/hosts192.168.1.1 node1192.168.1.2 node2192.168.1.3 node32. Install erlang and rabbitmq on nodes 192.168.1.1, 192.168.1.2 and 192.168.1.3, and then open RabbitMQ monitoring plugin. [root@node1 ~]# wget http://www.rabbitmq.com/releases/erlang/erlang-18.1-1.el7.centos.x86_64.rpm[root@node1 ~]# wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.3/rabbitmq-server-3.6.3-1.noarch.rpm[root@node1 ~]# rpm -ivh erlang-18.1-1.el7.centos.x86_64.rpm[root@node1 ~]# rpm -ivh rabbitmq-server-3.6.3-1.noarch.rpm[root@node1 ~]# rabbitmq-plugins enable rabbitmq_management3. Set Erlang Cookies

Erlang Cookie file:/var/lib/rabbitmq/. erlang.cookie. Here, copy the file in node 1 to node 2 and node 3. Since the permission of this file is 400, you need to modify the permission of this file in node 2 and node 3 to 777 first, then copy the file in node 1 to node 2 and node 3, and finally modify the permissions and the users/groups to which it belongs.

[root@node1 ~]# chmod 777 /var/lib/rabbitmq/.erlang.cookie[root@node1 ~]# scp -r /var/lib/rabbitmq/.erlang.cookie root@node2:/var/lib/rabbitmq/.erlang.cookie[root@node1 ~]# scp -r /var/lib/rabbitmq/.erlang.cookie root@node3:/var/lib/rabbitmq/.erlang.cookie[root@node1 ~]# chmod 400 /var/lib/rabbitmq/.erlang.cookie[root@node1 ~]# chown rabbitmq /var/lib/rabbitmq/.erlang.cookie[root@node1 ~]# chgrp rabbitmq /var/lib/rabbitmq/.erlang.cookie4. Run each node with the-detached parameter [root@node1~]#rabbitmqctl stop [root@node1~]#rabbitmq-server-detached5. The cluster will be node 2, node3 and node1 form cluster [root@node2~]#rabbitmqctl stop_app [root@node2~]#rabbitmqctl join_cluster rabbit@node1 [root@node2~]#rabbitmqctl start_app #---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#[root@node3~]#rabbitmqctl stop_app[root@node3~]#rabbitmqctl join_cluster rabbit@node1[root@node3~]#rabbitmqctl start_app

Node 2 and node 3 are also automatically connected; if you want to use memory nodes, you can join the cluster using the following command:

[root@node2 ~]# rabbitmqctl join_cluster *--ram* rabbit@node1

After the cluster is configured, you can execute the following command on any RabbitMQ node to see if the cluster configuration is successful.

rabbitmqctl cluster_status

6. Set mirror queue policy

Execute the following command on any node

[root@node1 ~]# rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'

Set all queues to mirror queues, i.e. queues will be replicated to each node and the state of each node will remain constant. After completing these 6 steps, RabbitMQ high availability cluster has been set up, the last step is to set up the equalizer.

Tip: RabbitMQ configuration file is:/etc/rabbitmq/rabbitmq. config RabbitMQ environment configuration file is:/etc/rabbitmq/rabbitmq-env. conf 7. Install and configure HAProxy

Install HAProxy on www.example.com and modify/etc/haproxy/haproxy. cfg.

[root@snails ~]# haproxy -vv[root@snails ~]# vi /etc/haproxy/haproxy.cfglisten rabbitmq_cluster 0.0.0.0:5672mode tcpbalance roundrobinserver 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 3server node2 192.168.1.3:5672 check inter 2000 rise 2 fall 3listen private_monitoring :8100 mode http option httplog stats enable #Set haproxy monitoring address to http://localhost:8100/rabbitmq-stats stats uri /rabbitmq-stats stats refresh 5s [root@snails~]#/usr/sbin/haproxy-D-f/etc/haproxy/haproxy. cfg-p/var/run/haproxy. pid Success, let's verify the effect!!!!!! 1

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report