RabbitMQ消息中间件集群搭建

环境准备:至少三台虚拟主机,操作系统为Centos6.x或者7.x x64位,CPU至少1核,内存2G,磁盘10G以上,配置好网络yum源,关闭iptables,关闭seliunx

1,   服务器hosts文件修改(vim /etc/hosts)

10.38.1.166      node1
10.38.1.177      node2
10.38.1.180      node3

2,设置Erlang Cookie

Erlang Cookie 文件:/root/.erlang.cookie (注意编译安装的是这个文件)

[root@node1 ~]# chmod 777 /root/.erlang.cookie

[root@node1 ~]# scp -r /root/.erlang.cookie root@node2:/root/.erlang.cookie

[root@node1 ~]# scp -r /root/.erlang.cookie root@node3:/root/.erlang.cookie

[root@node1 ~]# chmod 400 /root/.erlang.cookie

[root@node1 ~]# chown rabbitmq.rabbitmq /root/.erlang.cookie

 

3,把node2、node3分别加入到集群node1中,rabbitmqctl stop_app —仅关闭应用,节点不被关闭

(1)  node2

./rabbitmqctl stop_app
./rabbitmqctl join_cluster --ram rabbit@node1
./rabbitmqctl start_app

(2)  node3

./rabbitmqctl stop_app
./rabbitmqctl join_cluster --ram rabbit@node1
./rabbitmqctl start_app

6,查看集群情况

./rabbitmqctl cluster_status
[{nodes,[{disc,[rabbit@node1]},{ram,[rabbit@node3,rabbit@node2]}]},
 {running_nodes,[rabbit@node3,rabbit@node2,rabbit@node1]},
 {cluster_name,<<"rabbit@node1">>},
 {partitions,[]},
 {alarms,[{rabbit@node3,[]},{rabbit@node2,[]},{rabbit@node1,[]}]}]
7,然后分别进入各个节点,查看集群情况
http://10.38.1.166:15672/#/