1.修改3台的主机名称,也可以不改
vi /etc/hostname
2.配置各个节点的host文件,让各节点都能识别对方
vi /etc/hosts
192.168.3.132 host-rabbitmq
192.168.3.133 host-rabbitmq2
192.168.3.134 host-rabbitmq3
3.以确保各个节点的cookie文件使用的同一个值
在node1上执行远程命令
scp /var/lib/rabbitmq/.erlang.cookie root@host-rabbitmq2:/var/lib/rabbitmq/.erlang.cookie
scp /var/lib/rabbitmq/.erlang.cookie root@host-rabbitmq3:/var/lib/rabbitmq/.erlang.cookie
4.重启RabbitMQ服务,顺带启动Erlang虚拟机和RabbitMQ应用服务(在三个节点上执行)
rabbitmq-server -detached
5.在2节点上执行
rabbitmqctl stop_app #只关闭Rabbitmq服务
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@host-rabbitmq
rabbitmqctl start_app #只启动应用服务
6.在3节点执行
rabbitmqctl stop_app #只关闭Rabbitmq服务
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@host-rabbitmq2
rabbitmqctl start_app #只启动应用服务
7.集群状态
rabbitmqctl cluster_status
8.解除集群节点(node2和node3机器分别执行)
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
rabbitmqctl cluster_status
rabbitmqctl forget_cluster_node_rabbit@host-rabbitmq2(node1机器上执行)