项目场景:
搭建rabbitmq集群时mq1为主,mq2,mq3为从 mq2和mq3加入集群时输入命令:rabbitmqctl join_cluster rabbit@mq1报错
问题描述:
具体报错为: Error: unable to perform an operation on node ‘rabbit@localhost’. Please see diagnostics information and suggestions below.
Most common reasons for this are:
- Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)
- CLI tool fails to authenticate with the server (e.g. due to CLI tool’s Erlang cookie not matching that of the server)
- Target node is not running
In addition to the diagnostics info below:
- See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more
- Consult server logs on node rabbit@localhost
- If target node is configured to use long node names, don’t forget to use --longnames with CLI tools
DIAGNOSTICS
attempted to contact: [rabbit@localhost]
rabbit@localhost:
- connected to epmd (port 4369) on localhost
- epmd reports: node ‘rabbit’ not running at all
no other nodes on localhost - suggestion: start the node
Current node details:
- node name: ‘rabbitmqcli-1268-rabbit@localhost’
- effective user’s home directory: /var/lib/rabbitmq
- Erlang cookie hash: Y808sbgvYL/c08FQp16K+w==
原因分析:
我找了一天都没有找到任何的解决办法,网上其他的都是在本地把mq跑起来的,而我是在虚拟机上跑起来的,这时候我观察到错误中写的是 Error: unable to perform an operation on node ‘rabbit@localhost’. Please see diagnostics information and suggestions below.
它上面写的是rabbit@localhost而不是rabbit@mq2或者rabbit@mq3
我就怀疑可能是hostname和hosts这一层关系没有对应上
结果我修改了hostname和rabbitmq-env.conf之后就可以加入集群了!
解决方案:
1.先把hostname和hosts文件的映射对应上
我们先查看hosts文件里面的内容(如果没有添加ip映射则需要自己手动添加) 我们这时就用mq3为例,修改mq3虚拟机上的hostname
hostnamectl set-hostname mq3
这时我们把mq跑起来
service rabbitmq-server start
再把mq关闭
rabbitmqctl stop_app
就会有提示
Stopping rabbit application on node rabbit@mq3
这时的提示已经显示rabbit@mq3说明修改成功
此时尝试一下加入集群,如果成功加入则不需要以下步骤
2. 修改rabbitmq变量(如果这时已经可以加入集群则不用此步骤)
vim /etc/rabbitmq/rabbitmq-env.conf
将NODENAME=rabbit@localhost改成 NODENAME=rabbit@mq3
此时我们在尝试加入把mq3加入mq1集群
rabbitmqctl join_cluster rabbit@mq1
这时就可以成功加入集群了 加入集群后启动rabbitmq
rabbitmqctl start_app
这时我们去页面查看一下
搭建rabbitmq集群成功!
|