In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to configure a highly available RabbitMQ cluster. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
At present, RabbitMQ is a very popular message middleware, which is widely used by both Internet companies and small and medium-sized enterprises. As a qualified developer, it is necessary to know something about RabbitMQ.
Overview
There are about three modes of operation:
Single mode: non-cluster mode, single mode.
Normal mode: RabbitMQ default cluster mode.
For Queue, the message entity exists on only one of the nodes, and the An and B nodes only have the same metadata, that is, the queue structure. When the message enters the Queue of node An and the consumer is pulled from node B, RabbitMQ will temporarily transmit the message between An and B, take out the message entity in An and send it to consumer through B.
So consumer should try to connect to each node and get messages from it. That is, for the same logical queue, a physical Queue is established on multiple nodes. Otherwise, no matter whether the consumer is connected to An or B, the export is always in A, which will create a bottleneck.
A problem with this mode is that when the A node fails, the B node cannot get the unconsumed message entities in the A node.
If you persist the message, you have to wait for node A to recover before it can be consumed; if there is no persistence, the message will be lost.
Mirror mode: there are multiple nodes in Queue at the same time. The above problem can be solved by changing the mode to achieve high availability of HA. The essence of this mode is that the message entity will actively synchronize between the mirror nodes instead of pulling data temporarily when the server fetches the data.
The side effects of this mode are also obvious. in addition to reducing system performance, if there are too many mirror queues and a large number of messages enter, the network bandwidth within the cluster will be greatly consumed by this synchronous communication.
Let's get familiar with these three operating modes by configuring RabbitMQ mirroring mode
1. Environment description
The RabbitMQ cluster is installed on three nodes: 10.0.0.1, 10.0.0.2, 10.0.0.3
HAProxy is installed on 10.0.0.4 and is used to provide RabbitMQ balance.
The three nodes add the following to the / etc/hosts file:
10.0.0.1 rabbit110.0.0.2 rabbit210.0.0.3 rabbit32. Install erlang, Rabbitmqcd oneinstack/srcwget http://erlang.org/download/otp_src_18.3.tar.gztar xzf otp_src_18.3.tar.gzcd otp_src_18.3./configure-prefix=/usr/local/erlang-- enable-shared-zlib-- with-ssl-- enable-threads-- enable-smp-support-- enable-kernel-poll-- enable-hipe-- without-javacmake & & make installcd.. wget http://www.rabbitmq.com/releases/rabbitmq-server/ V3.5.7/rabbitmq-server-generic-unix-3.5.7.tar.gztar xzf rabbitmq-server-generic-unix-3.5.4.tar.gzmv rabbitmq_server-3.5.4 rabbitmqsed-I's @ ^ ERL _ DIR=.*@ERL_DIR=/usr/local/erlang/bin/@' / usr/local/rabbitmq/sbin/rabbitmq-defaultssed-I's @ ^ log _ BASE=.*@LOG_BASE=/usr/local/rabbitmq/var/log/rabbitmq@' / usr / local/rabbitmq/sbin/rabbitmq-defaults # log directory mkdir-p / usr/local/rabbitmq/var/ {lib Log} / rabbitmq3. The general user (rabbitmq) runs RabbitMQuseradd rabbitmqwget http://pkgs.fedoraproject.org/cgit/rpms/rabbitmq-server.git/plain/rabbitmq-script-wrappersed-I 's@cd / var/lib/rabbitmq@cd / usr/local/rabbitmq/var/lib/rabbitmq@g' rabbitmq-script-wrapper # to change the rabbitmq data storage directory sed-I' s data storage directory -wrappercp rabbitmq-script-wrapper / usr/sbin/rabbitmqctlcp rabbitmq-script-wrapper / usr/sbin/rabbitmq-servercp rabbitmq-script-wrapper / usr/sbin/rabbitmq-pluginschown-R rabbitmq.rabbitmq / usr/local/rabbitmq/var4. Log splicing cat > > / etc/logrotate.d/rabbitmq-server local/rabbitmq/var/log/rabbitmq/*.log {weekly missingok rotate 20 compress delaycompress notifempty sharedscripts postrotate / sbin/service rabbitmq-server rotate-logs > / dev/null endscript} EOF5. Startup script
Reference: "RabbitMQ startup script"
6. Set up Erlang Cookie
Erlang Cookie file: / home/rabbitmq/.erlang.cookie. Here, copy the file of rabbit1 to rabbit2 and rabbit3, and set 400permissions
Chmod 400 / home/rabbitmq/.erlang.cookiechown rabbitmq.rabbitmq / home/rabbitmq/.erlang.cookie7. Modify the configuration file
Password and cluster configuration:
Cat > / usr/local/rabbitmq/etc/rabbitmq/rabbitmq.config 'rabbit@rabbit1','rabbit@rabbit2',' rabbit@rabbit3'], disc}}, {tcp_listeners, [{"0.0.0", 5672}]}, {default_vhost, "/" > >}, {default_user, "linuxeye" > >}, {default_pass, "linuxeye@123" > >}, {loopback_users, ["linuxeye"]} {default_permissions, [. * "> >,". * "> >,". * ">]}] .EOF
Enable rabbitmq_management
Cat > / usr/local/rabbitmq/etc/rabbitmq/enabled_plugins8. Start the 3-node rabbitmq respectively
Use the rabbitmqctl cluster_status command to indicate that the cluster has been built successfully
[root@rabbit2 ~] # rabbitmqctl cluster_statusCluster status of node rabbit@rabbit2... [{nodes, [{disc, [rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]}, {running_nodes, [rabbit@rabbit3,rabbit@rabbit1,rabbit@rabbit2]}, {cluster_name, "rabbit@rabbit2" > >}, {partitions, []}] 9. Set mirror queue policy
Execute on any node:
Rabbitmqctl set_policy ha-all "^"'{"ha-mode": "all"}'10. Configure HAProxy
After the HAProxy is configured, the browser accesses http://10.0.0.4:15672, and the following proves that the rabbitmq image mode is built successfully
Thank you for reading! This is the end of the article on "how to configure highly available RabbitMQ clusters". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.