在 Windows 系统上怎么使用rabbitmq相关命令,比如:rabbitmqctl list_queues 命令

文章目录

    • [方法一:使用 RabbitMQ Command Prompt(推荐)](#方法一:使用 RabbitMQ Command Prompt(推荐))
    • [方法二:使用普通命令提示符(CMD)或 PowerShell](#方法二:使用普通命令提示符(CMD)或 PowerShell)
    • [方法三:将 RabbitMQ 添加到系统环境变量 PATH(一劳永逸)](#方法三:将 RabbitMQ 添加到系统环境变量 PATH(一劳永逸))
    • 注意事项
    • 可能出现的问题
      • [什么是 Erlang Cookie?](#什么是 Erlang Cookie?)
      • 错误原因分析
      • 解决方案
        • [步骤 1:找到 `.erlang.cookie` 文件](#步骤 1:找到 .erlang.cookie 文件)
        • [步骤 2:找到 RabbitMQ 服务使用的 `.erlang.cookie`](#步骤 2:找到 RabbitMQ 服务使用的 .erlang.cookie)
        • [步骤 3:确保两个 cookie 文件内容一致](#步骤 3:确保两个 cookie 文件内容一致)
        • [步骤 4:统一 cookie 文件](#步骤 4:统一 cookie 文件)
        • [步骤 5:重启 RabbitMQ 服务](#步骤 5:重启 RabbitMQ 服务)
        • [步骤 6:再次运行命令](#步骤 6:再次运行命令)

在 Windows 系统上使用rabbitmq相关命令,有以下几种方式,本文以 rabbitmqctl list_queues 命令为例:

方法一:使用 RabbitMQ Command Prompt(推荐)

这是最简单的方法,适用于通过官方安装程序安装的 RabbitMQ,安装后自带。

  1. 打开 RabbitMQ Command Prompt
    • 点击 Windows 开始菜单。
    • 找到 RabbitMQ Server 文件夹,或者检索可以看到。
    • 点击其中的 "RabbitMQ Command Prompt"(或类似名称,如 "RabbitMQ Command Prompt (sbin dir)")。
  2. 执行命令
bash 复制代码
rabbitmqctl list_queues name messages_ready messages_unacknowledged
复制代码
- 在打开的命令行窗口中,直接输入:
- 按回车执行。

方法二:使用普通命令提示符(CMD)或 PowerShell

如果你不想使用专用的 RabbitMQ 命令提示符,可以手动指定路径。

  1. 打开 CMD 或 PowerShell
    • Win + R,输入 cmdpowershell,然后回车。
  2. 导航到 RabbitMQ 安装的 sbin 目录
bash 复制代码
cd "D:\developer\rabbitmq3.13.3\rabbitmq_server-<版本号>\sbin"

注意<版本号> 是你实际安装的版本,例如 rabbitmq_server-3.13.3。你可以通过文件资源管理器查看具体名称。

复制代码
- RabbitMQ 默认安装在 `C:\Program Files\RabbitMQ Server\`。
- 进入其 `sbin` 目录:
  1. 执行命令
bash 复制代码
rabbitmqctl.bat list_queues name messages_ready messages_unacknowledged

注意 :在 Windows 上,脚本文件是 .bat 后缀,所以是 rabbitmqctl.bat,但通常直接输入 rabbitmqctl 也可以。

方法三:将 RabbitMQ 添加到系统环境变量 PATH(一劳永逸)

这样你就可以在任意位置运行命令。

  1. 添加环境变量
    • 右键点击"此电脑"或"我的电脑" -> "属性"。
    • 点击"高级系统设置"。
    • 点击"环境变量"。
    • 在"系统变量"中找到 Path,点击"编辑"。
    • 点击"新建",然后添加 RabbitMQ 的 sbin 目录路径,例如:
      • D:\developer\rabbitmq3.13.3\rabbitmq_server-3.13.3\sbin
    • 点击"确定"保存所有设置。
  2. 重启 CMD/PowerShell
    • 关闭并重新打开你的命令行窗口。
  3. 直接执行命令
bash 复制代码
rabbitmqctl list_queues name messages_ready messages_unacknowledged
复制代码
- 现在你可以在任何目录下直接运行:

注意事项

  • 权限 :确保你以具有足够权限的用户身份运行命令提示符(通常是管理员权限,但通常普通用户也可以运行 rabbitmqctl)。
  • RabbitMQ 服务 :确保 RabbitMQ 服务正在运行。你可以在"服务"管理器中检查 RabbitMQ 服务的状态。
  • 网络和节点rabbitmqctl 默认连接本地节点。如果你要管理远程节点,需要配置环境变量或使用 --node 参数。

可能出现的问题

如果执行中报如下错误:

D:\developer\rabbitmq3.13.3\rabbitmq_server-3.13.3\sbin>rabbitmqctl list_queues name messages_ready messages_unacknowledged

Error: unable to perform an operation on node 'rabbit@MrZhan'. 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@MrZhan

  • If target node is configured to use long node names, don't forget to use --longnames with CLI tools

DIAGNOSTICS

===========

attempted to contact: [rabbit@MrZhan]

rabbit@MrZhan:

  • connected to epmd (port 4369) on MrZhan

  • epmd reports node 'rabbit' uses port 25672 for inter-node and CLI tool traffic

  • TCP connection succeeded but Erlang distribution failed

  • suggestion: check if the Erlang cookie is identical for all server nodes and CLI tools

  • suggestion: check if all server nodes and CLI tools use consistent hostnames when addressing each other

  • suggestion: check if inter-node connections may be configured to use TLS. If so, all nodes and CLI tools must do that

  • suggestion: see the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more

Current node details:

  • node name: 'rabbitmqcli-159-rabbit@MrZhan'

  • effective user's home directory: c:/Users/11876

  • Erlang cookie hash: QTxLXubDQ5UA1/9w86QRsA==

这个错误是 RabbitMQ 中非常典型的 节点连接和认证问题。错误信息明确指出:

TCP connection succeeded but Erlang distribution failed

suggestion: check if the Erlang cookie is identical for all server nodes and CLI tools

这意味着你的 rabbitmqctl 命令行工具虽然能连接到 RabbitMQ 节点的网络端口,但在 Erlang 层面的"节点间通信"失败了,最核心的原因是 Erlang Cookie 不匹配

什么是 Erlang Cookie?

RabbitMQ 使用 Erlang 的分布式机制,所有节点(包括 CLI 工具)之间通信需要一个共享的"密钥"------即 Erlang Cookie 。这个 cookie 是一个文件(.erlang.cookie),必须在 所有 RabbitMQ 节点和 CLI 工具 上保持完全一致,否则无法通信。

错误原因分析

你的错误日志显示:

  • CLI 工具尝试连接节点 rabbit@MrZhan
  • TCP 连接成功(说明端口 25672 没问题)。
  • 但 Erlang 分布式通信失败。
  • 提示:Erlang cookie 不匹配

解决方案

步骤 1:找到 .erlang.cookie 文件

这个文件通常位于:

  • Windows : C:\Users\<你的用户名>\.erlang.cookie
  • 或者:C:\Windows\.erlang.cookie
  • 有时在 Erlang 安装目录下。

在你的错误信息中,提到了:

plain 复制代码
effective user's home directory: c:/Users/11876

所以你应该去:

plain 复制代码
c:\Users\11876\.erlang.cookie

查看是否存在这个文件。

步骤 2:找到 RabbitMQ 服务使用的 .erlang.cookie

RabbitMQ 服务运行时也有自己的 cookie 文件。它通常位于:

plain 复制代码
C:\Windows\System32\config\systemprofile\.erlang.cookie

注意:这是 RabbitMQ 服务器运行时使用的 cookie,可能和你用户目录下的不一样。

  1. 打开 c:\Users\11876\.erlang.cookie(CLI 工具用的)。
  2. 打开 <font style="color:rgb(38, 44, 49);">C:\Windows\System32\config\systemprofile\.erlang.cookie</font>\.erlang.cookie(RabbitMQ 服务用的)。
  3. 比较两个文件的内容是否完全相同(包括大小写、空格等)。
  • 推荐做法:将服务端的 cookie 文件内容复制到用户目录下,覆盖 CLI 工具使用的 cookie。
bash 复制代码
copy C:\Windows\System32\config\systemprofile\.erlang.cookie\.erlang.cookie c:\Users\11876\.erlang.cookie
  • 或者反过来,但必须确保一致

⚠️ 注意:.erlang.cookie 文件的权限在 Windows 上通常不是问题,但在某些系统上需要设置为只读或限制访问。

步骤 5:重启 RabbitMQ 服务

修改 cookie 后,必须重启 RabbitMQ 服务:

  1. 打开 "服务" 管理器(services.msc)。
  2. 找到 RabbitMQ 服务。
  3. 右键选择 重启
步骤 6:再次运行命令
bash 复制代码
rabbitmqctl list_queues name messages_ready messages_unacknowledged

现在应该可以正常执行了。

本文内容到此结束了,

如有收获欢迎点赞👍收藏💖关注✔️,您的鼓励是我最大的动力。

如有错误❌疑问💬欢迎各位指出。
主页共饮一杯无的博客汇总👨‍💻

保持热爱,奔赴下一场山海。🏃🏃🏃

相关推荐
zhangfeng11333 小时前
Windows 的 Git Bash 中使用 md5sum 命令非常简单 md5做文件完整性检测 WinRAR 可以计算文件的 MD5 值
人工智能·windows·git·bash
彭波3965 小时前
.NET Framework 3.5问题修复教程!可以离线修复
windows·安全·电脑·.net·开源软件
love530love6 小时前
OpenClaw 手机直连配置全流程
人工智能·windows·python·智能手机·c#·agent·openclaw
AnalogElectronic9 小时前
windows递归遍历当前目录下文件并重命名程序
windows
web3.08889999 小时前
taoxi商品详情|商品属性|包装规格信息 API接口
windows
新手886011 小时前
Oracle VirtualBox虚拟机安装 和 安装 window11版本虚拟机 及 启用EFI和硬盘无法使用 问题
服务器·windows·计算机网络·安全·虚拟机
门豪杰11 小时前
Windows下配置针对WSL的cc-switch
windows·claude·claude code·cc-switch·cc switch
姓王名礼11 小时前
一份 Windows/macOS/Linux 完整安装 + 运行 + 对接 WebUI 的步骤
linux·windows·macos
开开心心就好12 小时前
绿色版PDF多功能工具,支持编辑转换
人工智能·windows·pdf·ocr·excel·语音识别·harmonyos
武藤一雄13 小时前
C#常见面试题100问 (第一弹)
windows·microsoft·面试·c#·.net·.netcore