IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> centos7.9 搭建rabbitmq集群,两台服务器 -> 正文阅读

[系统运维]centos7.9 搭建rabbitmq集群,两台服务器

首先准备好环境,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

集群搭建成功了

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-05-14 10:14:48  更:2022-05-14 10:16:01 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年6日历 -2024/6/26 22:48:56-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码