Loading...
CentOS 6.7 部署RabbitMQ消息中间件集群

RabbitMQ笔记 2015/12/18 RabbitMQ , CentOS

CentOS 6.7 部署RabbitMQ消息中间件集群

#准备工作

分别在两台名centos1和centos2的CentOS6.7安装RabbitMQ消息中间件节点:详情步骤请查看:http://imethan.cn/blog/article/78

将节点服务更新为“stop”状态


#集群说明

默认安装的RabbitMQ节点会自动生成“Erlang cookie”,该cookie用于识别是否是集群中的一个节点,集群中的全部节点的cookie必须保持一致,否则没办法成为集群中的一个节点。

默认安装生成的cookie位于“/var/lib/rabbitmq/.erlang.cookie”路径或者是“$HOME/.erlang.cookie”路径


#将centos1中的“/var/lib/rabbitmq/.erlang.cookie”复制到centos2的“/var/lib/rabbitmq/”目录下


#分别启动CentOS的RabbitMQ服务

cd /usr/lib/rabbitmq/bin

centos1$ rabbitmq-server -detached

centos2$ rabbitmq-server -detached


#启动过程中出现如下问题:

"Cookie file /var/lib/rabbitmq/.erlang.cookie must be accessible by owner only"

chmod 600 /var/lib/rabbitmq/.erlang.cookie


“Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces”

vi /var/lib/rabbitmq/.erlang.cookie

将centos1中的cookie内容copy到centos2中的cookie


#两个节点独立启动后查看状态

centos1$ rabbitmqctl cluster_status

Cluster status of node rabbit@centos1 ...

[{nodes,[{disc,[rabbit@centos1]}]},

 {running_nodes,[rabbit@centos1]},

 {cluster_name,<<"rabbit@centos1.imethan.cn">>},

 {partitions,[]}]


centos2$ rabbitmqctl cluster_status

Cluster status of node rabbit@centos2 ...

[{nodes,[{disc,[rabbit@centos2]}]},

 {running_nodes,[rabbit@centos2]},

 {cluster_name,<<"rabbit@centos2.imethan.cn">>},

 {partitions,[]}]


#创建集群,将centos2节点加入centos1集群

centos2$ rabbitmqctl stop_app

Stopping node rabbit@centos2 ...

centos2$ rabbitmqctl join_cluster rabbit@centos1

Clustering node rabbit@centos2 with rabbit@centos1 ...

centos2$ rabbitmqctl start_app

Starting node rabbit@centos2 ...


#查看集群状态

centos1$ rabbitmqctl cluster_status

Cluster status of node rabbit@centos1 ...

[{nodes,[{disc,[rabbit@centos1,rabbit@centos2]}]},

 {running_nodes,[rabbit@centos2,rabbit@centos1]},

 {cluster_name,<<"rabbit@centos1.imethan.cn">>},

 {partitions,[]}]


centos2$ rabbitmqctl cluster_status

Cluster status of node rabbit@centos2 ...

[{nodes,[{disc,[rabbit@centos1,rabbit@centos2]}]},

 {running_nodes,[rabbit@centos1,rabbit@centos2]},

 {cluster_name,<<"rabbit@centos1.imethan.cn">>},

 {partitions,[]}]


登录WEB管理界面首页查看集群状态

NameFile descriptors (?)Socket descriptors (?)Erlang processesMemoryDisk spaceInfo+/-
rabbit@centos1
25
1024 available
1
829 available
181
1048576 available
39MB
395MB high watermark
13GB
48MB low watermark
Disc 1 Stats
rabbit@centos2
20
1024 available
1
829 available
175
1048576 available
38MB
395MB high watermark
12GB
48MB low watermark
Disc 1


至此,centos1和centos2的RabbitMQ集群部署完成。



#其他管理操作

#重启节点,本例子集群中只有两个节点,如果将其中的主节点停止,集群的另外节点将切换为主节点

