生产环境中至少运行3个rabbitmq服务器,测试环境中我们可以只运行两个,我们配置了两个节点,分别为controller1和controller2。
# systemctl start rabbitmq
# scp root@NODE:/var/lib/rabbitmq/.erlang.cookie /var/lib/rabbitmq/.erlang.cookie
需要修改NODE为controller1或者对应
# chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie
# chmod 400 /var/lib/rabbitmq/.erlang.cookie
# systemctl enable rabbitmq-server
# systemctl start rabbitmq-server
# rabbitmqctl cluster_status
Cluster status of node rabbit@controller1...
[{nodes,[{disc,[rabbit@ controller1]}]},
{running_nodes,[rabbit@ controller1]},
{partitions,[]}]
...done.
# rabbitmqctl stop_app
Stopping node rabbit@controller2...
...done.
# rabbitmqctl join_cluster --ram rabbit@ controller1
# rabbitmqctl start_app
Starting node rabbit@ controller2...
...done.</pre>
# rabbitmqctl cluster_status
Cluster status of node rabbit@controller1...
[{nodes,[{disc,[rabbit@ controller1]},{ram,[rabbit@ controller2]}]}, \
{running_nodes,[rabbit@NODE,rabbit@ controller1]}]
# rabbitmqctl set_policy ha-all '^(?!amq\.).*' '{"ha-mode": "all"}
rabbit_hosts=controller1:5672,controller2:5672
rabbit_retry_interval=1
rabbit_retry_backoff=2
rabbit_max_retries=0
rabbit_durable_queues=true</pre>
rabbit_ha_queues=true
NOTE:如果想更改从没有使用HA queues的旧配置到HA queues,你需要重启服务
复制
# rabbitmqctl stop_app
# rabbitmqctl reset
# rabbitmqctl start_app