RabbitMQ普通集群搭建指南

RabbitMQ普通集群搭建指南

本文已经完全迁移至,www.geekery.cn 后续不在此更新

目标架构

本次搭建的目标是构建一个由三个节点组成的RabbitMQ集群,节点信息如下:

  • rabbit02 : IP地址 192.168.10.132
  • rabbit03 : IP地址 192.168.10.133
  • rabbit04 : IP地址 192.168.10.134

预备工作

在开始之前,确保所有节点上都已安装RabbitMQ Server。如果尚未安装,可以通过以下命令进行安装:

bash 复制代码
yum install -y epel-release
yum install -y rabbitmq-server

同时,设置主机名和修改/etc/hosts文件以正确解析各节点的名称。

同步.erlang.cookie

为了允许节点间通信,需要确保所有节点上的.erlang.cookie文件内容相同。使用以下命令从rabbit02节点复制cookie到其他节点

bash 复制代码
[root@rabbit02 ~]# scp /var/lib/rabbitmq/.erlang.cookie rabbit03:/var/lib/rabbitmq/
The authenticity of host 'rabbit03 (192.168.10.133)' can't be established.
ECDSA key fingerprint is SHA256:ImtbIE2DzY9M7yqwTDfMn3EzHOjk0CGowUigMe00exk.
ECDSA key fingerprint is MD5:23:d8:46:37:71:8b:e3:56:d1:48:d4:f5:a9:64:80:f0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'rabbit03,192.168.10.133' (ECDSA) to the list of known hosts.
root@rabbit03's password: 
.erlang.cookie                                                                                                                                             100%   20    24.5KB/s   00:00    
[root@rabbit02 ~]# scp /var/lib/rabbitmq/.erlang.cookie rabbit04:/var/lib/rabbitmq/
The authenticity of host 'rabbit04 (192.168.10.134)' can't be established.
ECDSA key fingerprint is SHA256:ImtbIE2DzY9M7yqwTDfMn3EzHOjk0CGowUigMe00exk.
ECDSA key fingerprint is MD5:23:d8:46:37:71:8b:e3:56:d1:48:d4:f5:a9:64:80:f0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'rabbit04,192.168.10.134' (ECDSA) to the list of known hosts.
root@rabbit04's password: 
.erlang.cookie                                                                                                                                             100%   20    21.1KB/s   00:00    
[root@rabbit02 ~]# 

集群配置

rabbit03rabbit04上执行以下步骤:

bash 复制代码
[root@rabbit03 ~]# rabbitmqctl stop_app
Stopping node rabbit@rabbit03 ...
...done.
[root@rabbit03 ~]# rabbitmqctl reset
Resetting node rabbit@rabbit03 ...
...done.
[root@rabbit03 ~]# systemctl stop firewalld
[root@rabbit03 ~]# rabbitmqctl join_cluster --ram rabbit@rabbit02
Clustering node rabbit@rabbit03 with rabbit@rabbit02 ...
...done.
bash 复制代码
[root@rabbit04 ~]# rabbitmqctl stop_app
Stopping node rabbit@rabbit04 ...
...done.
[root@rabbit04 ~]# systemctl stop firewalld
[root@rabbit04 ~]# rabbitmqctl stop_app
Stopping node rabbit@rabbit04 ...
...done.
[root@rabbit04 ~]# rabbitmqctl reset
Resetting node rabbit@rabbit04 ...
...done.
[root@rabbit04 ~]# rabbitmqctl join_cluster --ram rabbit@rabbit02
Clustering node rabbit@rabbit04 with rabbit@rabbit02 ...
...done.

最终确认

rabbit02上执行以下步骤来确认集群状态:

这表明集群已经成功建立,并且rabbit02作为磁盘节点,rabbit03rabbit04作为RAM节点加入了集群。

bash 复制代码
[root@rabbit02 ~]# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit02 ...
[{nodes,[{disc,[rabbit@rabbit02]},{ram,[rabbit@rabbit04,rabbit@rabbit03]}]},
 {running_nodes,[rabbit@rabbit02]},
 {cluster_name,<<"rabbit@rabbit02">>},
 {partitions,[]}]
