默认openstack使用rabbitmq做信息队列,如果想是云高可用,那么需要对每个涉及的组件都进行高可用配置,本文主要介绍如何使用rabbitmq做高可用。
高可用的方法为:
通过 Erlang 的分布式特性(通过 magic cookie 认证节点)进行 RabbitMQ 集群,各 RabbitMQ 服务为对等节点,即每个节点都提供服务给客户端连接,进行消息发送与接收。 这些节点通过 RabbitMQ HA 队列(镜像队列)进行消息队列结构复制。本方案中搭建 3 个节点,并且都是磁盘节点(所有节点状态保持一致,节点完全对等),只要有任何一个节点能够工作,RabbitMQ 集群对外就能提供服务。
环境为:
系统centos 7.1
rabbitmq版本是3.6.2
主机信息
node1 10.10.33.163 node2 10.10.33.166 node3 10.10.33.167
/etc/hosts配置为
10.10.33.163 ip-10-10-33-163 10.10.33.166 ip-10-10-33-166 10.10.33.167 ip-10-10-33-167
下面是开始安装
一、安装
安装第三方库与rabbitmq
yum install -y epel-release yum install rabbitmq-server
启动服务
systemctl enable rabbitmq-server.service systemctl start rabbitmq-server.service
二、配置
在node1里配置
将node1的/var/lib/rabbitmq/.erlang.cookie复制到node2与node3
修改权限(所有节点)
chmod 400 /var/lib/rabbitmq/.erlang.cookie chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie
在node2里配置
[[email protected] my.cnf.d]# rabbitmqctl stop_app Stopping node ‘[email protected]‘ ... [[email protected] my.cnf.d]# rabbitmqctl join_cluster [email protected] Clustering node ‘[email protected]‘ with ‘[email protected]‘ ... You have new mail in /var/spool/mail/root [[email protected] my.cnf.d]# rabbitmqctl start_app Starting node ‘[email protected]‘ ...
在node3里配置
[[email protected] my.cnf.d]# rabbitmqctl stop_app Stopping node ‘[email protected]‘ ... [[email protected] my.cnf.d]# rabbitmqctl join_cluster [email protected] Clustering node ‘[email protected]‘ with ‘[email protected]‘ ... [[email protected] my.cnf.d]# rabbitmqctl start_app Starting node ‘[email protected]‘ ...
查看集群状态
[[email protected] my.cnf.d]# rabbitmqctl cluster_status Cluster status of node ‘[email protected]‘ ... [{nodes,[{disc,[‘[email protected]‘,‘[email protected]‘, ‘[email protected]‘]}]}, {running_nodes,[‘[email protected]‘,‘[email protected]‘, ‘[email protected]‘]}, {cluster_name,<<"[email protected]">>}, {partitions,[]}, {alarms,[{‘[email protected]‘,[]}, {‘[email protected]‘,[]}, {‘[email protected]‘,[]}]}]
三、集群高可用配置
设计镜像队列策略
在任何一个节点执行
[[email protected] ~]# rabbitmqctl set_policy ha-all ‘^(?!amq\.).*‘ ‘{"ha-mode": "all"}‘ Setting policy "ha-all" for pattern "^(?!amq\\.).*" to "{\"ha-mode\": \"all\"}" with priority "0" ...
时间: 2024-10-07 04:52:13