CentOS7.5 安装rabbitmq采坑

前言

业务中使用到了celery,redis用作消息代理时,断点等情况可能会产生数据丢失,企业级的消息代理,自然想到了rabbitmq。原本ubuntu中只需要一两行命令就可以安装的rabbitmq-server,却在centos中遇到了不少坑。

官网安装

一开始到官网安装rabbitmq,由于官方源的302问题,所以寻找其他的安装步骤。

手动安装

[linux]CentOS 7 下安装 RabbitMQ这里找到一些步骤,看到rabbitmq的版本也比较新(flag狂立),然后就采用了文中的步骤安装。但是所有的安装成功之后发现启动不了。

[root@xlj ~]# rabbitmqctl status
Status of node rabbit@xlj ...
Error: unable to connect to node rabbit@xlj: nodedown

DIAGNOSTICS
===========

attempted to contact: [rabbit@xlj]

rabbit@xlj:
  * connected to epmd (port 4369) on xlj
  * epmd reports: node 'rabbit' not running at all
                  no other nodes on xlj
  * suggestion: start the node

current node details:
- node name: 'rabbitmq-cli-18@xlj'
- home dir: /var/lib/rabbitmq
- cookie hash: 092AOKFm9rigsKLaoyXi4g==
[root@xlj ~]# systemctl stop rabbitmq-server
[root@xlj ~]# systemctl status rabbitmq-server
● rabbitmq-server.service - LSB: Enable AMQP service provided by RabbitMQ broker
   Loaded: loaded (/etc/rc.d/init.d/rabbitmq-server; bad; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)

12月 20 11:03:52 xlj su[28224]: (to rabbitmq) root on none
12月 20 11:03:52 xlj su[28225]: (to rabbitmq) root on none
12月 20 11:03:54 xlj rabbitmq-server[27988]: Starting rabbitmq-server: SUCCESS
12月 20 11:03:54 xlj rabbitmq-server[27988]: rabbitmq-server.
12月 20 11:03:54 xlj systemd[1]: Started LSB: Enable AMQP service provided by RabbitMQ broker.
12月 20 13:19:40 xlj systemd[1]: Stopping LSB: Enable AMQP service provided by RabbitMQ broker...
12月 20 13:19:40 xlj su[4152]: (to rabbitmq) root on none
12月 20 13:19:40 xlj systemd[1]: Stopped LSB: Enable AMQP service provided by RabbitMQ broker.
12月 20 13:19:40 xlj rabbitmq-server[4070]: Stopping rabbitmq-server: RabbitMQ is not running
12月 20 13:19:40 xlj rabbitmq-server[4070]: rabbitmq-server.
Hint: Some lines were ellipsized, use -l to show in full.

log中返回

{"init terminating in do_boot",noproc}
[FAILED]

谷歌搜索之,找到了一个邮件组里提到过这个问题、
rabbitmq-server start fail

21 is only supported starting with 3.7.7; for 3.6.15 you have to stay with 20.x.
RTFM. :-)

查看了一下erl的版本,发现自己是21.0,可能是这个原因引起的。
于是查找官网下载了一个3.7.9的rabbitmq。这个原因和人家写的帖子也没关系,因为在当时的帖子中使用yum install erlang安装的版本是18。

换了rabbitmq的版本,启动了服务现在可以正常启动了。

root@xlj component]# systemctl status rabbitmq-server
● rabbitmq-server.service - RabbitMQ broker
   Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; disabled; vendor preset: disabled)
   Active: active (running) since 四 2018-12-20 13:52:48 CST; 47min ago
  Process: 9278 ExecStop=/usr/sbin/rabbitmqctl shutdown (code=exited, status=0/SUCCESS)
 Main PID: 9405 (beam.smp)
   Status: "Initialized"
   CGroup: /system.slice/rabbitmq-server.service
           ├─9405 /usr/lib64/erlang/erts-10.1/bin/beam.smp -W w -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -K true -- -ro...
           ├─9747 erl_child_setup 32768
           ├─9772 inet_gethost 4
           └─9773 inet_gethost 4

12月 20 13:52:47 xlj rabbitmq-server[9405]: ##  ##
12月 20 13:52:47 xlj rabbitmq-server[9405]: ##  ##      RabbitMQ 3.7.9. Copyright (C) 2007-2018 Pivotal Software, Inc.
12月 20 13:52:47 xlj rabbitmq-server[9405]: ##########  Licensed under the MPL.  See http://www.rabbitmq.com/
12月 20 13:52:47 xlj rabbitmq-server[9405]: ######  ##
12月 20 13:52:47 xlj rabbitmq-server[9405]: ##########  Logs: /var/log/rabbitmq/[email protected]
12月 20 13:52:47 xlj rabbitmq-server[9405]: /var/log/rabbitmq/rabbit@xlj_upgrade.log
12月 20 13:52:47 xlj rabbitmq-server[9405]: Starting broker...
12月 20 13:52:48 xlj rabbitmq-server[9405]: systemd unit for activation check: "rabbitmq-server.service"
12月 20 13:52:48 xlj systemd[1]: Started RabbitMQ broker.
12月 20 13:52:49 xlj rabbitmq-server[9405]: completed with 3 plugins.