...done.
[root@rabbit02 ~]# 

[root@rabbit03 ~]# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit03 ...
[{nodes,[{disc,[rabbit@rabbit02]},{ram,[rabbit@rabbit03]}]}]
...done.
[root@rabbit03 ~]# 

[root@rabbit03 ~]# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbit03 ...
[{nodes,[{disc,[rabbit@rabbit02]},{ram,[rabbit@rabbit03]}]}]
...done.

END

一些有用没用的历史命令!!!可以不用看了

bash 复制代码
yum install -y epel* ;yum install -y rabbitmq-server
vi /etc/hosts
hostnamectl set-hostname rabbit02
vi /etc/hosts
find / -name *.cookie
man rabbitmq-server
rabbitmq-server -detached
scp /var/lib/rabbitmq/.erlang.cookie rabbit03:/var/lib/rabbitmq/
scp /var/lib/rabbitmq/.erlang.cookie rabbit04:/var/lib/rabbitmq/
systemctl status rabbitmq-server
systemctl restart rabbitmq-server.service
systemctl status rabbitmq-server.service
chmod 400 /var/lib/rabbitmq/.erlang.cookie
systemctl restart rabbitmq-server.service
systemctl status rabbitmq-server.service
find / -name *.cookie
systemctl stop firewalld
rabbitmqctl cluster_status
history 

yum install -y epel* ;yum install -y rabbitmq-server
hostnamectl set-hostname rabbit03
vi /etc/hosts
 rabbitmq-server -detached
chmod 400 /var/lib/rabbitmq/.erlang.cookie
systemctl restart rabbitmq-server.service
systemctl status rabbitmq-server.service
systemctl restart rabbitmq-server.service
systemctl status rabbitmq-server.service
chmod 400 /var/lib/rabbitmq/.erlang.cookie
systemctl restart rabbitmq-server.service
rabbitmq-server -detached 
systemctl start rabbitmq-server.service
systemctl status rabbitmq-server.service
ps -ef | grep rabbit
kill -9 1969 
ps -ef | grep rabbit
kill -9 1999
ps -ef | grep rabbit
systemctl start rabbitmq-server.service
systemctl status rabbitmq-server.service
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbit@rabbit02
systemctl stop firewalld
rabbitmqctl join_cluster --ram rabbit@rabbit02
rabbitmqctl cluster_status
history 

yum install -y epel* ;yum install -y rabbitmq-server
hostnamectl set-hostname rabbit04
vi /etc/hosts
 rabbitmq-server -detached
chmod 400 /var/lib/rabbitmq/.erlang.cookie
systemctl restart rabbitmq-server
systemctl status rabbitmq-server
rabbitmq-server -detached
systemctl status rabbitmq-server
systemctl restart rabbitmq-server
find / -name *.cookie
ps -ef | grep rabbit
kill -9  1960 1990  
ps -ef | grep rabbit
systemctl restart rabbitmq-server
systemctl status rabbitmq-server
rabbitmqctl stop_app
systemctl stop firewalld
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbit@rabbit02
rabbitmqctl cluster_status
相关推荐
许苑向上29 分钟前
【零基础小白】 window环境下安装RabbitMQ
rabbitmq
ZHOU西口1 小时前
微服务实战系列之玩转Docker(十八)
分布式·docker·云原生·架构·数据安全·etcd·rbac
zmd-zk1 小时前
kafka+zookeeper的搭建
大数据·分布式·zookeeper·中间件·kafka
yx9o7 小时前
Kafka 源码 KRaft 模式本地运行
分布式·kafka
Gemini19957 小时前
分布式和微服务的区别
分布式·微服务·架构
G丶AEOM7 小时前
分布式——BASE理论
java·分布式·八股
P.H. Infinity13 小时前
【RabbitMQ】03-交换机
分布式·rabbitmq
龙哥·三年风水16 小时前
群控系统服务端开发模式-应用开发-个人资料
分布式·php·群控系统
funnyZpC18 小时前
quartz集群增强版🎉
java·分布式·开源·集群·定时任务
明达技术18 小时前
工业4.0时代下的分布式IO模块
分布式