写点什么

rabbitmq-server 基础 windows 安装 rabbitmq-server,启用 mqtt 服务

  • 2024-07-24
    北京
  • 本文字数:8008 字

    阅读完需:约 26 分钟

压缩包内容

下载的是压缩包,解压之后拷贝到了常用的程序文件下,压缩包内的具体内容如下图所示:


进入目录

  • 具体路径如下所示

  • 你会看到该目录下有许多 bat 文件


D:\Program Files\rabbitmq_server-3.13.5\sbin
复制代码


安装插件

  • 后话:这里少安装了插件,导致 mqtt 服务没起来,后面花了半个多小时才明白错在哪里。


Microsoft Windows [版本 10.0.22631.3880](c) Microsoft Corporation。保留所有权利。
D:\Program Files\rabbitmq_server-3.13.5\sbin>rabbitmq-plugins enable rabbitmq_managementEnabling plugins on node rabbit@LAPTOP-95QSHN0F:rabbitmq_managementThe following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatchApplying plugin configuration to rabbit@LAPTOP-95QSHN0F...The following plugins have been enabled: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch
set 3 plugins.Offline change; changes will take effect at broker restart.
D:\Program Files\rabbitmq_server-3.13.5\sbin>
复制代码

添加环境变量


RABBITMQ_HOMED:\Program Files\rabbitmq_server-3.13.5
复制代码

在 PATH 中追加变量

运行管理员权限的 CMD

  • 错误的示范


Microsoft Windows [版本 10.0.22631.3880](c) Microsoft Corporation。保留所有权利。
C:\Users\admin>rabbitmq-service
*********************Service control usage*********************
rabbitmq-service help - Display this helprabbitmq-service install - Install the RabbitMQ servicerabbitmq-service remove - Remove the RabbitMQ service
The following actions can also be accomplished by usingWindows Services Management Console (services.msc):
rabbitmq-service start - Start the RabbitMQ servicerabbitmq-service stop - Stop the RabbitMQ servicerabbitmq-service disable - Disable the RabbitMQ servicerabbitmq-service enable - Enable the RabbitMQ service

C:\Users\admin>rabbitmq-service start服务名无效。
请键入 NET HELPMSG 2185 以获得更多的帮助。

C:\Users\admin>rabbitmq-service installD:\Program Files\Erlang OTP\erts-14.2.5.2\bin\erlsrv: Unable to register RabbitMQ service with service manager.Error: ¾Ü¾ø·ÃÎÊ¡£D:\Program Files\Erlang OTP\erts-14.2.5.2\bin\erlsrv: No service with the name RabbitMQ exists.
C:\Users\admin>
复制代码


  • 猜测是 cmd 的权限不够,于是切换到管理员权限再次运行相关命令。

  • 正确的示范


Microsoft Windows [版本 10.0.22631.3880](c) Microsoft Corporation。保留所有权利。
C:\Windows\System32>rabbitmq-service insatll
*********************Service control usage*********************
rabbitmq-service help - Display this helprabbitmq-service install - Install the RabbitMQ servicerabbitmq-service remove - Remove the RabbitMQ service
The following actions can also be accomplished by usingWindows Services Management Console (services.msc):
rabbitmq-service start - Start the RabbitMQ servicerabbitmq-service stop - Stop the RabbitMQ servicerabbitmq-service disable - Disable the RabbitMQ servicerabbitmq-service enable - Enable the RabbitMQ service

C:\Windows\System32>rabbitmq-service installD:\Program Files\Erlang OTP\erts-14.2.5.2\bin\erlsrv: Service RabbitMQ added to system.
C:\Windows\System32>rabbitmq-service startRabbitMQ 服务正在启动 .RabbitMQ 服务已经启动成功。
C:\Windows\System32>rabbitmq-plugins enable rabbitmq_managementEnabling plugins on node rabbit@LAPTOP-95QSHN0F:rabbitmq_managementThe following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatchApplying plugin configuration to rabbit@LAPTOP-95QSHN0F...Plugin configuration unchanged.
C:\Windows\System32>rabbitmq-service stopThe RabbitMQ service is stopping.The RabbitMQ service was stopped successfully.

C:\Windows\System32>rabbitmq-service startThe RabbitMQ service is starting.The RabbitMQ service was started successfully.

C:\Windows\System32>
复制代码

登录 web

web 界面成功登录


