rabbitmq High Availability

每个rabbitmq node运行RabbitMQ application共享用户virtual hosts, queues, exchanges, etc.

一个nodes组称之为一个集群。

所有的RabbitMQ broker上的操作所需要的data/state都是全节点复制,唯一的例外是message queues,,它只存放在创建它的node上,但对所有节点可见/可取。

为了复制message queues到所有节点需要打开mirrored queues。

下面创建一个RabbitMQ brokers集群,打开mirrored queues。
3个节点:
node1 10.15.85.141
node2 10.15.85.142
node3 10.15.85.143
注意:这并非完整的HA方案,仅仅是为了演示非单点故障。

1. 第一步:停掉node-01上的所有OpenStack services
2. 拷贝erlang cookie到其他2个节点:
% scp /var/lib/rabbitmq/.erlang.cookie [email protected]:/var/lib/rabbitmq/.erlang.cookie
% scp /var/lib/rabbitmq/.erlang.cookie [email protected]:/var/lib/rabbitmq/.erlang.cookie

确保权限为: user ‘rabbitmq‘, group ‘rabbitmq‘ 400
% chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie
% chmod 400 /var/lib/rabbitmq/.erlang.cookie

3. 启动node-02 和 node-03的RabbitMQ service
% chkconfig rabbitmq-server on
% service rabbitmq-server start

现在有个3个RabbitMQ brokers,下一步就是组建集群并开通 mirrored queues。

4. 让node 2/3加入到node1:
On node-02:
# rabbitmqctl stop_app
Stopping node ‘[email protected]‘ ...
...done.
 
# rabbitmqctl join_cluster [email protected]
Clustering node ‘[email protected]‘ with ‘[email protected]‘ ...
...done.
 
# rabbitmqctl start_app
Starting node ‘[email protected]‘ ...
...done.

On node-03:
# rabbitmqctl stop_app
Stopping node ‘[email protected]‘ ...
...done.
 
# rabbitmqctl join_cluster [email protected]
Clustering node ‘[email protected]‘ with ‘[email protected]‘ ...
...done.
 
# rabbitmqctl start_app
Starting node ‘[email protected]‘ ...
...done.

现在有了3个节点的RabbitMQ cluster. 查看集群状态:
# 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]‘]},
{partitions,[]}]
...done.

RabbitMQ clustering不能处理网络分割,也就是说不能跨WAN使用, shovel or federation plugins可以解决这个问题。

4.1 集群节点可以随时stop/start

node2$ rabbitmqctl stop

node2$ rabbitmq-server --detached

4.2 集群节点可以随时退出和加入

node2$ rabbitmqctl stop_app

node2$ rabbitmqctl reset

node2$ rabbitmqctl start_app

现在node2独立了。

也可以从node1上移除node2:

node2$ rabbitmqctl stop_app

node1$ rabbitmqctl forget_cluster_node [email protected]

注意:这时node2 依然认为它和node1是一个集群,直接重启它会出错,需要reset它:

node2$ rabbitmqctl reset

4.3 为了实验,一个机器上可以运行多个RabbitMQ nodes,前提是每个node的名字和ip/port不同。

详见:

http://www.rabbitmq.com/clustering.html

5. 创建policy来 Enable mirrored queues
% rabbitmqctl set_policy HA ‘^(?!amq\.).*‘ ‘{"ha-mode": "all"}‘

详细配置见:

http://www.rabbitmq.com/ha.html

6. 既然消息队列可以从3个任意的RabbitMQ brokers访问,在节点1上setup一个LB HAProxy:
Install haproxy on node-01.
% yum install haproxy
Edit /etc/haproxy/haproxy.cfg and create a simple TCP proxy for RabbitMQ.
global
    daemon
 
defaults
    mode tcp
    maxconn 10000
    timeout connect 5s
    timeout client 100s
    timeout server 100s
 
listen rabbitmq 10.15.85.141:5670
    mode tcp
    balance roundrobin
    server node-01 10.15.85.141:5672 check inter 5s rise 2 fall 3
    server node-02 10.15.85.142:5672 check inter 5s rise 2 fall 3
    server node-03 10.15.85.143:5672 check inter 5s rise 2 fall 3

haproxy位于10.15.85.141:5670
到这个proxy的连接会round-robin到3个节点上。

7.启动haproxy
% service haproxy start

8.让OpenStack service指向haproxy

Neutron:
openstack-config --set /etc/neutron/neutron.conf DEFAULT rabbit_host 10.15.85.141
openstack-config --set /etc/neutron/neutron.conf DEFAULT rabbit_port 5670
Nova:
openstack-config --set /etc/nova/nova.conf DEFAULT rabbit_host 10.15.85.141
openstack-config --set /etc/nova/nova.conf DEFAULT rabbit_port 5670
Glance:
openstack-config --set /etc/glance/glance-api.conf DEFAULT rabbit_host 10.15.85.141
openstack-config --set /etc/glance/glance-api.conf DEFAULT rabbit_port 5670
Cinder:
openstack-config --set /etc/cinder/cinder.conf DEFAULT rabbit_host 10.15.85.141
openstack-config --set /etc/cinder/cinder.conf DEFAULT rabbit_port 5670
Ceilometer:
openstack-config --set /etc/ceilometer/ceilometer.conf DEFAULT rabbit_host 10.15.85.141
openstack-config --set /etc/ceilometer/ceilometer.conf DEFAULT rabbit_port 5670

