【README】
1、本文基于 centos8 搭建 rabbitmq; 版本信息如下:
rabbitmq rabbitmq-server-3.8.12-1.el8.noarch.rpm
erlang erlang 23.2.5 (erts-11.1.8)
上述两者版本一定要强对应,否则mq启动失败,参见官网 https://rabbitmq.com/which-erlang.html#compatibility-matrix
2、本文旨在po出 报错现场和解决方法;
3、rabbitmq 配置文件 放置在 /etc/rabbitmq/ 下(参考官网 https://rabbitmq.com/configure.html#verify-configuration-config-file-location)
[root@centos201 rabbitmq]# cd /etc/rabbitmq/
[root@centos201 rabbitmq]# ls
enabled_plugins rabbitmq.config
【1】报错现场
[root@centos201 ~]# systemctl start rabbitmq-server
Job for rabbitmq-server.service failed because the control process exited with error code.
See "systemctl status rabbitmq-server.service" and "journalctl -xe" for details.
【2】我们根据提示,执行了 journalctl -xe 查看错误日志
[root@centos201 ~]# journalctl -xe
Feb 28 05:09:31 centos201 systemd[1]: rabbitmq-server.service: Main process exited, code=exited, status=1/FAILURE
Feb 28 05:09:31 centos201 systemd[1]: rabbitmq-server.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- The unit rabbitmq-server.service has entered the 'failed' state with result 'exit-code'.
Feb 28 05:09:31 centos201 systemd[1]: Failed to start RabbitMQ broker.
-- Subject: Unit rabbitmq-server.service has failed
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit rabbitmq-server.service has failed.
--
-- The result is failed.
Feb 28 05:09:41 centos201 systemd[1]: rabbitmq-server.service: Service RestartSec=10s expired, scheduling restart.
Feb 28 05:09:41 centos201 systemd[1]: rabbitmq-server.service: Scheduled restart job, restart counter is at 143.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Automatic restarting of the unit rabbitmq-server.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Feb 28 05:09:41 centos201 systemd[1]: Stopped RabbitMQ broker.
-- Subject: Unit rabbitmq-server.service has finished shutting down
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit rabbitmq-server.service has finished shutting down.
Feb 28 05:09:41 centos201 systemd[1]: Starting RabbitMQ broker...
-- Subject: Unit rabbitmq-server.service has begun start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit rabbitmq-server.service has begun starting up.
Feb 28 05:09:42 centos201 rabbitmq-server[7174]: Configuring logger redirection
Feb 28 05:09:43 centos201 rabbitmq-server[7174]: 05:09:43.660 [error] Failed to load advanced configuration file "/etc/rabbitmq/rabbitmq.config": 1: syntax error before: '=='
Feb 28 05:09:43 centos201 rabbitmq-server[7174]: 05:09:43.670 [error]
注意这句
【3】问题分析
什么叫做 advanced configuration file ? 本文查看了 rabbitmq的官网, 如下: https://rabbitmq.com/configure.html#config-location
rabbit有3个配置文件,分别是 rabbitmq.conf advanced.config rabbitmq-env.conf
那为啥就要读取 advanced.config 呢 ? 明明我们在 /etc/rabbitmq/ 下面 新建了 rabbitmq.config 文件啊 。
rabbitmq.conf 与 advanced.config 文件的区别在于,前者是使用的是类初始语法,可配置大多数设置;
后者使用的是经典语法,配置高级设置的;
但 发现 两者的后缀不一样, 前者是conf, 后者是 config ,但rabbitmq 只认后缀。
所以当我们把 rabbitmq.config 放入 /etc/rabbitmq/ 文件夹时, rabbitmq启动程序就会认为会读取 advanced.config 而不是 rabbitmq.conf。
原因:后缀名错误,应该是 rabbitmq.conf 而不该是 rabbitmq.config ;
【4】解决
把 rabbitmq.config 修改为 rabbitmq.conf 即可 ; 如下
[root@centos201 rabbitmq]# mv rabbitmq.config rabbitmq.conf
[root@centos201 rabbitmq]# systemctl start rabbitmq-server
[root@centos201 rabbitmq]#
[root@centos201 rabbitmq]# systemctl status rabbitmq-server
● rabbitmq-server.service - RabbitMQ broker
Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2021-02-28 07:29:42 CST; 10s ago
Main PID: 27039 (beam.smp)
Status: "Initialized"
Tasks: 23 (limit: 4761)
Memory: 123.3M
CGroup: /system.slice/rabbitmq-server.service
├─27039 /usr/lib64/erlang/erts-11.1.8/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -sbwt none -sbwtdcpu none -sbwtdio none -- -root /usr/>
├─27054 erl_child_setup 32768
├─27102 inet_gethost 4
└─27103 inet_gethost 4
Feb 28 07:29:38 centos201 rabbitmq-server[27039]: ########## Licensed under the MPL 2.0. Website: https://rabbitmq.com
Feb 28 07:29:38 centos201 rabbitmq-server[27039]: Doc guides: https://rabbitmq.com/documentation.html
Feb 28 07:29:38 centos201 rabbitmq-server[27039]: Support: https://rabbitmq.com/contact.html
Feb 28 07:29:38 centos201 rabbitmq-server[27039]: Tutorials: https://rabbitmq.com/getstarted.html
Feb 28 07:29:38 centos201 rabbitmq-server[27039]: Monitoring: https://rabbitmq.com/monitoring.html
Feb 28 07:29:38 centos201 rabbitmq-server[27039]: Logs: /var/log/rabbitmq/rabbit@centos201.log
Feb 28 07:29:38 centos201 rabbitmq-server[27039]: /var/log/rabbitmq/rabbit@centos201_upgrade.log
Feb 28 07:29:38 centos201 rabbitmq-server[27039]: Config file(s): /etc/rabbitmq/rabbitmq.conf
Feb 28 07:29:42 centos201 rabbitmq-server[27039]: Starting broker... completed with 3 plugins.
Feb 28 07:29:42 centos201 systemd[1]: Started RabbitMQ broker.
启动成功。bingo。
【5】访问 rabbitmq 管理ui
访问不不通?
停止防火墙即可。 systemctl stop firewalld.service
bingo! 成功访问。
【6】补充
为什么是 192.168.163.201:15672 ?
首先ip 是我本地机器ip, 端口是设置的 管理UI的端口, 在 rabbitmq.conf 配置即可。 配置策略参见官网 https://rabbitmq.com/management.html#configuration
management.tcp.port = 15672
management.tcp.ip = 192.168.163.201