Message middleware Rabbitmq

Table of Contents

1. What is message middleware?

rabbitmq

Common cluster preparation environment

2. Install rabbitmq

Upload rabbitmq package

Installed on all three servers

Start rabbitmq service

Open rabbitmq’s web access interface (operate on all three platforms)

?edit

Enable user remote login (operate on all three stations)

Restart the rabbitmq service (operate on all three servers)

Check whether the port is started successfully

Browser test to see if it can be accessed normally

3. Deploy rabbitmq cluster

Add domain name resolution (executed on all three stations)

Create the data storage directory and log storage directory (executed on all three servers)

Create configuration file (executed on all three machines)

Build erlang cluster image

Add rabbitmq-2 and rabbitmq-3 as memory nodes to the rabbitmq-1 node cluster (execution on servers 2 and 3)

View cluster status (executed on any server)

Browser test cluster deployment is complete

4. Configure the mirror cluster

Create a mirror cluster (executed on all three servers)

Check again in the browser whether the configuration is successful

experiment


1. What is message middleware?

Message middleware can also be called message queue, which refers to the use of efficient and reliable message delivery mechanism for platform-independent data exchange, and the integration of distributed systems based on data communication. By providing message passing and message queuing models, process communication can be extended in a distributed environment.

Rabbitmq

RabbitMQ was released in 2007. It is a reusable enterprise messaging system based on AMQP (Advanced Message Queuing Protocol). It is one of the most mainstream message middleware currently.

The current mainstream message middleware includes RabbitMQ, Kafka, ActiveMQ, RocketMQ, etc.

Features:

Reliability, scalability, high availability, multiple protocols, multi-language clients, management interface, plug-in mechanism

Ordinary cluster preparation environment

Preparation:

Turn off firewall and selinux

rabbitmqrpm package (version 3.7.10): Link: https://pan.baidu.com/s/1I8YQddCiJXzzcXkpeW03jQ
Extraction code: tcht

rabbitmq and erlang compatible version

https://www.rabbitmq.com/which-erlang.htmlicon-default.png?t=N7T8https://www.rabbitmq.com/which-erlang.html
erlang version selection
https://packagecloud.io/rabbitmq/erlangicon-default.png?t=N7T8https://packagecloud.io/rabbitmq/erlang
rabbitmq version selection
https://www.rabbitmq.com/news.htmlicon-default.png?t=N7T8https://www.rabbitmq.com/news.html

Three servers:

Install rabbitmq and related dependencies

yum install -y epel-release gcc-c + + unixODBC unixODBC-devel openssl-devel ncurses-devel lrzsz net-tools
Host name IP address
rabbitmq-1

192.168.50.137

rabbitmq-2 192.168.50.141
rabbitmq-3 192.168.50.142

2. Install rabbitmq

Upload rabbitmq package

[root@rabbitmq-1 ~]# rz

[root@rabbitmq-2 ~]# rz

[root@rabbitmq-3 ~]# rz

[root@rabbitmq-1 ~]# ll

Installed on all three servers

[root@rabbitmq-1 ~]# yum -y install rabbitmq-server-3.7.10-1.el7.noarch.rpm

yum -y install rabbitmq-server-3.7.10-1.el7.noarch.rpm

[root@rabbitmq-1 ~]# yum -y install erlang-21.3.8.21-1.el7.x86_64.rpm

yum -y install erlang-21.3.8.21-1.el7.x86_64.rpm

Start rabbitmq service

[root@rabbitmq-1 ~]# systemctl daemon-reload

[root@rabbitmq-1 ~]# systemctl start rabbitmq-server

[root@rabbitmq-2 ~]# systemctl daemon-reload

[root@rabbitmq-2 ~]# systemctl start rabbitmq-server

[root@rabbitmq-3 ~]# systemctl daemon-reload

[root@rabbitmq-3 ~]# systemctl start rabbitmq-server

systemctl daemon-reload
systemctl start rabbitmq-server

Enable rabbitmq’s web access interface (operate on all three stations)

[root@rabbitmq-1 ~]# rabbitmq-plugins enable rabbitmq_management

[root@rabbitmq-2 ~]# rabbitmq-plugins enable rabbitmq_management

[root@rabbitmq-3 ~]# rabbitmq-plugins enable rabbitmq_management

rabbitmq-plugins enable rabbitmq_management

Enable user remote login (operate on all three stations)

#Modify the configuration file of rabbitmq

[root@rabbitmq-1 ~]# cp /usr/share/doc/rabbitmq-server-3.7.10/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config

cp /usr/share/doc/rabbitmq-server-3.7.10/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config

[root@rabbitmq-1 ~]# vim /etc/rabbitmq/rabbitmq.config

vim /etc/rabbitmq/rabbitmq.config

Restart rabbitmq service (operate on all three stations)

[root@rabbitmq-1 ~]# systemctl restart rabbitmq-server

[root@rabbitmq-2 ~]# systemctl restart rabbitmq-server

[root@rabbitmq-3 ~]# systemctl restart rabbitmq-server

systemctl restart rabbitmq-server

Check whether the port is started successfully

[root@rabbitmq-1 ~]# netstat -lntp

[root@rabbitmq-2 ~]# netstat -lntp

[root@rabbitmq-3 ~]# netstat -lntp

netstat -lntp

Browser test whether it can be accessed normally

Access port 15672

3. Deploy rabbitmq cluster

Add domain name resolution (executed on all three stations)

[root@rabbitmq-1 ~]# vim /etc/hosts

vim /etc/hosts
192.168.50.137 rabbitmq-1
192.168.50.141 rabbitmq-2
192.168.50.142 rabbitmq-3

Create data storage directory and log storage directory (executed on all three servers)

