centos8 安装rabbitmq

centos8 安装rabbitmq

更换阿里云repo

http://mirrors.aliyun.com/repo/

下载

Centos-8.repo

查询最新的mq版本以及对应的erlang信息

参考url
https://www.rabbitmq.com/which-erlang.html

最新版本的mq为 3.8.14 对应的erlang为 23.X

配置yum源

参考 https://www.rabbitmq.com/install-rpm.html#package-cloud

A quick way to install is to use a Package Cloud-provided script. Package Cloud also can be used to install a recent Erlang version via yum.

1 参考 https://packagecloud.io/rabbitmq/rabbitmq-server/install#bash-rpm

curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
# import the new PackageCloud key that will be used starting December 1st, 2018 (GMT)
rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey

# import the old PackageCloud key that will be discontinued on December 1st, 2018 (GMT)
rpm --import https://packagecloud.io/gpg.key
rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc

centos8 建repo文件

cd /etc/yum.repos.d

官网给的示例是

# In /etc/yum.repos.d/rabbitmq.repo

##
## Zero dependency Erlang
##

[rabbitmq_erlang]
name=rabbitmq_erlang
baseurl=https://packagecloud.io/rabbitmq/erlang/el/8/$basearch
repo_gpgcheck=1
gpgcheck=1
enabled=1
# PackageCloud's repository key and RabbitMQ package signing key
gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

[rabbitmq_erlang-source]
name=rabbitmq_erlang-source
baseurl=https://packagecloud.io/rabbitmq/erlang/el/8/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
# PackageCloud's repository key and RabbitMQ package signing key
gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

##
## RabbitMQ server
##

[rabbitmq_server]
name=rabbitmq_server
baseurl=https://packagecloud.io/rabbitmq/rabbitmq-server/el/8/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

[rabbitmq_server-source]
name=rabbitmq_server-source
baseurl=https://packagecloud.io/rabbitmq/rabbitmq-server/el/8/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

因上一步script.rpm.sh自动已经创建了rabbitmq_server的repo文件,所以只需要建个erlang的repo文件就可以

vi rabbitmq_rabbitmq-erlang.repo

[rabbitmq_erlang]
name=rabbitmq_erlang
baseurl=https://packagecloud.io/rabbitmq/erlang/el/8/$basearch
repo_gpgcheck=1
gpgcheck=1
enabled=1
# PackageCloud's repository key and RabbitMQ package signing key
gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

[rabbitmq_erlang-source]
name=rabbitmq_erlang-source
baseurl=https://packagecloud.io/rabbitmq/erlang/el/8/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
# PackageCloud's repository key and RabbitMQ package signing key
gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

安装

yum update -y

rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
如果把repo文件中的repo_gpgcheck设置为0,不校验的话不用上一步导入key
yum install erlang rabbitmq-server -y

启动服务

systemctl start rabbitmq-server

设置开机启动

systemctl enable rabbitmq-server

问题排错

启动失败

提示

[root@192 home]# systemctl status rabbitmq-server
● 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 Thu 2021-04-01 16:14:29 CST; 9s ago
  Process: 41310 ExecStart=/usr/sbin/rabbitmq-server (code=exited, status=1/FAILURE)
 Main PID: 41310 (code=exited, status=1/FAILURE)
[root@192 home]# 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.

查看日志

/var/log/rabbitmq文件夹下为空

/var/log/message中提示信息为