9 最后把这个集群写入到配置文件/etc/rabbitmq/rabbitmq.config,这样node启动时会自动创建该集群
[{rabbit,
  [{cluster_nodes, {[‘[email protected]‘, ‘[email protected]‘, ‘[email protected]‘], ram}}]}].

注意:有很多旧文档依然推荐用pacemake和DRBD作为rabbitmq的HA方案,有了queue mirror技术,这个已经过时了。

详见:

http://www.rabbitmq.com/pacemaker.html

High availability with Pacemaker and DRBD

参考:
https://www.rdoproject.org/RabbitMQ
http://blog.flux7.com/blogs/tutorials/how-to-creating-highly-available-message-queues-using-rabbitmq

时间: 2024-11-08 10:32:16

rabbitmq High Availability的相关文章

RabbitMQ概念及环境搭建(四)RabbitMQ High Availability

#################################################### RabbitMQ High Availability #################################################### 1.高可用queue 默认情况下RabbitMQ cluster中的queues位于单独的节点(queues被首次声明的节点),而exchanges和bindings存在于cluster中各节点.因而每个节点失效exchanges和b

OpenStack Kolla 源码分析 --Ansible

OpenStack Kolla 源码分析 –Ansible Kolla介绍 Kolla项目利用Docker.Docker-Compose.Ansible来完成部署OpenStack,目前Kolla已经能够完成一个all-in-one的开发环境的部署.从Kolla项目spec中的描述来看,主要是利用Docker容器的隔离性来达到OpenStack的原子升级.回退在升级.整个升级.回退的过程更容易控制影响范围,降低整个OpenStack的运维复杂度.Kolla 提供了生产级别的 OpenStack

RabbitMQ简介与使用

RabbitMQ简介与使用 2013年3月23日  小白  学习笔记 1. AMQP简介 在了解RabbitMQ之前,首先要了解AMQP协议.AMQP,即Advanced Message Queuing Protocol,高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设计. 当前各种应用大量使用异步消息模型,并随之产生众多消息中间件产品及协议,标准的不一致使应用与中间件之间的耦合限制产品的选择,并增加维护成本.AMQP是一个提供统一消息服务的应用层标准协议,基于此协议的客户端与

rabbitmq HA

Highly Available Queues By default, queues within a RabbitMQ cluster are located on a single node (the node on which they were first declared). This is in contrast to exchanges and bindings, which can always be considered to be on all nodes. Queues c

FW 构建OpenStack的高可用性(HA,High Availability)

原文地址:http://blog.csdn.net/hilyoo/article/details/7704280 1.CAP理论 1) CAP 理论给出了3个基本要素: 一致性 ( Consistency) :任何一个读操作总是能读取到之前完成的写操作结果: 可用性 ( Availability) :每一个操作总是能够在确定的时间内返回: 分区可容忍性 (Tolerance of network Partition) :在出现网络分区的情况下,仍然能够满足一致性和可用性: CAP 理论指出,三者

RabbitMQ学习和使用

RabbitMQ学习和使用 RabbitMQ介绍 MQ全称Message Queue 消息队列,RabbitMQ是基于AMQP(高级消息队列协议)实现的.消息队列通常用以应用之间相互通信,解决同步问题.MQ是典型的生产者消费者模型,RabbitMQ最常用的三种模式是点对点模式.发布订阅模式.广播模式. RabbitMQ is a message-queueing software called a message broker or queue manager. Simply said; It

Exploring Message Brokers: RabbitMQ, Kafka, ActiveMQ, and Kestrel--reference

[This article was originally written by Yves Trudeau.] http://java.dzone.com/articles/exploring-message-brokers Message brokers are not regularly covered here but are, nonetheless, important web-related technologies. Some time ago, I was asked by one

【原创】RabbitMQ 之 Clustering 和 Network Partition(翻译)

Clustering and Network Partitions RabbitMQ clusters do not tolerate network partitions well. If you are thinking of clustering across a WAN, don't. You should use federation or the shovel instead. RabbitMQ 集群无法很好的应对网络分区情况.如果你打算跨 WAN 构建集群,请 别.你应该考虑使用

Rabbitmq集群部署Haproxy

安装前的说明: 1.为了配合做rabbitmq的负载均衡,本次的安装包是安装的低版本1.5.8版本,下载包的地址:https://src.fedoraproject.org/repo/pkgs/haproxy/2.按照上两篇博客,先把rabbitmq集群装好:单机版Rabbitmq部署:http://blog.51cto.com/10950710/2135676Rabbitmq集群部署:http://blog.51cto.com/10950710/2135717 安装步骤: 1.将haproxy