使用rabbitmq过程中遇到的问题及解决方法记录。

时间:2021-09-07 10:10:37

OS: Linux ---Centos7
RabbitMQ版本:RabbitMQ version: 3.8.1
erlang版本:Erlang configuration: Erlang/OTP 22 [erts-10.6.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:64] [hipe]
安装方式:使用rpm安装

后台启动方式:

cd /usr/lib/rabbitmq/bin
./rabbitmq-server start &

或者

./rabbitmq-server start -detached
# Warning: PID file not written; -detached was passed.#忽略警告,貌似是rabbitmq bug

问题1:用 rabbitmq-server start &启动报错

[root@lyy bin]# rabbitmq-server start &
[1] 9900
[root@lyy bin]# /usr/lib/rabbitmq/bin/rabbitmq-server:行51: /var/lib/rabbitmq/mnesia/rabbit.pid: 权限不够
Failed to write pid file: /var/lib/rabbitmq/mnesia/rabbit.pid

解决方法:

chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/mnesia/

问题2: rabbitmqctl 用不了

[root@lyy bin]# rabbitmqctl status
Error: unable to perform an operation on node 'rabbit@lyy'. 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@lyy
* If target node is configured to use long node names, don't forget to use --longnames with CLI tools DIAGNOSTICS
=========== attempted to contact: [rabbit@lyy] rabbit@lyy:
* connected to epmd (port 4369) on lyy
* epmd reports node 'rabbit' uses port 25672 for inter-node and CLI tool traffic
* TCP connection succeeded but Erlang distribution failed * Authentication failed (rejected by the remote node), please check the Erlang cookie Current node details:
* node name: 'rabbitmqcli-4109-rabbit@lyy'
* effective user's home directory: /var/lib/rabbitmq
* Erlang cookie hash: 8y/oHO82So4EqWKv6DO9vw==

解决办法:

[root@lyy bin]# vim /var/lib/rabbitmq/.erlang.cookie
[root@lyy rabbitmq]# cd /home
[root@lyy ~]# vim .erlang.cookie

把两个文件中内容改为一致,重启rabbitmq即可