[root@rabbitmq-1 ~]# mkdir -p /data/rabbitmq/data

[root@rabbitmq-1 ~]# mkdir -p /data/rabbitmq/logs

[root@rabbitmq-1 ~]# chmod 777 -R /data/rabbitmq

[root@rabbitmq-1 ~]# chown rabbitmq.rabbitmq /data/ -R

mkdir -p /data/rabbitmq/data
mkdir -p /data/rabbitmq/logs
chmod 777 -R /data/rabbitmq
chown rabbitmq.rabbitmq /data/ -R

Create configuration file (execute on all three stations)

[root@rabbitmq-1 ~]# vim /etc/rabbitmq/rabbitmq-env.conf

vim /etc/rabbitmq/rabbitmq-env.conf

Insert the following:

RABBITMQ_MNESIA_BASE=/data/rabbitmq/data
RABBITMQ_LOG_BASE=/data/rabbitmq/logs

Restart rabbitmq

[root@rabbitmq-1 ~]# systemctl restart rabbitmq-server

systemctl restart rabbitmq-server

Build erlang cluster image

Cluster document storage location:

Use decompression to install the deployed rabbitmq location: home/.erlang.cookie

The location of rabbitmq installed using rpm and other installation packages: /var/lib/rabbitmq

cat /var/lib/rabbitmq/.erlang.cookie

Remote copy to other two nodes

[root@rabbitmq-1 ~]# scp /var/lib/rabbitmq/.erlang.cookie 192.168.50.141:/var/lib/rabbitmq/

[root@rabbitmq-1 ~]# scp /var/lib/rabbitmq/.erlang.cookie 192.168.50.142:/var/lib/rabbitmq/

scp /var/lib/rabbitmq/.erlang.cookie 192.168.50.141:/var/lib/rabbitmq/
scp /var/lib/rabbitmq/.erlang.cookie 192.168.50.142:/var/lib/rabbitmq/

Restart rabbitmq service

[root@rabbitmq-2 ~]# systemctl restart rabbitmq-server

[root@rabbitmq-3 ~]# systemctl restart rabbitmq-server

systemctl restart rabbitmq-server

Add rabbitmq-2 and rabbitmq-3 as memory nodes to the rabbitmq-1 node cluster (2, 3 server execution)

[root@rabbitmq-2 ~]# rabbitmqctl stop_app

[root@rabbitmq-3 ~]# rabbitmqctl stop_app

rabbitmqctl stop_app

If the node command is stopped and an error is reported, the execution

[root@rabbitmq-2 ~]# chmod 400 /var/lib/rabbitmq/.erlang.cookie

[root@rabbitmq-2 ~]# chown rabbitmq.rabbitmq /var/lib/rabbitmq/.erlang.cookie

chmod 400 /var/lib/rabbitmq/.erlang.cookie
chown rabbitmq.rabbitmq /var/lib/rabbitmq/.erlang.cookie

Re-execute the stop node command

Data reset

[root@rabbitmq-2 ~]# rabbitmqctl reset

rabbitmqctl reset

Add memory node

[root@rabbitmq-2 ~]# rabbitmqctl join_cluster –ram rabbit@rabbitmq-1

rabbitmqctl join_cluster --ram rabbit@rabbitmq-1

Now rabbitmq-2 and rabbitmq-3 are memory nodes, and the default startup is rabbitmq-1 disk node.

Start node

[root@rabbitmq-2 ~]# rabbitmqctl start_app

rabbitmqctl start_app

Extensions:

In the RabbitMQ cluster, there must be at least two disk nodes, otherwise the queue metadata will not be written to the cluster. When the disk node goes down, the cluster will not be able to write new queue metadata information.

<1>Change node type

The rabbit service must be stopped: rabbitmqctl stop_app

You can use the command rabbitmqctl change_cluster_node_type disc(ram), provided that

<2>Join the cluster using disk nodes

rabbitmqctl join_cluster rabbit@rabbitmq-1

View cluster status (executed on any server)

[root@rabbitmq-1 ~]# rabbitmqctl cluster_status

rabbitmqctl cluster_status

Whether the deployment of the browser test cluster has been completed

Access port 15672

Create a queue

Created successfully

4. Configure mirror cluster

Create a mirror cluster (execute on all three servers)

[root@rabbitmq-1 ~]# rabbitmqctl set_policy ha-all “^” ‘{“ha-mode”:”all”}’

[root@rabbitmq-2 ~]# rabbitmqctl set_policy ha-all “^” ‘{“ha-mode”:”all”}’

[root@rabbitmq-3 ~]# rabbitmqctl set_policy ha-all “^” ‘{“ha-mode”:”all”}’

rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'

Parameter explanation:

rabbitmqctl set_policy [-p Vhost] Name Pattern Definition [Priority]

-p Vhost: vhost name, “^” matches all queues, ha-all policy name is ha-all, ‘{“ha-mode”:”all”}’ policy mode is all, that is, copied to all nodes, including new Add nodes.

Strategy description:

Pattern: Queue matching pattern (regular expression)
Definition: Image definition, including three parts ha-mode, ha-params, ha-sync-mode
ha-mode: Specifies the mode of the mirror queue. The valid value is all/exactly/nodes

all: means mirroring on all nodes in the cluster

exactly: means mirroring on the specified number of nodes. The number of nodes is specified by ha-params.
nodes: means mirroring on the specified node, the node name is specified through ha-params
ha-params: parameters needed for ha-mode mode
ha-sync-mode: synchronization mode of messages in the queue, valid values are automatic and manual
priority: optional parameter, priority of policy

Check again in the browser whether the configuration is successful

Experiment

Create a vhost (virtual host) and add the main queue to user permissions

Add completed