Configuring RabbitMQ 3.6.3 cluster and high availability on CentOS7

Overview of clusters

         RabbitMQ cluster is implemented through Erlang's distributed feature (magic cookie authentication node). Each RabbitMQ service is peer-to-peer node, that is, each node provides services to the client to connect, send and receive messages.

These nodes replicate message queue structure through RabbitMQ HA queue (mirror queue). In this paper, three nodes are set up, and they are all disk nodes (all nodes are in the same state, and the nodes are completely equivalent). As long as any node can work, RabbitMQ cluster can provide external services.

Environmental Science

  • CentOS 7, 64 bit
  • RabbitMQ 3.6.3
  • HAProxy 1.6.0
    RabbitMQ cluster is installed on three nodes: 192.168.1.1, 192.168.1.2 and 192.168.1.3; HAProxy is installed on 192.168.1.4 to provide external RabbitMQ load balancing service.

Configuration steps

1. Modify / etc/hosts and configure ssh mutual password free login

[root@node1 ~]# vi /etc/hosts
192.168.1.1 node1
192.168.1.2 node2
192.168.1.3 node3

2. Install erlang and rabbitmq

At 192.168.1.1,192.168.1.2,192.168.1.3 Install on three nodes and turn on RabbitMQ Monitoring plug-ins.
[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_management

3. Set Erlang Cookie

Erlang Cookie file: / var/lib/rabbitmq/.erlang.cookie. Here, the file of node1 is copied to node2 and node3. Because the file permission is 400, you need to modify the file permission in node2 and node3 to 777, then copy the file in node1 to node2 and node3, and finally modify the permission and the user / group 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.cookie

4. Use the - detached parameter to run each node

[root@node1 ~]# rabbitmqctl stop
[root@node1 ~]#  rabbitmq-server -detached

5. Form a cluster

take node2,node3 And node1 Clustering
[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

At this time, node2 and node3 will also automatically establish a connection; if you want to use memory nodes, you can use the following command to join the cluster.
[root@node2 ~]# rabbitmqctl join_cluster *--ram* rabbit@node1
After the cluster is configured, you can execute the following command on any node of RabbitMQ to check whether the cluster configuration is successful.

rabbitmqctl cluster_status

6. Set the mirror queue policy

Execute the following command on any node
[root@node1 ~]# rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'

Set all queues as mirror queues, i.e. the queues will be copied to each node, and each node will remain in the same state. After these six steps, RabbitMQ high availability cluster has been set up, and the last step is to set up equalizer.

Tips:
The configuration file for RabbitMQ is / etc/rabbitmq/rabbitmq.config
 The environment configuration file of RabbitMQ is / etc / RabbitMQ / RabbitMQ env.conf

7. Install and configure HAProxy

Install HAProxy on 192.168.1.4 and modify / etc/haproxy/haproxy.cfg.

[root@snails ~]# haproxy -vv
[root@snails ~]# vi /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

listen private_monitoring :8100
       mode    http
       option  httplog
       stats   enable
       #Set the monitoring address of haproxy 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

It's a success. Let's verify the effect together!!!!!!!!!! One

Keywords: Linux RabbitMQ Erlang RPM CentOS

Added by duckula on Wed, 20 Nov 2019 17:49:57 +0200