Skip to main content
 首页 » 数据库

在centos7中安装rabbitMQ

2022年07月18日48thcjp

参考地址: 

https://www.linuxidc.com/Linux/2018-01/150600.htm

https://blog.csdn.net/summerhust/article/details/7201298

遇到的问题:

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" f

stemctl status rabbitmq-server.service 
● rabbitmq-server.service - RabbitMQ broker 
   Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; disabled; vendor preset: disabled) 
   Active: activating (auto-restart) (Result: exit-code) since Tue 2018-03-20 16:40:20 CST; 3s ago Process: 27573 ExecStop=/usr/sbin/rabbitmqctl shutdown (code=exited, status=78) Process: 27390 ExecStart=/usr/sbin/rabbitmq-server (code=exited, status=1/FAILURE) Main PID: 27390 (code=exited, status=1/FAILURE) Mar 20 16:40:20 vdevops systemd[1]: Failed to start RabbitMQ broker. Mar 20 16:40:20 vdevops systemd[1]: Unit rabbitmq-server.service entered failed state. Mar 20 16:40:20 vdevops systemd[1]: rabbitmq-server.service failed. 

查看具体错误

journalctl -xe 
Mar 20 16:43:36 vdevops rabbitmq-server[1578]: links: [<0.46.0>] Mar 20 16:43:36 vdevops rabbitmq-server[1578]: dictionary: [] Mar 20 16:43:36 vdevops rabbitmq-server[1578]: trap_exit: true Mar 20 16:43:36 vdevops rabbitmq-server[1578]: status: running Mar 20 16:43:36 vdevops rabbitmq-server[1578]: heap_size: 610 Mar 20 16:43:36 vdevops rabbitmq-server[1578]: stack_size: 27 Mar 20 16:43:36 vdevops rabbitmq-server[1578]: reductions: 954 Mar 20 16:43:36 vdevops rabbitmq-server[1578]: 2018-03-20 16:43:36 supervisor_report Mar 20 16:43:36 vdevops rabbitmq-server[1578]: supervisor: {local,net_sup} Mar 20 16:43:36 vdevops rabbitmq-server[1578]: errorContext: start_error Mar 20 16:43:36 vdevops rabbitmq-server[1578]: reason: {"Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces",[{auth,init_cookie,0,[{file,"auth.erl"},{li Mar 20 16:43:36 vdevops rabbitmq-server[1578]: offender: [{pid,undefined},{id,auth},{mfargs,{auth,start_link,[]}},{restart_type,permanent},{shutdown,2000},{child Mar 20 16:43:36 vdevops rabbitmq-server[1578]: 2018-03-20 16:43:36 supervisor_report Mar 20 16:43:36 vdevops rabbitmq-server[1578]: supervisor: {local,kernel_sup} Mar 20 16:43:36 vdevops rabbitmq-server[1578]: errorContext: start_error Mar 20 16:43:36 vdevops rabbitmq-server[1578]: reason: {shutdown,{failed_to_start_child,auth,{"Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces",[{aut Mar 20 16:43:36 vdevops rabbitmq-server[1578]: offender: [{pid,undefined},{id,net_sup},{mfargs,{erl_distribution,start_link,[]}},{restart_type,permanent},{shutdo Mar 20 16:43:36 vdevops rabbitmq-server[1578]: 2018-03-20 16:43:36 crash_report Mar 20 16:43:36 vdevops rabbitmq-server[1578]: initial_call: {application_master,init,['Argument__1','Argument__2','Argument__3','Argument__4']} Mar 20 16:43:36 vdevops rabbitmq-server[1578]: pid: <0.35.0> Mar 20 16:43:36 vdevops rabbitmq-server[1578]: registered_name: [] Mar 20 16:43:36 vdevops rabbitmq-server[1578]: error_info: {exit,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{"Error when rea Mar 20 16:43:36 vdevops rabbitmq-server[1578]: ancestors: [<0.34.0>] Mar 20 16:43:36 vdevops rabbitmq-server[1578]: message_queue_len: 1 Mar 20 16:43:36 vdevops rabbitmq-server[1578]: messages: [{'EXIT',<0.36.0>,normal}] Mar 20 16:43:36 vdevops rabbitmq-server[1578]: links: [<0.34.0>,<0.33.0>] Mar 20 16:43:36 vdevops rabbitmq-server[1578]: dictionary: [] Mar 20 16:43:36 vdevops rabbitmq-server[1578]: trap_exit: true Mar 20 16:43:36 vdevops rabbitmq-server[1578]: status: running Mar 20 16:43:36 vdevops rabbitmq-server[1578]: heap_size: 987 Mar 20 16:43:36 vdevops rabbitmq-server[1578]: stack_size: 27 Mar 20 16:43:36 vdevops rabbitmq-server[1578]: reductions: 250 Mar 20 16:43:36 vdevops rabbitmq-server[1578]: 2018-03-20 16:43:36 std_info Mar 20 16:43:36 vdevops rabbitmq-server[1578]: application: kernel Mar 20 16:43:36 vdevops rabbitmq-server[1578]: exited: {{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{"Error when reading /var/ Mar 20 16:43:36 vdevops rabbitmq-server[1578]: type: permanent Mar 20 16:43:37 vdevops rabbitmq-server[1578]: {"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{{shutdown,{failed_to_start_chi Mar 20 16:43:37 vdevops rabbitmq-server[1578]: Kernel pid terminated (application_controller) ({application_start_failure,kernel,{{shutdown,{failed_to_start_chil Mar 20 16:43:37 vdevops rabbitmq-server[1578]: Crash dump is being written to: /var/log/rabbitmq/erl_crash.dump...done Mar 20 16:43:37 vdevops systemd[1]: rabbitmq-server.service: main process exited, code=exited, status=1/FAILURE Mar 20 16:43:37 vdevops rabbitmqctl[1761]: 16:43:37.884 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces Mar 20 16:43:38 vdevops rabbitmqctl[1761]: 16:43:38.769 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces Mar 20 16:43:38 vdevops rabbitmqctl[1761]: 16:43:38.770 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces Mar 20 16:43:39 vdevops rabbitmqctl[1761]: 16:43:39.659 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces Mar 20 16:43:39 vdevops rabbitmqctl[1761]: 16:43:39.660 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces Mar 20 16:43:40 vdevops rabbitmqctl[1761]: 16:43:40.553 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces Mar 20 16:43:40 vdevops rabbitmqctl[1761]: 16:43:40.554 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces Mar 20 16:43:41 vdevops rabbitmqctl[1761]: 16:43:41.450 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces Mar 20 16:43:41 vdevops rabbitmqctl[1761]: 16:43:41.450 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces Mar 20 16:43:42 vdevops rabbitmqctl[1761]: 16:43:42.347 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces Mar 20 16:43:42 vdevops rabbitmqctl[1761]: 16:43:42.347 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces Mar 20 16:43:43 vdevops rabbitmqctl[1761]: 16:43:43.241 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces Mar 20 16:43:43 vdevops rabbitmqctl[1761]: 16:43:43.242 [error] Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces 

错误日志显示访问问题,查询资料可能是权限问题。

chmod +x .erlang.cookie 重复上诉操作,错误改为:

Mar 20 16:54:59 vdevops rabbitmqctl[22540]: 16:54:59.815 [error] Cookie file /var/lib/rabbitmq/.erlang.cookie must be accessible by owner only Mar 20 16:54:59 vdevops rabbitmqctl[22540]: 16:54:59.815 [error] Cookie file /var/lib/rabbitmq/.erlang.cookie must be accessible by owner only Mar 20 16:55:00 vdevops rabbitmqctl[22540]: 16:55:00.721 [error] Cookie file /var/lib/rabbitmq/.erlang.cookie must be accessible by owner only Mar 20 16:55:00 vdevops rabbitmqctl[22540]: 16:55:00.722 [error] Cookie file /var/lib/rabbitmq/.erlang.cookie must be accessible by owner only Mar 20 16:55:01 vdevops rabbitmqctl[22540]: 16:55:01.632 [error] Cookie file /var/lib/rabbitmq/.erlang.cookie must be accessible by owner only Mar 20 16:55:01 vdevops rabbitmqctl[22540]: Distribution failed: {{:shutdown, {:failed_to_start_child, :auth, {'Cookie file /var/lib/rabbitmq/.erlang.cookie mus Mar 20 16:55:01 vdevops systemd[1]: rabbitmq-server.service: control process exited, code=exited status=78 Mar 20 16:55:01 vdevops systemd[1]: Failed to start RabbitMQ broker. -- Subject: Unit rabbitmq-server.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel 

修改权限

chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie chmod 400 .erlang.cookie 

再次运行,成功。

系统环境

操作系统:CentOS6.9

erlang:OTP 19.3

rabbitmq:rabbitmq-server 3.6.12

安装步骤

安装erlang

1,安装预环境

通过yum安装以下组件,运行命令:

[root@rabbitmqserver erlang]# yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel

2,下载erlang的源代码文件并解压缩

clipboard

运行如下命令解压。

[root@rabbitmqserver softwares]# tar -xvf otp_src_19.3.tar.gz

然后,运行如下命令重命名文件夹为erlang。

[root@rabbitmqserver softwares]# mv otp_src_19.3 ./erlang

clipboard

3,配置安装

首先是./configure,检查编译环境并配置安装路径,运行如下命令:

[root@rabbitmqserver erlang]# ./configure --prefix=/usr/erlang --without-javac

然后,make,对源代码进行编译,运行如下命令:

[root@rabbitmqserver erlang]# make

最后,make install,开始安装,运行如下命令:

[root@rabbitmqserver erlang]# make install

4,设置环境变量

运行以下命令编辑/etc/profile文件。

[root@rabbitmqserver erlang]# vim /etc/profile

在末尾追加以下内容。

clipboard

保存,然后运行以下命令使环境变量立即生效。

[root@rabbitmqserver erlang]# source /etc/profile

5,验证是否安装成功

运行如下命令,验证erlang是否安装成功。

[root@rabbitmqserver erlang]# erl

clipboard

 

安装rabbitmq-server

1,下载rpm包并安装

运行如下命令开始安装rpm包。

[root@rabbitmqserver softwares]# rpm -ivh rabbitmq-server-3.6.12-1.el6.noarch.rpm

可能碰到以下问题:

clipboard

解决办法:

http://blog.csdn.net/yunfeng482/article/details/72853983

2,设置环境变量

运行以下命令编辑/etc/profile文件。

[root@rabbitmqserver softwares]# vim /etc/profile

在末尾追加以下内容。

clipboard

保存,然后运行以下命令使环境变量立即生效。

[root@rabbitmqserver erlang]# source /etc/profile

3,开启Web监控

首先,运行以下命令,开启rabbitmq

[root@rabbitmqserver rabbitmq]# rabbitmq-server

clipboard

ctrl+c取消进程后,运行以下命令,开启web监控。

[root@rabbitmqserver rabbitmq]# rabbitmq-plugins enable rabbitmq_management

clipboard

4,启动

开启web监控之后,我们就可以正式启动rabbitmq了。

启动rabbitmq有以下两种方法。

第一种方法是,直接运行rabbitmq-server命令。

clipboard

但是这种方式,一旦终端退出后,rabbitmq服务就停止了,所以不推荐这么做。

第二种方法是,运行service rabbitmq-server xxx命令。

service rabbitmq-server start #启动

service rabbitmq-server stop #停止

service rabbitmq-server restart #重启

service rabbitmq-server status #查看状态

service rabbitmq-server etc #查看有哪些命令可以使用

同时将rabbitmq-server加入到开机自启动服务中,运行以下命令:

[root@rabbitmqserver bin]# chkconfig rabbitmq-server on

最佳实践是第二种方法。

 


本文参考链接:https://www.cnblogs.com/maohuidong/p/9503321.html