每个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