RabbiMQ is developed with Erang, clustering is very convenient, because Erlang is a distributed language by nature, but it does not support Load Balancing.
The RabbitMQ mode is roughly divided into the following three types:
(1) Single mode.
(2) Normal mode (the default cluster mode).
(3) Mirror mode (make the required queue into a mirror queue, which exists in multiple nodes, belongs to the HA scheme of RabbiMQ, and is more suitable for occasions that require high business reliability).
To realize the mirroring mode, you need to build a common cluster mode first, and then configure the mirroring mode on the basis of this mode to achieve high availability.
The cluster nodes of RabbitMQ include memory nodes and disk nodes. RabbitMQ supports the persistence of messages
That is, the data is written on the disk. The most suitable solution is to have both memory nodes and disk nodes.
Operating system | ip | hostname | configuration |
---|---|---|---|
centos 6.9 | 192.168.31.7 | mq_01 | 1 core 2g |
centos 6.9 | 192.168.31.216 | mq_02 | 1 core 2g |
centos 6.9 | 192.168.31.214 | mq_03 | 1 core 2g |
Note that the three servers here are all connected to the Internet. In addition, the RabbitMQ cluster nodes must be in the same network segment. If it is across the wide area network, the effect will be worse.
Change the computer names of the three MQ nodes to mq_01, mq_02 and mq_03, and then modify the hosts configuration file
vim /etc/hostname
The content is as follows:
mq_01
The other two have the same operation but different content.
vi /etc/hosts
The content is as follows:
192.168.31.7 mq_01
192.168.31.216 mq_02
192.168.31.214 mq_03
The other two have the same operation and the same content.
In order to make the hostname permanent, restart 3 servers.
reboot -f
3 Install both servers
yum install -y epel-release
3 Install both servers
wget https://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el6.x86_64.rpm
yum install -y socat
rpm -ivh erlang-19.0.4-1.el6.x86_64.rpm
3 Install both servers
wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.8/rabbitmq-server-3.6.8-1.el6.noarch.rpm
rpm -ivh rabbitmq-server-3.6.8-1.el6.noarch.rpm
3 Run it on both servers
mkdir -p /data/log/rabbitmq
mkdir -p /data/rabbitmq/mnesia
chown -R rabbitmq.rabbitmq -R /data/log/rabbitmq /data/rabbitmq/mnesia
3 Run it on both servers
vi /etc/rabbitmq/rabbitmq-env.conf
The content is as follows:
RABBITMQ_LOG_BASE=/data/log/rabbitmq
RABBITMQ_MNESIA_BASE=/data/rabbitmq/mnesia
3 Run it on both servers
/etc/init.d/rabbitmq-server start
The Rabbitmq cluster is dependent on the erlang cluster to work, so the erlang cluster must be built first. Each node in the Erlang cluster is implemented through a magic cookie, which is stored in /var/lib/rabbitmq/.erlang.cookie, and the file has a permission of 400. Therefore, it is necessary to ensure that the cookies of each node are consistent, otherwise the nodes cannot communicate.
Log in to the mq_01 node and view erlang.cookie
# cat /var/lib/rabbitmq/.erlang.cookie
RUIRJRRZDNYEHCCWITRS
Copy the value of the .erlang.cookie of the mq_01 node to the other two nodes by means of scp.
scp /var/lib/rabbitmq/.erlang.cookie [email protected]:/var/lib/rabbitmq/.erlang.cookie
scp /var/lib/rabbitmq/.erlang.cookie [email protected]:/var/lib/rabbitmq/.erlang.cookie
Set permissions, execute the other two
chown -R rabbitmq.rabbitmq /var/lib/rabbitmq/.erlang.cookie
chmod 400/var/lib/rabbitmq/.erlang.cookie
RabbitMQ provides a very friendly graphical monitoring page plug-in (rabbitmq_management), which allows us to see the status of Rabbit or cluster status at a glance.
3 Run it on both servers
rabbitmq-plugins enable rabbitmq_management
View port
netstat -napt|grep 5672
Add mq_02 and mq_03 as memory nodes to the mq01 node cluster
Execute the following commands on mq_02 and mq_03:
Stop the rabbit app
rabbitmqctl stop_app
Join to disk node
rabbitmqctl join_cluster --ram rabbit@mq_01
Start the rabbit app
rabbitmqctl start_app
(1) By default, rabbitmq is a disk node after startup. Under this cluster command, mq02 and mq03 are memory nodes, and mq01 is a disk node.
(2) If you want to make mq02 and mq03 both disk nodes, just remove the --ram parameter.
(3) If you want to change the node type, you can use the command rabbitmqctl change_cluster_node_type disc(ram), provided that the rabbit application must be stopped
3 Every node, execute it
rabbitmqctl cluster_status
3 Every node, execute it
rabbitmqctl add_user admin 'admin123'
rabbitmqctl set_permissions -p / admin ...
rabbitmqctl set_user_tags admin administrator
Explanation:
The first command line indicates that the user admin is created, and the password is admin123
The second line of the command indicates that the admin user has configuration, write, and read permissions for all resources of the virtual host as'/'. Note: The following 3 dots indicate these 3 permissions.
The third line of command indicates that the admin user is assigned administrator rights.
Open the browser and enter http://192.168.31.7:15672,
Username: admin, password: admin123
After login, the interface as shown in the figure appears.
Reference link for this article:
https://www.cnblogs.com/shihaiming/p/11014257.html
Recommended Posts