rabbitmq消息队列简介
RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息代理软件(亦称面向消息的中间件)
可伸缩性:集群服务
消息持久化:从内存持久化消息到硬盘,再从硬盘加载到内存
安装rabbitmq
[[email protected] ~]# yum install -y rabbitmq-server
[[email protected] ~]# yum install -y rabbitmq-server
配置监听地址
[[email protected] ~]# vi /etc/rabbitmq/rabbitmq-env.conf #创建这个文件
RABBITMQ_NODE_IP_ADDRESS=192.168.200.4
RABBITMQ_NODE_PORT=5672
[[email protected] ~]# vi /etc/rabbitmq/rabbitmq-env.conf
RABBITMQ_NODE_IP_ADDRESS=192.168.200.5
RABBITMQ_NODE_PORT=5672
启动服务(只启动一个节点)
[[email protected] ~]# systemctl start rabbitmq-server
拷贝.erlang.cookie文件到node-2节点
[[email protected] ~]# scp /var/lib/rabbitmq/.erlang.cookie node-2:/var/lib/rabbitmq/
.erlang.cookie 100% 20 0.0KB/s 00:00
[[email protected] ~]# ll /var/lib/rabbitmq/.erlang.cookie
-r-------- 1 root root 20 Apr 25 18:39 /var/lib/rabbitmq/.erlang.cookie
[[email protected] ~]# chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie
[[email protected] ~]# ll /var/lib/rabbitmq/.erlang.cookie
-r-------- 1 rabbitmq rabbitmq 20 Apr 25 18:39 /var/lib/rabbitmq/.erlang.cookie
启动node-2节点的rabbitmq
[[email protected] ~]# systemctl start rabbitmq-server
将node-2与node-1组成集群
[[email protected] ~]# rabbitmqctl stop_app
Stopping node ‘[email protected]‘ ...
[[email protected] ~]# rabbitmqctl join_cluster [email protected]
Clustering node ‘[email protected]‘ with ‘[email protected]‘ ...
[[email protected] ~]# rabbitmqctl start_app
Starting node ‘[email protected]‘ ...
查看集群状态
[[email protected] ~]# rabbitmqctl cluster_status
Cluster status of node ‘[email protected]‘ ...
[{nodes,[{disc,[‘[email protected]‘,‘[email protected]‘]}]},
{running_nodes,[‘[email protected]‘,‘[email protected]‘]},
{cluster_name,<<"[email protected]">>},
{partitions,[]},
{alarms,[{‘[email protected]‘,[]},{‘[email protected]‘,[]}]}]
#可以看到node-2已经和node-1组成集群
设置镜像队列
[[email protected] ~]# rabbitmqctl set_policy ha-all ‘^(?!amq\.).*‘ ‘{"ha-mode": "all"}‘
Setting policy "ha-all" for pattern "^(?!amq\\.).*" to "{\"ha-mode\": \"all\"}" with priority "0" ...
#在哪个节点都可以执行
#将所有队列设置为镜像队列,即队列会被复制到各个节点,各个节点状态保持一致。
原文地址:https://blog.51cto.com/9103824/2384531
时间: 2024-10-07 19:22:33