root@ubuntu:/var/lib/rabbitmq# rabbitmqctl join_cluster --ram rabbit@node2
Clustering node rabbit@node1 with rabbit@node2
Error: unable to connect to node rabbit@node1: nodedownDIAGNOSTICS
===========attempted to contact: [rabbit@node1]
rabbit@node1:
* connected to epmd (port 4369) on node1
* epmd reports node 'rabbit' running on port 25672
* TCP connection succeeded but Erlang distribution failed* Hostname mismatch: node "rabbit@ubuntu" believes its host is different. Please ensure that hostnames resolve the same way locally and on "rabbit@ubuntu"
current node details:
- node name: 'rabbitmq-cli-60@node1'
- home dir: /var/lib/rabbitmq
- cookie hash: BjCqdGwVCybIalCt35tRZg==
不知道跟我使用克隆的虚拟机有没有关系,两个虚拟机的hostname一样的。尝试各种方案后最简单的解决方法如下:首先设置主机名,这将修改/etc/hostname的内容
root@ubuntu:/var/lib/rabbitmq# hostnamectl set-hostname node1
此时如果执行
root@ubuntu:/var/lib/rabbitmq# service rabbitmq-server start
root@ubuntu:/var/lib/rabbitmq# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@node1
此时已经从原来的rabbit@ubuntu变为rabbit@node1。
在/etc/hosts添加ip和对应主机名
192.168.1.2 node0
192.168.1.3 node1
192.168.1.4 node2
之后执行
root@ubuntu:/var/lib/rabbitmq# rabbitmqctl join_cluster rabbit@node2
Clustering node rabbit@node1 with rabbit@node2
添加成功!注意,如果join_cluster 后面添加 --ram 则表示当前节点作为RAM节点加入到该集群中。如果不设置hosts的话会出现错误
unable to connect to epmd (port 4369) on node2: nxdomain (non-existing domain)
这可能是因为加入集群的命令用的是主机名“ rabbit@node2”
最后记得重新start_app
rabbitmqctl start_app