双节点部署rabbitmq集群

rabbitmq消息队列简介

RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件)
可伸缩性:集群服务
消息持久化:从内存持久化消息到硬盘,再从硬盘加载到内存

安装rabbitmq

[root@node-1 ~]# yum install -y rabbitmq-server
[root@node-2 ~]# yum install -y rabbitmq-server

配置监听地址

[root@node-1 ~]# vi /etc/rabbitmq/rabbitmq-env.conf    #创建这个文件
RABBITMQ_NODE_IP_ADDRESS=192.168.200.4
RABBITMQ_NODE_PORT=5672
[root@node-2 ~]# vi /etc/rabbitmq/rabbitmq-env.conf 
RABBITMQ_NODE_IP_ADDRESS=192.168.200.5
RABBITMQ_NODE_PORT=5672

启动服务(只启动一个节点)

[root@node-1 ~]# systemctl start rabbitmq-server

拷贝.erlang.cookie文件到node-2节点

[root@node-1 ~]# scp /var/lib/rabbitmq/.erlang.cookie node-2:/var/lib/rabbitmq/
.erlang.cookie                                                         100%   20     0.0KB/s   00:00 

[root@node-2 ~]# ll /var/lib/rabbitmq/.erlang.cookie 
-r-------- 1 root root 20 Apr 25 18:39 /var/lib/rabbitmq/.erlang.cookie
[root@node-2 ~]# chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie 
[root@node-2 ~]# ll /var/lib/rabbitmq/.erlang.cookie                         
-r-------- 1 rabbitmq rabbitmq 20 Apr 25 18:39 /var/lib/rabbitmq/.erlang.cookie

启动node-2节点的rabbitmq

[root@node-2 ~]# systemctl start rabbitmq-server

将node-2与node-1组成集群

[root@node-2 ~]# rabbitmqctl stop_app
Stopping node 'rabbit@node-2' ...
[root@node-2 ~]# rabbitmqctl join_cluster rabbit@node-1
Clustering node 'rabbit@node-2' with 'rabbit@node-1' ...
[root@node-2 ~]# rabbitmqctl start_app
Starting node 'rabbit@node-2' ...

查看集群状态

[root@node-1 ~]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@node-1' ...
[{nodes,[{disc,['rabbit@node-1','rabbit@node-2']}]},
 {running_nodes,['rabbit@node-2','rabbit@node-1']},
 {cluster_name,<<"rabbit@node-1">>},
 {partitions,[]},
 {alarms,[{'rabbit@node-2',[]},{'rabbit@node-1',[]}]}]
 #可以看到node-2已经和node-1组成集群

设置镜像队列

[root@node-1 ~]# rabbitmqctl set_policy ha-all '^(?!amq\.).*' '{"ha-mode": "all"}'
Setting policy "ha-all" for pattern "^(?!amq\\.).*" to "{\"ha-mode\": \"all\"}" with priority "0" ...
#在哪个节点都可以执行 
#将所有队列设置为镜像队列,即队列会被复制到各个节点,各个节点状态保持一致。
上一篇:Linux RabbitMQ导入管理界面报错


下一篇:PCL读取PCD文件的数据