RabbitMQ 集群:无法将从节点加入主节点
RabbitMQ clustering: Can't join slave node to master
我有两个 RabbitMQ 节点在不同的服务器上使用 docker:
rabbitmq-1.myhost.com(大师)
rabbitmq-2.myhost.com(从)
我尝试将 slave 连接到 master,创建一个双节点集群:
root@rabbitmq-2:/# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@rabbitmq-2 ...
root@rabbitmq-2:/# rabbitmqctl join_cluster rabbit@rabbitmq-1.myhost.com
但我得到:
root@rabbitmq-2:/# rabbitmqctl join_cluster rabbitmq-1.myhost.com
Clustering node rabbit@rabbitmq-2 with rabbitmq-1.myhost.com
Error:
{:badarg, [{:rpc, :rpcify_exception, 2, [file: 'rpc.erl', line: 467]}, {:rpc, :call, 5, [file: 'rpc.erl', line: 410]}, {:lists, :foldl, 3, [file: 'lists.erl', line: 1263]}, {:rabbit_mnesia, :discover_cluster, 1, [file: 'src/rabbit_mnesia.erl', line: 804]}, {:rabbit_mnesia, :join_cluster, 2, [file: 'src/rabbit_mnesia.erl', line: 236]}]}
编辑:我在添加前一行之前复制了我的 /etc/hosts:
root@rabbitmq-2:/# cat /etc/hosts
127.0.0.1localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
XX.XX.XX.XX rabbitmq-1.myhost.com rabbitmq-1
YY.YY.YY.YY rabbitmq-2.myhost.com rabbitmq-2
但是当我启动我的 docker 容器时我得到了这个:
Attaching to rabbitmq-2
rabbitmq-2 | 11:02:14.540 [error]
rabbitmq-2 |
rabbitmq-2 | BOOT FAILED
rabbitmq-2 | ===========
rabbitmq-2 | 11:02:14.542 [error] BOOT FAILED
rabbitmq-2 | 11:02:14.543 [error] ===========
rabbitmq-2 | 11:02:14.543 [error] ERROR: epmd error for host rabbitmq-2: address (cannot connect to host/port)
rabbitmq-2 | ERROR: epmd error for host rabbitmq-2: address (cannot connect to host/port)
我终于明白了,将两个带有别名(rabbitmq-1 和 rabbitmq-2)的 IP 添加到 /etc/hosts,并在从属节点 (rabbitmqctl-2) 中使用这些命令:
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@rabbitmq-1
rabbitmqctl start_app
rabbitmqctl cluster_status
我有两个 RabbitMQ 节点在不同的服务器上使用 docker:
rabbitmq-1.myhost.com(大师) rabbitmq-2.myhost.com(从)
我尝试将 slave 连接到 master,创建一个双节点集群:
root@rabbitmq-2:/# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@rabbitmq-2 ...
root@rabbitmq-2:/# rabbitmqctl join_cluster rabbit@rabbitmq-1.myhost.com
但我得到:
root@rabbitmq-2:/# rabbitmqctl join_cluster rabbitmq-1.myhost.com
Clustering node rabbit@rabbitmq-2 with rabbitmq-1.myhost.com
Error:
{:badarg, [{:rpc, :rpcify_exception, 2, [file: 'rpc.erl', line: 467]}, {:rpc, :call, 5, [file: 'rpc.erl', line: 410]}, {:lists, :foldl, 3, [file: 'lists.erl', line: 1263]}, {:rabbit_mnesia, :discover_cluster, 1, [file: 'src/rabbit_mnesia.erl', line: 804]}, {:rabbit_mnesia, :join_cluster, 2, [file: 'src/rabbit_mnesia.erl', line: 236]}]}
编辑:我在添加前一行之前复制了我的 /etc/hosts:
root@rabbitmq-2:/# cat /etc/hosts
127.0.0.1localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
XX.XX.XX.XX rabbitmq-1.myhost.com rabbitmq-1
YY.YY.YY.YY rabbitmq-2.myhost.com rabbitmq-2
但是当我启动我的 docker 容器时我得到了这个:
Attaching to rabbitmq-2
rabbitmq-2 | 11:02:14.540 [error]
rabbitmq-2 |
rabbitmq-2 | BOOT FAILED
rabbitmq-2 | ===========
rabbitmq-2 | 11:02:14.542 [error] BOOT FAILED
rabbitmq-2 | 11:02:14.543 [error] ===========
rabbitmq-2 | 11:02:14.543 [error] ERROR: epmd error for host rabbitmq-2: address (cannot connect to host/port)
rabbitmq-2 | ERROR: epmd error for host rabbitmq-2: address (cannot connect to host/port)
我终于明白了,将两个带有别名(rabbitmq-1 和 rabbitmq-2)的 IP 添加到 /etc/hosts,并在从属节点 (rabbitmqctl-2) 中使用这些命令:
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@rabbitmq-1
rabbitmqctl start_app
rabbitmqctl cluster_status