RabbitMQ 集群测试

RabbitMQ 集群测试

作者:Hily 原始链接:http://hily.me/blog/2010/05/rabbitmq-test-cluster/
版权声明:可以转载,转载时务必以超链接形式标明文章原始出处作者信息版权声明

#### 创建节点 ####

在本机上新建三个节点进行测试:

节点1:test1@gentoo
# export RABBITMQ_NODENAME=test1
# export RABBITMQ_NODE_PORT=5672
# ./rabbitmq-server -detached

节点2:test1@gentoo
# export RABBITMQ_NODENAME=test2
# export RABBITMQ_NODE_PORT=5673
# ./rabbitmq-server -detached

节点3:test1@gentoo
# export RABBITMQ_NODENAME=test3
# export RABBITMQ_NODE_PORT=5674
# ./rabbitmq-server -detached

#### 创建集群 ####

下面要将上述结点组成一个 cluster,其中 test2@gentoo 为 ram node,另两个为 disk node。
创建 ram node 和 disk node 方法请参见 RabbitMQ 帮助文档:

http://www.rabbitmq.com/admin-guide.html#cluster

------
Example:

rabbitmqctl cluster rabbit@tanto hare@elena
This command instructs the RabbitMQ node to join the cluster with nodes rabbit@tanto and

hare@elena. If the node is one of these then it becomes a disk node, otherwise a ram

node.
------

将 test2@gentoo 做为 ram node 添加到 cluster 中:
# ./rabbitmqctl -n test2@gentoo stop_app
# ./rabbitmqctl -n test2@gentoo reset
# ./rabbitmqctl -n test2@gentoo cluster test1@gentoo
# ./rabbitmqctl -n test2@gentoo start_app
# ./rabbitmqctl -n test2@gentoo status
Status of node test2@gentoo ...
[...,
{nodes,[test2@gentoo,test1@gentoo]},
{running_nodes,[test1@gentoo,test2@gentoo]}]
...done.

将 test3@gentoo 做为 disk node 添加到 cluster 中:
# ./rabbitmqctl -n test3@gentoo stop_app
# ./rabbitmqctl -n test3@gentoo reset
# ./rabbitmqctl -n test3@gentoo cluster test1@gentoo test3@gentoo
# ./rabbitmqctl -n test3@gentoo start_app
# ./rabbitmqctl -n test3@gentoo status
Status of node test3@gentoo ...
[...,
{running_nodes,[test1@gentoo,test2@gentoo,test3@gentoo]}]
...done.

再来看看三个节点的汇总状态:
# ./rabbitmqctl -n test1@gentoo status
Status of node test1@gentoo ...
[...,
{nodes,[test3@gentoo,test2@gentoo,test1@gentoo]},
{running_nodes,[test3@gentoo,test2@gentoo,test1@gentoo]}]
...done.
# ./rabbitmqctl -n test2@gentoo status
Status of node test2@gentoo ...
[...,
{nodes,[test3@gentoo,test2@gentoo,test1@gentoo]},
{running_nodes,[test3@gentoo,test1@gentoo,test2@gentoo]}]
...done.
# ./rabbitmqctl -n test3@gentoo status
Status of node test3@gentoo ...
[...,
{nodes,[test3@gentoo,test2@gentoo,test1@gentoo]},
{running_nodes,[test1@gentoo,test2@gentoo,test3@gentoo]}]
...done.

#### 修改节点类型 ####

下面演示修改节点的类型:
* 将 test2@gentoo 修改为 disk node
* 将 test3@gentoo 修改为 ram node

修改节点类型,只需要 stop_app,不需要 reset。

修改 test2@gentoo:
# ./rabbitmqctl -n test2@gentoo stop_app
# ./rabbitmqctl -n test2@gentoo cluster test1@gentoo test2@gentoo
# ./rabbitmqctl -n test2@gentoo start_app

修改 test3@gentoo:
# ./rabbitmqctl -n test3@gentoo stop_app
# ./rabbitmqctl -n test3@gentoo cluster test1@gentoo test2@gentoo
# ./rabbitmqctl -n test3@gentoo start_app

#### 重启节点 ####

下面通过重启 test1@gentoo 和 test3@gentoo 节点来观察集群的状态:

停止 test1@gentoo:
# ./rabbitmqctl -n test1@gentoo stop
# ./rabbitmqctl -n test2@gentoo status
Status of node test2@gentoo ...
[...,
{nodes,[test3@gentoo,test2@gentoo,test1@gentoo]},
{running_nodes,[test3@gentoo,test2@gentoo]}]
...done.
# ./rabbitmqctl -n test3@gentoo status
Status of node test3@gentoo ...
[...,
{nodes,[test3@gentoo,test2@gentoo,test1@gentoo]},
{running_nodes,[test2@gentoo,test3@gentoo]}]
...done.