http://127.0.0.1:15672/
复制代码



用户名:guest密码:guest
复制代码


查看服务状态

C:\Windows\System32>rabbitmqctl statusError: unable to perform an operation on node 'rabbit@LAPTOP-95QSHN0F'. 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@LAPTOP-95QSHN0F * If target node is configured to use long node names, don't forget to use --longnames with CLI tools
DIAGNOSTICS===========
attempted to contact: ['rabbit@LAPTOP-95QSHN0F']
rabbit@LAPTOP-95QSHN0F: * connected to epmd (port 4369) on LAPTOP-95QSHN0F * 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-879-rabbit@LAPTOP-95QSHN0F' * effective user's home directory: c:/Users/admin * Erlang cookie hash: /xMiHS/89iRC4rIO9xsucQ==
复制代码


网页可以登陆了,但是 rabbitmq 服务还没有开启呢!mqtt.fx 也报错,无法连接。

排错之旅

  • 尝试重启服务



C:\Windows\System32>rabbitmq-server
2024-07-20 21:18:59.516000+08:00 [error] <0.153.0>2024-07-20 21:18:59.516000+08:00 [error] <0.153.0> BOOT FAILED2024-07-20 21:18:59.516000+08:00 [error] <0.153.0> ===========2024-07-20 21:18:59.516000+08:00 [error] <0.153.0> ERROR: could not bind to distribution port 25672, it is in use by another node: rabbit@LAPTOP-95QSHN0F2024-07-20 21:18:59.516000+08:00 [error] <0.153.0>BOOT FAILED===========ERROR: could not bind to distribution port 25672, it is in use by another node: rabbit@LAPTOP-95QSHN0F
2024-07-20 21:19:00.535000+08:00 [error] <0.153.0> supervisor: {local,rabbit_prelaunch_sup}2024-07-20 21:19:00.535000+08:00 [error] <0.153.0> errorContext: start_error2024-07-20 21:19:00.535000+08:00 [error] <0.153.0> reason: {dist_port_already_used,25672,"rabbit","LAPTOP-95QSHN0F"}2024-07-20 21:19:00.535000+08:00 [error] <0.153.0> offender: [{pid,undefined},2024-07-20 21:19:00.535000+08:00 [error] <0.153.0> {id,prelaunch},2024-07-20 21:19:00.535000+08:00 [error] <0.153.0> {mfargs,{rabbit_prelaunch,run_prelaunch_first_phase,[]}},2024-07-20 21:19:00.535000+08:00 [error] <0.153.0> {restart_type,transient},2024-07-20 21:19:00.535000+08:00 [error] <0.153.0> {significant,false},2024-07-20 21:19:00.535000+08:00 [error] <0.153.0> {shutdown,5000},2024-07-20 21:19:00.535000+08:00 [error] <0.153.0> {child_type,worker}]2024-07-20 21:19:00.535000+08:00 [error] <0.153.0>2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> crasher:2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> initial call: application_master:init/42024-07-20 21:19:00.535000+08:00 [error] <0.151.0> pid: <0.151.0>2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> registered_name: []2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> exception exit: {{shutdown,2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> {failed_to_start_child,prelaunch,2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> {dist_port_already_used,25672,"rabbit",2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> "LAPTOP-95QSHN0F"}}},2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> {rabbit_prelaunch_app,start,[normal,[]]}}2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> in function application_master:init/4 (application_master.erl, line 142)2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> ancestors: [<0.150.0>]2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> message_queue_len: 12024-07-20 21:19:00.535000+08:00 [error] <0.151.0> messages: [{'EXIT',<0.152.0>,normal}]2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> links: [<0.150.0>,<0.44.0>]2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> dictionary: []2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> trap_exit: true2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> status: running2024-07-20 21:19:00.535000+08:00 [error] <0.151.0> heap_size: 3762024-07-20 21:19:00.535000+08:00 [error] <0.151.0> stack_size: 282024-07-20 21:19:00.535000+08:00 [error] <0.151.0> reductions: 1652024-07-20 21:19:00.535000+08:00 [error] <0.151.0> neighbours:2024-07-20 21:19:00.535000+08:00 [error] <0.151.0>Runtime terminating during boot (terminating)
Crash dump is being written to: erl_crash.dump...done
C:\Windows\System32>rabbitmq-service
*********************Service control usage*********************
rabbitmq-service help - Display this helprabbitmq-service install - Install the RabbitMQ servicerabbitmq-service remove - Remove the RabbitMQ service
The following actions can also be accomplished by usingWindows Services Management Console (services.msc):
rabbitmq-service start - Start the RabbitMQ servicerabbitmq-service stop - Stop the RabbitMQ servicerabbitmq-service disable - Disable the RabbitMQ servicerabbitmq-service enable - Enable the RabbitMQ service

