簡介
本文檔介紹如何在群集斷開時將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,[]}]