简介
本文档介绍如何在群集中断时手动将RabbitMQ添加到群集。
先决条件
要求
本文档没有任何特定的要求。
使用的组件
本文档中的信息基于以下软件和硬件版本:
问题
本文将指导您如何验证RabbitMQ集群并手动将这些实例添加到集群。CloudCenter提供了为RabbitMQ配置高可用性(HA)的向导,但是,在很多情况下,它表示HA在退出向导后已成功配置,但RabbitMQ群集未正确形成。
验证RabbitMQ是否不在集群中
步骤1.使用CLI控制台登录到所有RabbitMQ服务器。
步骤2.检验RabbitMQ服务器是否在所有实例上运行。
#ps -ef | grep rabbit
Output:
rabbitmq 1677 1 0 14:47 ? 00:00:00 /usr/lib/erlang/erts-6.4/bin/epmd -daemon
root 1973 1 0 14:47 ? 00:00:00 /bin/sh /etc/rc.d/init.d/rabbitmq-server start
root 2000 1973 0 14:47 ? 00:00:00 /bin/bash -c ulimit -S -c 0 >/dev/null 2>&1 ; /usr/sbin/rabbitmq-server
root 2003 2000 0 14:47 ? 00:00:00 su rabbitmq -s /bin/sh -c /usr/lib/rabbitmq/bin/rabbitmq-server
rabbitmq 2026 2003 0 14:47 ? 00:00:05 /usr/lib/erlang/erts-6.4/bin/beam -W w -K true -A30 -P 1048576 -- -root /usr/lib/erlang -progname erl -- -home /var/lib/rabbitmq -- -pa /usr/lib/rabbitmq/lib/rabbitmq_server-3.5.1/sbin/../ebin -noshell -noinput -s rabbit boot -sname rabbit@ip-172-31-32-101 -boot start_sasl -config /etc/rabbitmq/rabbitmq -kernel inet_default_connect_options [{nodelay,true}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,"/var/log/rabbitmq/rabbit@ip-172-31-32-101.log"} -rabbit sasl_error_logger {file,"/var/log/rabbitmq/rabbit@ip-172-31-32-101-sasl.log"} -rabbit enabled_plugins_file "/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/lib/rabbitmq/lib/rabbitmq_server-3.5.1/sbin/../plugins" -rabbit plugins_expand_dir "/var/lib/rabbitmq/mnesia/rabbit@ip-172-31-32-101-plugins-expand" -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/var/lib/rabbitmq/mnesia/rabbit@ip-172-31-32-101" -kernel inet_dist_listen_min 25672 -kernel inet_dist_listen_max 25672
rabbitmq 2242 2026 0 14:47 ? 00:00:00 inet_gethost 4
rabbitmq 2243 2242 0 14:47 ? 00:00:00 inet_gethost 4
root 2602 2588 0 15:04 pts/0 00:00:00 grep --color=auto rabbit
OR
#/sbin/service rabbitmq-server status
Status of node 'rabbit@ip-172-31-32-101' ...
[{pid,2026},
{running_applications,
[{rabbitmq_management,"RabbitMQ Management Console","3.5.1"},
{rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.5.1"},
{webmachine,"webmachine","1.10.3-rmq3.5.1-gite9359c7"},
{mochiweb,"MochiMedia Web Server","2.7.0-rmq3.5.1-git680dba8"},
{rabbitmq_management_agent,"RabbitMQ Management Agent","3.5.1"},
{rabbit,"RabbitMQ","3.5.1"},
----- Text omitted for brevity
步骤3.使用以下命令检验所有实例的集群状态:
[root@ip-172-31-32-101 ~]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@ip-172-31-32-101' ...
[{nodes,[{disc,['rabbit@ip-172-31-32-101']}]},
{running_nodes,['rabbit@ip-172-31-32-101']},
{cluster_name,<<"rabbit@ip-172-31-32-101.us-east-2.compute.internal">>},
{partitions,[]}]
在此输出中,您可以确定集群中只运行一个节点。
解决方案
在此场景中,您将rabbit@ip-172-31-32-101添加到您的群集rabbit@ip-172-31-45-110.us-east-2.compute.internal
步骤1.要连接第二个RabbitMQ服务器,需要确保应用程序停止并加入集群。
步骤2.切换到RabbitMQ2服务器并停止应用。
[root@ip-172-31-32-101 ~]# rabbitmqctl stop_app
Stopping node 'rabbit@ip-172-31-32-101' ...
[root@ip-172-31-32-101 ~]#
步骤3.将RabbitMQ2服务器加入RabbitMQ1集群。
[root@ip-172-31-32-101 ~]# rabbitmqctl join_cluster rabbit@ip-172-31-45-110
Clustering node 'rabbit@ip-172-31-32-101' with 'rabbit@ip-172-31-45-110' ...
步骤4.启动rabbitmq2应用程序。
[root@ip-172-31-32-101 ~]# rabbitmqctl start_app
Starting node 'rabbit@ip-172-31-32-101' ...
在任一节点上运行cluster_status命令时,可以看到这两个节点已加入集群中。
Server1 : Output
[root@ip-172-31-45-110 ~]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@ip-172-31-45-110' ...
[{nodes,[{disc,['rabbit@ip-172-31-32-101','rabbit@ip-172-31-45-110']}]},
{running_nodes,['rabbit@ip-172-31-32-101','rabbit@ip-172-31-45-110']},
{cluster_name,<<"rabbit@ip-172-31-45-110.us-east-2.compute.internal">>},
{partitions,[]}]
Server2 : Output
[root@ip-172-31-32-101 ~]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@ip-172-31-32-101' ...
[{nodes,[{disc,['rabbit@ip-172-31-32-101','rabbit@ip-172-31-45-110']}]},
{running_nodes,['rabbit@ip-172-31-45-110','rabbit@ip-172-31-32-101']},
{cluster_name,<<"rabbit@ip-172-31-45-110.us-east-2.compute.internal">>},
{partitions,[]}]