Apr  1 16:15:38 192 systemd[1]: rabbitmq-server.service: Service RestartSec=10s expired, scheduling restart.
Apr  1 16:15:38 192 systemd[1]: rabbitmq-server.service: Scheduled restart job, restart counter is at 13.
Apr  1 16:15:38 192 systemd[1]: Stopped RabbitMQ broker.
Apr  1 16:15:38 192 systemd[1]: Starting RabbitMQ broker...
Apr  1 16:15:40 192 rabbitmq-server[41678]: Configuring logger redirection
Apr  1 16:15:40 192 rabbitmq-server[41678]: 16:15:40.565 [error]
Apr  1 16:15:40 192 rabbitmq-server[41678]: 16:15:40.573 [error] BOOT FAILED
Apr  1 16:15:40 192 rabbitmq-server[41678]: BOOT FAILED
Apr  1 16:15:40 192 rabbitmq-server[41678]: 16:15:40.573 [error] ===========
Apr  1 16:15:40 192 rabbitmq-server[41678]: ===========
Apr  1 16:15:40 192 rabbitmq-server[41678]: 16:15:40.573 [error] ERROR: epmd error for host 192: badarg (unknown POSIX error)
Apr  1 16:15:40 192 rabbitmq-server[41678]: ERROR: epmd error for host 192: badarg (unknown POSIX error)
Apr  1 16:15:40 192 rabbitmq-server[41678]: 16:15:40.573 [error]
Apr  1 16:15:41 192 rabbitmq-server[41678]: 16:15:41.575 [error] Supervisor rabbit_prelaunch_sup had child prelaunch started with rabbit_prelaunch:run_prelaunch_first_phase() at undefined exit with reason {epmd_error,"192",badarg} in context start_error
Apr  1 16:15:41 192 rabbitmq-server[41678]: 16:15:41.575 [error] CRASH REPORT Process <0.152.0> with 0 neighbours exited with reason: {{shutdown,{failed_to_start_child,prelaunch,{epmd_error,"192",badarg}}},{rabbit_prelaunch_app,start,[normal,[]]}} in application_master:init/4 line 138
Apr  1 16:15:43 192 rabbitmq-server[41678]: {"Kernel pid terminated",application_controller,"{application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{epmd_error,\"192\",badarg}}},{rabbit_prelaunch_app,start,[normal,[]]}}}"}
Apr  1 16:15:43 192 rabbitmq-server[41678]: Kernel pid terminated (application_controller) ({application_start_failure,rabbitmq_prelaunch,{{shutdown,{failed_to_start_child,prelaunch,{epmd_error,"192",badarg}}},{rabbit_prelaunch_app,start,[norma
Apr  1 16:15:43 192 rabbitmq-server[41678]: #015
Apr  1 16:15:43 192 rabbitmq-server[41678]: Crash dump is being written to: erl_crash.dump...done
Apr  1 16:15:43 192 systemd[1]: rabbitmq-server.service: Main process exited, code=exited, status=1/FAILURE
Apr  1 16:15:43 192 systemd[1]: rabbitmq-server.service: Failed with result 'exit-code'.
Apr  1 16:15:43 192 systemd[1]: Failed to start RabbitMQ broker.

问题呢定位为主机名问题,原因为linux主机的名称是数字的原因造成此问题的

参考 https://blog.csdn.net/kang_tian/article/details/105719318

修改主机名

hostnamectl set-hostnam mq

修改后启动正常

Apr  1 16:17:49 192 systemd[1]: systemd-hostnamed.service: Succeeded.
Apr  1 16:17:52 192 rabbitmq-server[42198]:  ##  ##      RabbitMQ 3.8.14
Apr  1 16:17:52 192 rabbitmq-server[42198]:  ##  ##
Apr  1 16:17:52 192 rabbitmq-server[42198]:  ##########  Copyright (c) 2007-2021 VMware, Inc. or its affiliates.
Apr  1 16:17:52 192 rabbitmq-server[42198]:  ######  ##
Apr  1 16:17:52 192 rabbitmq-server[42198]:  ##########  Licensed under the MPL 2.0. Website: https://rabbitmq.com
Apr  1 16:17:52 192 rabbitmq-server[42198]:  Doc guides: https://rabbitmq.com/documentation.html
Apr  1 16:17:52 192 rabbitmq-server[42198]:  Support:    https://rabbitmq.com/contact.html
Apr  1 16:17:52 192 rabbitmq-server[42198]:  Tutorials:  https://rabbitmq.com/getstarted.html
Apr  1 16:17:52 192 rabbitmq-server[42198]:  Monitoring: https://rabbitmq.com/monitoring.html
Apr  1 16:17:52 192 rabbitmq-server[42198]:  Logs: /var/log/rabbitmq/rabbit@mq.log
Apr  1 16:17:52 192 rabbitmq-server[42198]:        /var/log/rabbitmq/rabbit@mq_upgrade.log
Apr  1 16:17:52 192 rabbitmq-server[42198]:  Config file(s): (none)
Apr  1 16:18:31 192 rabbitmq-server[42198]:  Starting broker... completed with 0 plugins.
Apr  1 16:18:31 192 systemd[1]: Started RabbitMQ broker.
上一篇:ABC 192 题解


下一篇:AtCoder Beginner Contest 192 F - Potion