C:\Windows\System32>rabbitmq-service stopThe RabbitMQ service is stopping.The RabbitMQ service was stopped successfully.

C:\Windows\System32>rabbitmq-server2024-07-20 21:19:33.893000+08:00 [notice] <0.44.0> Application syslog exited with reason: stopped2024-07-20 21:19:33.898000+08:00 [notice] <0.251.0> Logging: switching to configured handler(s); following messages may not be visible in this log output
## ## RabbitMQ 3.13.5 ## ## ########## Copyright (c) 2007-2024 Broadcom Inc and/or its subsidiaries ###### ## ########## Licensed under the MPL 2.0. Website: https://rabbitmq.com
Erlang: 26.2.5.2 [jit] TLS Library: OpenSSL - OpenSSL 3.1.0 14 Mar 2023 Release series support status: see https://www.rabbitmq.com/release-information
Doc guides: https://www.rabbitmq.com/docs Support: https://www.rabbitmq.com/docs/contact Tutorials: https://www.rabbitmq.com/tutorials Monitoring: https://www.rabbitmq.com/docs/monitoring Upgrading: https://www.rabbitmq.com/docs/upgrade
Logs: <stdout> c:/Users/admin/AppData/Roaming/RabbitMQ/log/rabbit@LAPTOP-95QSHN0F.log
Config file(s): (none)
Starting broker... completed with 3 plugins.
复制代码


  • 再次查看服务状态


C:\Users\admin>rabbitmqctl statusStatus of node rabbit@LAPTOP-95QSHN0F ...Runtime
OS PID: 30484OS: WindowsUptime (seconds): 292Is under maintenance?: falseRabbitMQ version: 3.13.5RabbitMQ release series support status: see https://www.rabbitmq.com/release-informationNode name: rabbit@LAPTOP-95QSHN0FErlang configuration: Erlang/OTP 26 [erts-14.2.5.2] [source] [64-bit] [smp:20:20] [ds:20:20:10] [async-threads:1] [jit:ns]Crypto library: OpenSSL 3.1.0 14 Mar 2023Erlang processes: 442 used, 1048576 limitScheduler run queue: 1Cluster heartbeat timeout (net_ticktime): 60
Plugins
Enabled plugin file: c:/Users/admin/AppData/Roaming/RabbitMQ/enabled_pluginsEnabled plugins:
* rabbitmq_management * rabbitmq_management_agent * rabbitmq_web_dispatch * amqp_client * cowboy * cowlib * oauth2_client * jose
Data directory
Node data directory: c:/Users/admin/AppData/Roaming/RabbitMQ/db/rabbit@LAPTOP-95QSHN0F-mnesiaRaft data directory: c:/Users/admin/AppData/Roaming/RabbitMQ/db/rabbit@LAPTOP-95QSHN0F-mnesia/quorum/rabbit@LAPTOP-95QSHN0F
Config files