centos1$ rabbitmqctl stop

Stopping and halting node rabbit@centos1 ...


centos2$ rabbitmqctl cluster_status

[{nodes,[{disc,[rabbit@centos1,rabbit@centos2]}]},

 {running_nodes,[rabbit@centos2]},

 {cluster_name,<<"rabbit@centos1.imethan.cn">>},

 {partitions,[]}]


NameFile descriptors (?)Socket descriptors (?)Erlang processesMemoryDisk spaceInfo+/-
rabbit@centos1
Node not running
rabbit@centos2
25
1024 available
1
829 available
181
1048576 available
38MB
395MB high watermark
12GB
48MB low watermark
Disc 1 Stats


centos1$ rabbitmq-server -detached

centos1$ rabbitmqctl cluster_status

Cluster status of node rabbit@centos1 ...

[{nodes,[{disc,[rabbit@centos1,rabbit@centos2]}]},

 {running_nodes,[rabbit@centos2,rabbit@centos1]},

 {cluster_name,<<"rabbit@centos1.imethan.cn">>},

 {partitions,[]}]


NameFile descriptors (?)Socket descriptors (?)Erlang processesMemoryDisk spaceInfo+/-
rabbit@centos1
25
1024 available
1
829 available
179
1048576 available
38MB
395MB high watermark
13GB
48MB low watermark
Disc 1
rabbit@centos2
25
1024 available
1
829 available
181
1048576 available
38MB
395MB high watermark
12GB
48MB low watermark
Disc 1 Stats


#从集群中移除一个节点

停止节点

centos2$ rabbitmqctl stop_app

Stopping node rabbit@centos2 ...

重置节点

centos2$ rabbitmqctl reset

Resetting node rabbit@rabbit2 ...done.

启动节点

centos2$ rabbitmqctl start_app

Starting node rabbit@rabbit2 ...done.


查看centos2节点是否已经移除

centos1$ rabbitmqctl cluster_status

Cluster status of node rabbit@centos1 ...

[{nodes,[{disc,[rabbit@centos1]}]},

 {running_nodes,[rabbit@centos1]},

 {cluster_name,<<"rabbit@centos1.imethan.cn">>},

 {partitions,[]}]


#默认安装的集群节点是“Disc”类型,可以设置节点类型为“Ram”

centos2$ rabbitmqctl stop_app

Stopping node rabbit@centos2 ...done.

centos2$ rabbitmqctl join_cluster --ram rabbit@centos1

Clustering node rabbit@centos2 with [rabbit@centos1] ...done.

centos2$ rabbitmqctl start_app

Starting node rabbit@centos2 ...done.


centos2$ rabbitmqctl cluster_status

Cluster status of node rabbit@centos2 ...

[{nodes,[{disc,[rabbit@centos1]},{ram,[rabbit@centos2]}]},

 {running_nodes,[rabbit@centos1,rabbit@centos2]},

 {cluster_name,<<"rabbit@centos1.imethan.cn">>},

 {partitions,[]}]


#修改centos2节点类型为“Ram”,集群中必须存在一个“Disc”类型的节点

centos2$ rabbitmqctl stop_app

Stopping node rabbit@centos2 ...

centos2$ rabbitmqctl change_cluster_node_type disc

Turning rabbit@rabbit2 into a ram node ...

centos2$ rabbitmqctl start_app

Starting node rabbit@centos2 ...


查看状态

centos2$ rabbitmqctl cluster_status

Cluster status of node rabbit@centos2 ...

[{nodes,[{disc,[rabbit@centos1,rabbit@centos2]}]},

 {running_nodes,[rabbit@centos1,rabbit@centos2]},

 {cluster_name,<<"rabbit@centos1.imethan.cn">>},

 {partitions,[]}]






#参考文档

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

http://www.cnblogs.com/avril/archive/2010/03/23/1692809.html




Comments