安装完后后台管理页面功能也可以开启了

[root@xlj component]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@xlj...
Plugin configuration unchanged.

但是页面通过:15672还是没法访问。这里尝试了很多命令来定位问题。
在本地使用telnet访问端口

telnet  15672

在服务器上使用curl,看到了页面内容,说明rabbitmq的后台已经启动

curl http://localhost:15672

检查防火墙设置,没有开启。

[root@xlj ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

12月 20 17:43:07 xlj systemd[1]: Starting firewalld - dynamic firewall daemon...
12月 20 17:43:07 xlj systemd[1]: Started firewalld - dynamic firewall daemon.
12月 20 17:44:02 xlj firewalld[7323]: WARNING: ALREADY_ENABLED: 80:tcp
12月 20 17:50:52 xlj systemd[1]: Stopping firewalld - dynamic firewall daemon...
12月 20 17:50:52 xlj systemd[1]: Stopped firewalld - dynamic firewall daemon.

这时对比了其他的一些服务,服务器上有个8200的接口服务,也是和这个一样的问题,无法通过端口来直接访问,而通过Nginx作一下反向代理就可以。
所以也尝试了一下将15672端口也反向代理一下,但是没有成功,查了相关资料好像是rabbitmq只支持apache,不支持Nginx。
这里分析的时候就发现不是rabbitmq的问题了,因为用的阿里云,所以登上阿里云看一下配置,结果发现了安全组,细想一下,问题应该是出在这里了。添加了一个安全规则,开放了15672端口,刷新页面,熟悉的小兔子出现了。
如果你和我一样使用的阿里云,这里记得要点添加安全组规则

屏幕快照 2018-12-21 下午3.33.13.png

这里留个坑,后来用supervisor配置在另一台CentOS7.6的服务器上,然后通过systemctl start rabbitmq-server可以启动,然后使用supervisor就启动不了。

rabbit@test06:
  * connected to epmd (port 4369) on test06
  * epmd reports node 'rabbit' uses port 25672 for inter-node and CLI tool traffic
  * TCP connection succeeded but Erlang distribution failed

  * Hostname mismatch: node "rabbit@izwz97of7rglk0huzajw6nz" believes its host is different. Please ensure that hostnames resolve the same way locally and on "rabbit@izwz97of7rglk0huzajw6nz"


Current node details:
 * node name: 'rabbitmqcli-18529-rabbit@test06'
 * effective user's home directory: /var/lib/rabbitmq
 * Erlang cookie hash: EZ8JXA8SuquW0bMwhaUZdQ==

supervisot是使用/usr/sbin/rabbitmq-server命令启动的。

下面总结一下rabbitmq的正常安装流程

安装相关依赖

yum update
yum install epel-release
yum install gcc gcc-c++ glibc-devel make ncurses-devel openssl-devel autoconf java-1.8.0-openjdk-devel git wget wxBase.x86_64

安装ErLang

wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
yum update
yum install erlang

输入erl检查一下是否安装成功

安装 Elixir

使用源码安装

git clone https://github.com/elixir-lang/elixir.git
cd elixir/
make clean test
export PATH="$PATH://elixir/bin"  # 这里path需要替换成自己的

输入iex判断是否安装成功

安装 RabbitMq

wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.9/rabbitmq-server-3.7.9-1.el7.noarch.rpm
rpm --import https://www.rabbitmq.com/rabbitmq-signing-key-public.asc
yum install rabbitmq-server-3.7.9-1.el7.noarch.rpm

启动服务试一下

systemctl start rabbitmq-server

这里又使用了supervisor启动。

[program:rabbitmq]
command=/usr/sbin/rabbitmq-server
directory=%(ENV_HOME)s/puma
user=root
autostart=true
redirect_stderr=true
stdout_logfile=/var/log/puma/rabbitmq.log
stderr_logfile=/var/log/puma/rabbitmq.err

整个rabbitmq服务就搭建好了。
后来在测试服务器使用supervisor启动的时候报了一个错误。

ERROR: epmd error for host izwz97of7rglk0huzajw6nz: nxdomain (non-existing domain)

查找一下/etc/hostname然后加到/etc/hosts中就好了

127.0.0.1   izwz97of7rglk0huzajw6nz

参考相关:

  • https://www.unixmen.com/install-rabbitmq-server-centos-7/
  • https://www.unixmen.com/install-erlang-elixir-centos-7/

你可能感兴趣的:(CentOS7.5 安装rabbitmq采坑)