停止 test3@gentoo:
# ./rabbitmqctl -n test3@gentoo stop
# ./rabbitmqctl -n test2@gentoo status
Status of node test2@gentoo ...
[...,
{nodes,[test3@gentoo,test2@gentoo,test1@gentoo]},
{running_nodes,[test2@gentoo]}]
...done.

启动 test1@gentoo:
# export RABBITMQ_NODENAME=test1
# export RABBITMQ_NODE_PORT=5672
# ./rabbitmq-server -detached
# ./rabbitmqctl -n test2@gentoo status
Status of node test2@gentoo ...
[...,
{nodes,[test3@gentoo,test2@gentoo,test1@gentoo]},
{running_nodes,[test1@gentoo,test2@gentoo]}]
...done.

启动 test3@gentoo:
# export RABBITMQ_NODENAME=test3
# export RABBITMQ_NODE_PORT=5674
# ./rabbitmq-server -detached

再检查3个节点的状态:
# ./rabbitmqctl -n test1@gentoo status
Status of node test1@gentoo ...
[...,
{nodes,[test3@gentoo,test2@gentoo,test1@gentoo]},
{running_nodes,[test3@gentoo,test2@gentoo,test1@gentoo]}]
...done.
# ./rabbitmqctl -n test2@gentoo status
Status of node test2@gentoo ...
[...,
{nodes,[test3@gentoo,test2@gentoo,test1@gentoo]},
{running_nodes,[test3@gentoo,test1@gentoo,test2@gentoo]}]
...done.
# ./rabbitmqctl -n test3@gentoo status
Status of node test3@gentoo ...
[...,
{nodes,[test3@gentoo,test2@gentoo,test1@gentoo]},
{running_nodes,[test1@gentoo,test2@gentoo,test3@gentoo]}]
...done.

一切正常!

#### 移除节点 ####

很简单,只需要在 stop_app 后做一次 reset 操作即可。

如移除 test3@gentoo,使其成为独立节点:
# ./rabbitmqctl -n test3@gentoo stop_app
# ./rabbitmqctl -n test3@gentoo reset
# ./rabbitmqctl -n test3@gentoo start_app

查看3个节点的状态:
# ./rabbitmqctl -n test1@gentoo status
Status of node test1@gentoo ...
[...,
{nodes,[test2@gentoo,test1@gentoo]},
{running_nodes,[test2@gentoo,test1@gentoo]}]
...done.
# ./rabbitmqctl -n test2@gentoo status
Status of node test2@gentoo ...
[...,
{nodes,[test2@gentoo,test1@gentoo]},
{running_nodes,[test1@gentoo,test2@gentoo]}]
...done.
# ./rabbitmqctl -n test3@gentoo status
Status of node test3@gentoo ...
[...,
{nodes,[test3@gentoo]},
{running_nodes,[test3@gentoo]}]
...done.

可以发现,test3@gentoo 已从 cluster 中移除。

接着移除 test2@gentoo:
# ./rabbitmqctl -n test2@gentoo stop_app
# ./rabbitmqctl -n test2@gentoo reset
# ./rabbitmqctl -n test2@gentoo start_app

查看3个节点的状态:
# ./rabbitmqctl -n test1@gentoo status
Status of node test1@gentoo ...
[...,
{nodes,[test1@gentoo]},
{running_nodes,[test1@gentoo]}]
...done.
# ./rabbitmqctl -n test2@gentoo status
Status of node test2@gentoo ...
[...,
{nodes,[test2@gentoo]},
{running_nodes,[test2@gentoo]}]
...done.
# ./rabbitmqctl -n test3@gentoo status
Status of node test3@gentoo ...
[...,
{nodes,[test3@gentoo]},
{running_nodes,[test3@gentoo]}]
...done.

就剩下 test1@gentoo 了,这个节点中还残留着 cluster 的信息。

帮助里说到,最后一个节点使用 reset 会出错,要使用 force_reset:

------
Note that we used force_reset here. The reason is that removing a node from a cluster updates only the node-local configuration of the cluster, and that calling reset gets the node to connect to any of the other nodes that it believes are in the cluster, to perform some house-keeping that is necessary when leaving a cluster. However, at this point, there are no other nodes in the cluster, but rabbit@rabbit2 doesn't know this. As a result, calling reset would fail, as it can't connect to rabbit@rabbit1 or rabbit@rabbit3, hence the use of force_reset, in which rabbit@rabbit2 does not attempt to contact any other nodes in the cluster. This situation only arises when resetting the last remaining node of a cluster.
------

但是我用 reset 也是正常的!可能是版本不一样吧。

##############

到此为止,先下班回家!

-- EOF --

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值