其他安装过程中出现的常见问题参见“RabbitMQ安装遇到的问题(转载)”,这里不重复说了。
重点说一个集群配置中的一个问题:
2台机器:
192.168.31.129 centosmq1 centos 6
192.168.31.21 centosmq2 centos 6
其中centosmq1、centosmq2 是对应的hostname
hostname可通过如下命令修改:
[root@MiWiFi-R3-srv ~]# vi /etc/sysconfig/network
HOSTNAME=centosmq1
修改后需重启机器生效
最后,在将centosmq2节点加入centosmq1节点进行集群时,报错:
[root@centosmq1 bin]# rabbitmqctl join_cluster rabbit@centosmq2
Clustering node rabbit@centosmq1 with rabbit@centosmq2
Error: unable to connect to nodes [rabbit@centosmq2]: nodedown
DIAGNOSTICS
===========
attempted to contact: [rabbit@centosmq2]
rabbit@centosmq2:
* unable to connect to epmd (port 4369) on centosmq2: address (cannot connect to host/port)
current node details:
- node name: 'rabbitmq-cli-61@centosmq1'
- home dir: /var/lib/rabbitmq
- cookie hash: e1Xkq95Z99vmhL8lgMvW0w==
[root@centosmq1 bin]#
翻遍了网上的资料都没有找到明确的解决方法,很多都是类似/etc/hosts中没有设置对hostname,或者.erlang.cookie 没有设置权限。
最后 抱着试一试的心态检查4369端口,在centosmq1机使用telnet命令:
[root@centosmq1 bin]# telnet centosmq2 4369
Trying 192.168.31.21...
telnet: connect to address 192.168.31.21: No route to host
说明centosmq2机没有开放4369端口
在centosmq2机使用如下命令开放4369端口:
[root@centosmq2 bin]# /sbin/iptables -I INPUT -p tcp --dport 4369 -j ACCEPT
[root@centosmq2 bin]# /etc/rc.d/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@centosmq2 bin]# /etc/init.d/iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
然后在centosmq1机重新执行加入集群节点命令,依然报错:
[root@centosmq1 bin]# rabbitmqctl join_cluster --ram rabbit@centosmq2
Clustering node rabbit@centosmq1 with rabbit@centosmq2
Error: unable to connect to nodes [rabbit@centosmq2]: nodedown
DIAGNOSTICS
===========
attempted to contact: [rabbit@centosmq2]
rabbit@centosmq2:
* connected to epmd (port 4369) on centosmq2
* epmd reports node 'rabbit' running on port 25672
* can't establish TCP connection, reason: ehostunreach (host is unreachable)
* suggestion: blocked by firewall?
current node details:
- node name: 'rabbitmq-cli-32@centosmq1'
- home dir: /var/lib/rabbitmq
- cookie hash: e1Xkq95Z99vmhL8lgMvW0w==
[root@centosmq1 bin]# telnet 192.168.31.21 25672
Trying 192.168.31.21...
telnet: connect to address 192.168.31.21: No route to host
再用同样的方式在centosmq2机开放25672端口,然后就可以了:
[root@centosmq1 bin]# rabbitmqctl join_cluster --ram rabbit@centosmq2
Clustering node rabbit@centosmq1 with rabbit@centosmq2
查看集群状态:
[root@centosmq1 bin]# rabbitmqctl cluster_status
Cluster status of node rabbit@centosmq1
[{nodes,[{disc,[rabbit@centosmq2]},{ram,[rabbit@centosmq1]}]},
{alarms,[{rabbit@centosmq2,[]}]}]
可以看到已经有rabbit@centosmq2、rabbit@centosmq1 2个节点了。
启动centosmq1上的rabbitmq服务:
[root@centosmq1 bin]# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@centosmq1
[root@centosmq1 bin]# rabbitmqctl start_app
Starting node rabbit@centosmq1
[root@centosmq1 bin]#
通过localhost:15672/管理页面就能看到有2个节点了。
没有telnet命令:
使用如下命令安装telnet
yum install xinetd
yum install telnet
yum install telnet-server
装好telnet服务之后,默认是不开启服务的,需要修改文件来开启服务
vi /etc/xinetd.d/telnet
修改 disable = yes 为 disable = no
启动 xinetd服务
service xinetd restart
或者
/etc/rc.d/init.d/xinetd restart