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 > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Overview of RabbitMQ Cluster
Through the distributed characteristics of Erlang (through the magic cookie authentication node) for RabbitMQ cluster, each RabbitMQ service is a peer node, that is, each node provides services to the client connection to send and receive messages.
These nodes replicate the message queue structure through RabbitMQ HA queues (mirror queues). In this scheme, three nodes are built, and all of them are disk nodes (all nodes are in the same state, and the nodes are completely equivalent). As long as any node can work, the RabbitMQ cluster can provide services.
Install Erlang, RabbitMQ
Http://yanconggod.blog.51cto.com/1351649/1933009
Modify / etc/hosts
The corresponding relationship of the three nodes that join the cluster:
10.0.0.231 node1
10.0.0.232 node2
10.0.0.233 node3
Set up Erlang Cookie
RabbitMQ nodes and command-line tools e.g. Rabbitmqctl are interconnected using Cookie, and Cookie is a random set of numeric + letter strings. When the RabbitMQ server starts, Erlang VM automatically creates a Cookie file with random content. If you are installing RabbitMQ from the yum source, the Erlang Cookie file is in / var/lib/rabbitmq/.erlang.cookie. If the RabbitMQ,Erlang Cookie file $HOME/.erlang.cookie is installed through the source code.
The example demonstrated in this article is installed with source code. Since the permission of this file is 400, you need to modify the permission of the file in node2 and node3 to 777:
Node1:yancongadmin@node1:~$ chmod 777 .erlang.cookienode2: yancongadmin@node2:~$ chmod 777 .erlang.cookieyancongadmin @ node2:~$ scp-r node1:/home/yancongadmin/.erlang.cookie ~ / yancongadmin@node1's password:.erlang.cookie 100% 20 0.0KB/s 00V 00node3v chmod 777 .erlang.cookieyancongadmin @ node3:~$ scp-r node1:/home/yancongadmin/.erlang.cookie ~ / yancongadmin@node1's password:.erlang.cookie 100% 20 0.0KB/s 00:00
Restore the permissions in node1, node2 and node3 respectively:
Yancongadmin@node1:~$ chmod 400 .erlang.cookie
Finally, confirm that the values of .erlang.cookie on the three machines are the same.
Yancongadmin@node1:~$ cat .erlang.cookieVORMVSAAOFEQKTNWByancongadmin @ node2:~$ cat .erlang.cookieVORMVSAAOFEQKTNWBByancongadmin @ node3:~$ cat .erlang.cookieVORMVSAAOFEQKTNWBB
Start Rabbit Node in the background using the detached parameter
Yancongadmin@node1:~$ rabbitmqctl stopStopping and halting node rabbit@node1... Gracefully halting Erlang VMyancongadmin@node1:~$ rabbitmq-server-detached
Through the rabbitmqctl cluster_status command, you can view the status of each node, whose name is rabbit@shorthostname
Node1:yancongadmin@node1:~$ rabbitmqctl cluster_statusCluster status of node rabbit@node1... [{nodes, [{disc, [rabbit@node1]}]}, {running_nodes, [rabbit@node1]}, {cluster_name,}, {partitions, []}, {alarms, [{rabbit@node1, []}]}] node2:yancongadmin@node2:~$ rabbitmqctl cluster_statusCluster status of node rabbit@node2... [{nodes, [{disc, [rabbit@node2]}]}, {running_nodes, [rabbit@node2]} {cluster_name,}, {partitions, []}, {alarms, [{rabbit@node2, []}]}] node3:yancongadmin@node3:~$ rabbitmqctl cluster_statusCluster status of node rabbit@node3... [{nodes, [{disc, [rabbit@node3]}]}, {running_nodes, [rabbit@node3]}, {cluster_name,}, {partitions, []}, {alarms, [{rabbit@node3, []}]}]
Cluster node1, node2 and node3
Because when rabbitmq-server starts, it starts the node and the application together, it presets the RabbitMQ application to standalone mode. To add a node to an existing cluster, you need to stop the application and set the node to its original state, and then you are ready to join the cluster. If you use. / rabbitmqctl stop, both the application and the node will be shut down. So using rabbitmqctl stop_app only closes the application.
Node2:yancongadmin@node2:~$ rabbitmqctl stop_appStopping node rabbit@node2... yancongadmin@node2:~$ rabbitmqctl join_cluster rabbit@node1Clustering node rabbit@node2 with rabbit@node1... yancongadmin@node2:~$ rabbitmqctl start_appStarting node rabbit@node2... node3:yancongadmin@node3:~$ rabbitmqctl stop_appStopping node rabbit@node3... yancongadmin@node3:~$ rabbitmqctl join_cluster rabbit@node1Clustering node rabbit@node3 with rabbit@node1... yancongadmin@node3:~$ rabbitmqctl start_appStarting node rabbit@node3...
At this point, node2 and node3 will also automatically establish a connection.
If you want to use memory nodes, you can use the following command:
Yancongadmin@node2:~$ rabbitmqctl join_cluster-ram rabbit@node1
After the cluster is configured, you can execute rabbitmqctl cluster_status on any node of the RabbitMQ to see if the cluster configuration is successful.
Node1:yancongadmin@node1:~$ rabbitmqctl cluster_statusCluster status of node rabbit@node1... [{nodes, [{disc, [rabbit@node1,rabbit@node2,rabbit@node3]}]}, {running_nodes, [rabbit@node1]}, {cluster_name,}, {partitions, []}, {alarms, [{rabbit@node1, []}]}] node2:yancongadmin@node2:~$ rabbitmqctl cluster_statusCluster status of node rabbit@node2... [{nodes, [{disc, [rabbit@node1,rabbit@node2]}]} {alarms, [{rabbit@node1, []}]}] node3:yancongadmin@node3:~$ rabbitmqctl cluster_statusCluster status of node rabbit@node3... [{nodes, [{disc, [rabbit@node1,rabbit@node2,rabbit@node3]}]}, {alarms, [{rabbit@node1, []}]}]
RabbitMQ Mirror function
The Rabbit mirroring function needs to be implemented based on RabbitMQ policy, which is used to control and modify a cluster-wide vhost queue behavior and Exchange behavior.
Yancongadmin@node2:~$ rabbitmqctl set_policy-p hrsystem ha-allqueue "^"'{"ha-mode": "all"}'
This command creates a policy with a vhost name of hrsystem, a policy name of ha-allqueue, a policy pattern of all to copy to all nodes, including new nodes, and a policy regular expression of "^" to indicate all matching queue names.
For example, the following command, ^ message this rule should be modified according to its own, this refers to synchronization "message" at the beginning of the queue name, we configure the use of all queues, so the expression is "^".
Yancongadmin@node2:~$ rabbitmqctl set_policy-p hrsystem ha-allqueue "^ message"'{"ha-mode": "all"}'
Execute on any node:
Yancongadmin@node2:# rabbitmqctl set_policy ha-all "^" {"ha-mode": "all"} 'Setting policy "ha-all" for pattern "^" to "{\" ha-mode\ ":\" all\ "}" with priority "0"
All queues are set as mirror queues, that is, the queues are copied to each node, and the state of each node is maintained all the time.
The examples I have used are for reference only:
Rabbitmqctl set_policy ha-xxx "^ cn\ .xxx"\ {"ha-mode": "exactly", "ha-params": 2, "ha-sync-mode": "automatic", "ha-promote-on-shutdown": "always", "ha-sync-batch-size": 20} 'rabbitmqctl set_policy queue-xxx "^ queue"\' {"ha-mode": "exactly", "ha-params": 2, "ha-sync-mode": "automatic" "ha-promote-on-shutdown": "always", "ha-sync-batch-size": 20}'
If you need a load balancer, you need to install and configure HAProxy
For example:
Listen rabbitmq_cluster 0.0.0.0:5672 mode tcpbalance roundrobin server node1 10.0.0.231:5672 check inter 2000 rise 2 fall 3server node2 10.0.0.232:5672 check inter 2000 rise 2 fall 3server node3 10.0.0.233:5672 check inter 2000 rise 2 fall 3
Reference: http://idoall.org/blog/post/lion/15
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.