一. 环境准备
环境如下
主机名 | ip |
---|---|
rabbitmq01 | 10.9.132.128 |
rabbitmq02 | 10.9.67.10 |
单节点部署可以参考上一篇文章
二. 部署集群
2.1 修改host
10.9.132.128 rabbitmq01
10.9.67.10 rabbitmq02
2.2 修改erlang.cookie文件中cookie值一致
cat /var/lib/rabbitmq/.erlang.cookie
YIHXTAVFVTEWSDSXWVLY
chmod 600 /var/lib/rabbitmq/.erlang.cookie
#查看集群状态
rabbitmqctl cluster_status
Cluster status of node rabbit@rabbitmq01
[{nodes,[{disc,[rabbit@rabbitmq01]}]},
{running_nodes,[rabbit@rabbitmq01]},
{cluster_name,<<"rabbit@rabbitmq01">>},
{partitions,[]},
{alarms,[{rabbit@rabbitmq01,[]}]}]
#停止服务
rabbitmqctl stop_app
#加入集群
rabbitmqctl join_cluster --ram rabbit@rabbitmq02
#启动服务
rabbitmqctl start_app
#再次查看集群
rabbitmqctl cluster_status
Cluster status of node rabbit@rabbitmq01
[{nodes,[{disc,[rabbit@rabbitmq02]},{ram,[rabbit@rabbitmq01]}]},
{running_nodes,[rabbit@rabbitmq02,rabbit@rabbitmq01]},
{cluster_name,<<"rabbit@rabbitmq01">>},
{partitions,[]},
{alarms,[{rabbit@rabbitmq02,[]},{rabbit@rabbitmq01,[]}]}]
2.3 开启HA 镜像队列
rabbitmqctl set_policy -p / ha "^" '{"ha-mode":"all"}'
Setting policy "ha" for pattern "^" to "{\"ha-mode\":\"all\"}" with priority "0"
rabbitmqctl list_policies -p /
Listing policies
/ ha all ^ {"ha-mode":"all"} 0