RabbitMQ 3.9.8 的rpm安装方式

之前采用源码的方式安装erlang,之后再来安装rabbitMQ,这种方式有一些复杂。现在参考官网,可以直接用rpm安装。本文对安装过程进行描述。
官方参考Installing on RPM-based Linux (RedHat Enterprise Linux, CentOS, Fedora, openSUSE)

1.rpm包下载

需要安装的操作系统信息:

[root@m161p114 ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.9.2009 (Core)
Release:    7.9.2009
Codename:   Core
[root@m161p114 ~]# 

本文选择最新版本的RabbitMQ 3.9.8。现在rabbitMQ的下载文件都放在了github。

rabbitmq-server

由于操作系统是centos7,那么选择下载的版本为 rabbitmq-server-3.9.8-1.el7.noarch.rpm.

另外需要下载erlang,参考rabbitMQ和rabbitMQ的兼容关系:
RabbitMQ Erlang Version Requirements

erlang最低版本为23.2,在此选择了23.3.4.8版本。因为这个版本有支持el7的rpm包可下载。
erlang-rpm

下载的版本为:erlang-23.3.4.8-1.el7.x86_64.rpm

现在将这两个rpm上传到需要安装的服务的/opt/software目录。

2.rpm安装

首先要安装依赖包:

[root@m161p114 ~]# yum install -y socat
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * centos-sclo-rh: mirrors.huaweicloud.com
 * centos-sclo-sclo: mirrors.huaweicloud.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                                      | 3.6 kB  00:00:00     
centos-sclo-rh                                                                                                                                                                            | 3.0 kB  00:00:00     
centos-sclo-sclo                                                                                                                                                                          | 3.0 kB  00:00:00     
epel                                                                                                                                                                                      | 4.7 kB  00:00:00     
extras                                                                                                                                                                                    | 2.9 kB  00:00:00     
updates                                                                                                                                                                                   | 2.9 kB  00:00:00     
(1/3): epel/x86_64/updateinfo                                                                                                                                                             | 1.0 MB  00:00:01     
(2/3): epel/x86_64/primary_db                                                                                                                                                             | 7.0 MB  00:00:06     
(3/3): updates/7/x86_64/primary_db                                                                                                                                                        |  12 MB  00:00:08     
Resolving Dependencies
--> Running transaction check
---> Package socat.x86_64 0:1.7.3.2-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================================================================================
 Package                                         Arch                                             Version                                                   Repository                                      Size
=================================================================================================================================================================================================================
Installing:
 socat                                           x86_64                                           1.7.3.2-2.el7                                             base                                           290 k

Transaction Summary
=================================================================================================================================================================================================================
Install  1 Package

Total download size: 290 k
Installed size: 1.1 M
Downloading packages:
socat-1.7.3.2-2.el7.x86_64.rpm                                                                                                                                                            | 290 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : socat-1.7.3.2-2.el7.x86_64                                                                                                                                                                    1/1 
  Verifying  : socat-1.7.3.2-2.el7.x86_64                                                                                                                                                                    1/1 

Installed:
  socat.x86_64 0:1.7.3.2-2.el7                                                                                                                                                                                   

Complete!

erlang安装:

[root@m161p114 software]# cd /opt/software

[root@m161p114 software]# rpm -ivh erlang-23.3.4.8-1.el7.x86_64.rpm 
warning: erlang-23.3.4.8-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID cc4bbe5b: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:erlang-23.3.4.8-1.el7            ################################# [100%]
[root@m161p114 software]# 

安装之后查看版本:

[root@m161p114 software]# erl
Erlang/OTP 23 [erts-11.2.2.7] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Eshell V11.2.2.7  (abort with ^G)

erlang23安装成功。

rabbitMQ安装:

[root@m161p114 software]# rpm -ivh rabbitmq-server-3.9.8-1.el7.noarch.rpm 
warning: rabbitmq-server-3.9.8-1.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 6026dfca: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:rabbitmq-server-3.9.8-1.el7      ################################# [100%]
[root@m161p114 software]# 

3.配置及启动rabbitmq

首先要检查host文件,在hosts文件中确保存在hostname对应的ip解析。
在本文中,增加:

192.168.161.114 m161p114

配置管理后台:

[root@m161p114 ~]# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@m161p114:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@m161p114...
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

set 3 plugins.
Offline change; changes will take effect at broker restart.

之后,启动rabbitmq:

[root@m161p114 opt]# service rabbitmq-server start
Redirecting to /bin/systemctl start rabbitmq-server.service

rabbitmq启动完成。

增加用户:

[root@m161p114 opt]# rabbitmqctl add_user root 123456
Adding user "root" ...
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
[root@m161p114 opt]# rabbitmqctl set_user_tags root administrator
Setting tags for user "root" to [administrator] ...
[root@m161p114 opt]# 

至此,rabbitmq安装完成,可以用新增的用户,访问rabbitMQ:

http://192.168.161.114:15672

RabbitMQ 登陆

这样RabbitMQ就安装完毕,通过service rabbitmq-server 可以对rabbitmq进行启动和关闭。

4.遇到的一些常见的错误

4.1 端口被占用错误

启动报错:


[root@m161p114 ~]# service rabbitmq-server restart
Redirecting to /bin/systemctl restart rabbitmq-server.service
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.
[root@m161p114 ~]# 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.
[root@m161p114 ~]# systemctl 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 Mon 2021-11-01 14:54:05 CST; 9s ago
  Process: 25478 ExecStart=/usr/sbin/rabbitmq-server (code=exited, status=1/FAILURE)
 Main PID: 25478 (code=exited, status=1/FAILURE)
   Status: "Standing by"

Nov 01 14:54:05 m161p114 systemd[1]: Failed to start RabbitMQ broker.
Nov 01 14:54:05 m161p114 systemd[1]: Unit rabbitmq-server.service entered failed state.
Nov 01 14:54:05 m161p114 systemd[1]: rabbitmq-server.service failed.


[root@m161p114 ~]# systemctl 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 Mon 2021-11-01 14:56:45 CST; 1s ago
  Process: 26366 ExecStart=/usr/sbin/rabbitmq-server (code=exited, status=1/FAILURE)
 Main PID: 26366 (code=exited, status=1/FAILURE)
   Status: "Standing by"

Nov 01 14:56:45 m161p114 systemd[1]: Failed to start RabbitMQ broker.
Nov 01 14:56:45 m161p114 systemd[1]: Unit rabbitmq-server.service entered failed state.
Nov 01 14:56:45 m161p114 systemd[1]: rabbitmq-server.service failed.
[root@m161p114 ~]# 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.
[root@m161p114 ~]# journalctl -xe
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {failed_to_start_child,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {ranch_embedded_sup,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {acceptor,{0,0,0,0,0,0,0,0},5672}},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {shutdown,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {failed_to_start_child,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {ranch_listener_sup,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {acceptor,{0,0,0,0,0,0,0,0},5672}},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {shutdown,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {failed_to_start_child,ranch_acceptors_sup,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {listen_error,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {acceptor,{0,0,0,0,0,0,0,0},5672},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: eaddrinuse}}}}}}},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {child,undefined,'rabbit_tcp_listener_sup_:::5672',
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {tcp_listener_sup,start_link,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: [{0,0,0,0,0,0,0,0},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: 5672,ranch_tcp,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: [inet6,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {backlog,128},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {nodelay,true},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {linger,{true,0}},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {exit_on_close,false}],
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: rabbit_connection_sup,[],
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {rabbit_networking,tcp_listener_started,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: [amqp,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: [{backlog,128},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {nodelay,true},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {linger,{true,0}},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {exit_on_close,false}]]},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {rabbit_networking,tcp_listener_stopped,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: [amqp,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: [{backlog,128},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {nodelay,true},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {linger,{true,0}},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: {exit_on_close,false}]]},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: 10,1,"TCP listener"]},
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: transient,infinity,supervisor,
Nov 01 14:57:16 m161p114 rabbitmq-server[26561]: [tcp_listener_sup]}}}}
Nov 01 14:57:17 m161p114 rabbitmq-server[26561]: {"init terminating in do_boot",{error,{could_not_start_listener,"::",5672,{{shutdown,{failed_to_start_child,{ranch_embedded_sup,{acceptor,{0,0,0,0,0,0,0,0},5672
Nov 01 14:57:17 m161p114 rabbitmq-server[26561]: init terminating in do_boot ({error,{could_not_start_listener,::,5672,{{shutdown,{_}},{child,undefined,rabbit_tcp_listener_sup_:::5672,{_},transient,infinity,su

启动rabbitmq,出现上述错误。
实际上这是端口被占用所致。rabbitmq使用的是5672端口。而这个服务器上由于安装过activeMQ,导致5672端口被占用。

[root@m161p114 usr]# netstat -an |grep 5672
tcp        0      0 0.0.0.0:5672            0.0.0.0:*               LISTEN     
[root@m161p114 usr]# lsof -i:5672
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
java    15085 root  139u  IPv4 142285      0t0  TCP *:amqp (LISTEN)
[root@m161p114 usr]# 
[root@m161p114 etc]# ps -aux |grep activemq
root     15085  0.1  5.6 4749504 450096 ?      Sl   Oct28   6:45 /bin/java -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=/opt/apache-activemq-5.16.3//conf/login.config -Dcom.sun.management.jmxremote -Djava.awt.headless=true -Djava.io.tmpdir=/opt/apache-activemq-5.16.3//tmp -Dactivemq.classpath=/opt/apache-activemq-5.16.3//conf:/opt/apache-activemq-5.16.3//../lib/: -Dactivemq.home=/opt/apache-activemq-5.16.3/ -Dactivemq.base=/opt/apache-activemq-5.16.3/ -Dactivemq.conf=/opt/apache-activemq-5.16.3//conf -Dactivemq.data=/opt/apache-activemq-5.16.3//data -jar /opt/apache-activemq-5.16.3//bin/activemq.jar start
root     32118  0.0  0.0 112820   944 pts/0    S+   15:14   0:00 grep --color=auto activemq
[root@m161p114 etc]# 

可以看到,5672被activeMQ占用。虽然activeMQ使用的是61616端口,但是amqp服务还是会占用5672端口。
我们只需要关闭activeMQ,然后重启rabbitMQ即可。

4.2 增加用户报错

增加rabbitMQ 用户的过程中,出现如下错误:

[root@m161p114 etc]# rabbitmqctl add_user root 123456
Error: unable to perform an operation on node 'rabbit@m161p114'. 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@m161p114
 * If target node is configured to use long node names, don't forget to use --longnames with CLI tools

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

attempted to contact: [rabbit@m161p114]

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

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

[root@m161p114 etc]# 

这需要将rabbitMQ server启动。否则将会出现上述错误。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,222评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,455评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,720评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,568评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,696评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,879评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,028评论 3 409
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,773评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,220评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,550评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,697评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,360评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,002评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,782评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,010评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,433评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,587评论 2 350

推荐阅读更多精彩内容