Log file(s)
* <stdout> * c:/Users/admin/AppData/Roaming/RabbitMQ/log/rabbit@LAPTOP-95QSHN0F.log
Alarms
(none)
Memory
Total memory used: 0.1108 gbCalculation strategy: rssMemory high watermark setting: 0.4 of available memory, computed to: 6.7914 gb
code: 0.0406 gb (36.63 %)other_system: 0.0323 gb (29.15 %)other_proc: 0.0209 gb (18.85 %)allocated_unused: 0.0057 gb (5.12 %)reserved_unallocated: 0.0042 gb (3.79 %)metrics: 0.0021 gb (1.86 %)other_ets: 0.0017 gb (1.57 %)atom: 0.0016 gb (1.41 %)plugins: 0.0008 gb (0.71 %)msg_index: 0.0004 gb (0.38 %)metadata_store: 0.0002 gb (0.18 %)mgmt_db: 0.0002 gb (0.14 %)binary: 0.0001 gb (0.07 %)mnesia: 0.0001 gb (0.07 %)metadata_store_ets: 0.0 gb (0.03 %)quorum_ets: 0.0 gb (0.03 %)connection_other: 0.0 gb (0.0 %)quorum_queue_procs: 0.0 gb (0.0 %)quorum_queue_dlx_procs: 0.0 gb (0.0 %)stream_queue_procs: 0.0 gb (0.0 %)stream_queue_replica_reader_procs: 0.0 gb (0.0 %)connection_readers: 0.0 gb (0.0 %)connection_channels: 0.0 gb (0.0 %)queue_procs: 0.0 gb (0.0 %)queue_slave_procs: 0.0 gb (0.0 %)stream_queue_coordinator_procs: 0.0 gb (0.0 %)connection_writers: 0.0 gb (0.0 %)
File Descriptors
Total: 0, limit: 65439Sockets: 0, limit: 58893
Free Disk Space
Low free disk space watermark: 0.05 gbFree disk space: 217.4944 gb
Totals
Connection count: 0Queue count: 0Virtual host count: 1
Listeners
Interface: [::], port: 15672, protocol: http, purpose: HTTP APIInterface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communicationInterface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0Interface: 0.0.0.0, port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
C:\Users\admin>

复制代码

检查端口与服务是否正常开启

  • 通过网页查看和 telnet 测试,发现 1883 端口没开着!

  • 成功定位故障点!



C:\Users\admin>telnet 127.0.0.1 1883正在连接127.0.0.1...无法打开到主机的连接。 在端口 1883: 连接失败
C:\Users\admin>
复制代码

查阅相关资料,了解 rabbitmq-server 特性

  • 当查到默认情况下,rabbitmq-server 是不开启 mqtt 的,需要输入手动开启命令。

  • 此时才修正了文章开头的错误。


C:\Users\admin>rabbitmq-plugins enable rabbitmq_mqttEnabling plugins on node rabbit@LAPTOP-95QSHN0F:rabbitmq_mqttThe following plugins have been configured:  rabbitmq_management  rabbitmq_management_agent  rabbitmq_mqtt  rabbitmq_web_dispatchApplying plugin configuration to rabbit@LAPTOP-95QSHN0F...The following plugins have been enabled:  rabbitmq_mqtt
set 4 plugins.Offline change; changes will take effect at broker restart.
C:\Users\admin>rabbitmq-plugins enable rabbitmq_web_mqttEnabling plugins on node rabbit@LAPTOP-95QSHN0F:rabbitmq_web_mqttThe following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_mqtt rabbitmq_web_dispatch rabbitmq_web_mqttApplying plugin configuration to rabbit@LAPTOP-95QSHN0F...The following plugins have been enabled: rabbitmq_web_mqtt
set 5 plugins.Offline change; changes will take effect at broker restart.
C:\Users\admin>
复制代码

重启 server

C:\Windows\System32>rabbitmq-server2024-07-20 21:56:15.245000+08:00 [notice] <0.44.0> Application syslog exited with reason: stopped2024-07-20 21:56:15.250000+08:00 [notice] <0.251.0> Logging: switching to configured handler(s); following messages may not be visible in this log output
## ## RabbitMQ 3.13.5 ## ## ########## Copyright (c) 2007-2024 Broadcom Inc and/or its subsidiaries ###### ## ########## Licensed under the MPL 2.0. Website: https://rabbitmq.com
Erlang: 26.2.5.2 [jit] TLS Library: OpenSSL - OpenSSL 3.1.0 14 Mar 2023 Release series support status: see https://www.rabbitmq.com/release-information
Doc guides: https://www.rabbitmq.com/docs Support: https://www.rabbitmq.com/docs/contact Tutorials: https://www.rabbitmq.com/tutorials Monitoring: https://www.rabbitmq.com/docs/monitoring Upgrading: https://www.rabbitmq.com/docs/upgrade
Logs: <stdout> c:/Users/admin/AppData/Roaming/RabbitMQ/log/rabbit@LAPTOP-95QSHN0F.log
Config file(s): (none)
Starting broker... completed with 5 plugins.
复制代码

成功


发布于: 刚刚阅读数: 5
用户头像

关注小而美的工业项目。 2021-05-29 加入

关注PLC、HMI、Scada、项目管理、高低压电工和工业自动化。

评论

发布
暂无评论
rabbitmq-server基础 windows安装rabbitmq-server,启用mqtt服务_windows_万里无云万里天_InfoQ写作社区