centos7.9 搭建rabbitmq集群,两台服务器

22 篇文章 0 订阅
4 篇文章 0 订阅

目录

1、修改linux配置文件

2、复制cookie内容

3、创建用户登录查看是否创建成功

4、重启后报错的问题


首先准备好环境,rabbit安装见:

centos7.9 安装rabbitmq_fyihdg的博客-CSDN博客

我是这个成功安装的基础上搭建的rabbitmq集群,

我安装的是普通集群,

192.168.1.61   rabbitmq1    (主)
192.168.1.62   rabbitmq2   (从)

1、修改linux配置文件

两台服务器修改如下:

vi /etc/hosts 

 

使用命令查询主机是否修改:

hostnamectl 

如果发现hostname名字没修改成host文件中的名字,执行命令修改:

hostnamectl set-hostname  rabbitmq1

2、复制cookie内容

首先切换到.erlang.cookie,所有的目录,默认是在:/var/lib/rabbimq

但有时候,命令ll -a 居然没有!!!然后怎么办?写了一个程序,连接到rabbitmq,发几条消息,消费几条消息,重启后,就生成了。

cd /var/lib/rabbitmq

把主服务器上的.erlang.cookie文件,复制到从服务器,相同的位置,可以把这个文件下载到本机,再上传到从服务器,或者使用命令复制,在主服务器上操作:

scp .erlang.cookie root@192.168.1.62:/var/lib/rabbitmq/.erlang.cookie

回车会提示输入root密码,输入回车就行

 然后授权, .erlang.cookie 文件权限只能是600,777我试过,不行的

chmod 600 .erlang.cookie

 

 要注意这里,刚刚复制过来的是root,用户,要修改过来

chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie

主服务器执行如今命令:


rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
如果报:You cannot reset a node when it is the only disc node in a cluster,执行:
​​​​​​​rabbitmqctl force_reset

执行rabbitmqctl stop_app命令可能会报错:

[root@rabbitmq01 rabbitmq]# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@rabbitmq01 ...
Error: unable to perform an operation on node 'rabbit@rabbitmq01'. Please see diagnostics information and suggestions below.

Most common reasons for this are:

 * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)
 * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)
 * Target node is not running

In addition to the diagnostics info below:

 * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more
 * Consult server logs on node rabbit@rabbitmq01
 * If target node is configured to use long node names, don't forget to use --longnames with CLI tools

DIAGNOSTICS
===========

attempted to contact: [rabbit@rabbitmq01]

rabbit@rabbitmq01:
  * connected to epmd (port 4369) on rabbitmq01
  * epmd reports: node 'rabbit' not running at all
                  no other nodes on rabbitmq01
  * suggestion: start the node

Current node details:
 * node name: 'rabbitmqcli-1562-rabbit@rabbitmq01'
 * effective user's home directory: /var/lib/rabbitmq
 * Erlang cookie hash: KiLCK6kZzMo9nB0K7pdlng==

 解决的办法是,输入命令:

systemctl start rabbitmq-server

就可以解决了

然后从服务器分别执行命令: 

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster  rabbit@rabbitmq1   
rabbitmqctl start_app

可能会报以下错误:

[root@rabbitmq02 rabbitmq]# rabbitmqctl join_cluster  rabbit@rabbitmq01
Clustering node rabbit@rabbitmq02 with rabbit@rabbitmq01
Error: unable to perform an operation on node 'rabbit@rabbitmq01'. Please see diagnostics information and suggestions below.

Most common reasons for this are:

 * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)
 * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)
 * Target node is not running

In addition to the diagnostics info below:

 * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more
 * Consult server logs on node rabbit@rabbitmq01
 * If target node is configured to use long node names, don't forget to use --longnames with CLI tools

DIAGNOSTICS
===========

attempted to contact: [rabbit@rabbitmq01]

rabbit@rabbitmq01:
  * unable to connect to epmd (port 4369) on rabbitmq01: address (cannot connect to host/port)


Current node details:
 * node name: 'rabbitmqcli-1958-rabbit@rabbitmq02'
 * effective user's home directory: /var/lib/rabbitmq
 * Erlang cookie hash: KiLCK6kZzMo9nB0K7pdlng==

[root@rabbitmq02 rabbitmq]# systemctl start firewalld
[root@rabbitmq02 rabbitmq]# systemctl stop firewalld

解决的办法是,在主服务器和从服务上执行以下命令:先开启防火封墙,再关闭

 systemctl start firewalld
 
 systemctl stop firewalld

3、创建用户登录查看是否创建成功

两台服务器分别执行命令,其中root是我自己定义,可以随意修改

rabbitmqctl add_user root root
rabbitmqctl set_user_tags root administrator
rabbitmqctl set_permissions -p / root ".*" ".*" ".*"

这样的方式还不够完善,一台挂了,另一台就无法消费消息了,所以, 要设置镜像模式:

 

 

查看集群状态:

rabbitmqctl cluster_status

集群搭建成功了

4、重启后报错的问题

  当关机然后第二天启动,发现服务无法启动:

[root@rabbitmq02 ~]# service rabbitmq-server   start
Redirecting to /bin/systemctl start rabbitmq-server.service
Job for rabbitmq-server.service failed because a timeout was exceeded. See "systemctl status rabbitmq-server.service" and "journalctl -xe" for details.
[root@rabbitmq02 ~]# 

这里一定要注意:

一定先启动从节点,再启动主节点, 否则会一直卡在命令窗口

需要的朋友在这里可以下载:

安装了RocketMQ集群,rabbitmq集群,Mware-Java文档类资源-CSDN下载除了一台刚刚安装完成,纯净版的,没有做任何开更改,剩下都是从纯净版克隆过来的,所有的VM虚拟机的ro更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/fyihdg/85620849

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fyihdg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值