当前位置:   article > 正文

centos系统下RabbitMQ安装教程_centos安装rabbitmq

centos安装rabbitmq

centos系统下RabbitMQ安装教程
我这里的环境用的腾讯云的轻应用环境

RabbitMQ是一个开源的遵循AMQP协议实现的基于Erlang语言编写,即需要先安装部署Erlang环境再安装RabbitMQ环境。需加注意的是,读者若不想跟着我的版本号下载安装,可根据两者版本号的对应表进行下载,安装相应版本的Erlang和RabbitMQ,只需在下文修改命令里面的版本号即可,如下:
一 Erlang下载安装
在确定了RabbitMQ版本号后,先下载安装Erlang环境。
相关网站

https://packagecloud.io/rabbitmq/rabbitmq-server
  • 1
wget --content-disposition https://packagecloud.io/rabbitmq/erlang/packages/el/7/erlang-22.3.4.12-1.el7.x86_64.rpm/download.rpm
  • 1
[root@VM-8-17-centos new]# wget --content-disposition https://packagecloud.io/rabbitmq/rabbitmq-server/packages/el/7/rabbitmq-server-3.8.13-1.el7.noarch.rpm/download.rpm
--2022-11-27 22:54:52--  https://packagecloud.io/rabbitmq/rabbitmq-server/packages/el/7/rabbitmq-server-3.8.13-1.el7.noarch.rpm/download.rpm
Resolving packagecloud.io (packagecloud.io)... 52.52.36.226, 54.183.55.100, 2600:1f1c:2e5:6900:6ede:11a0:5db3:4dfb, ...
Connecting to packagecloud.io (packagecloud.io)|52.52.36.226|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://d28dx6y1hfq314.cloudfront.net/828/1033/el/7/package_files/1305009.rpm?t=1669561193_b7657897acf0012634d1db181f00c0b527f201b8 [following]
--2022-11-27 22:54:53--  https://d28dx6y1hfq314.cloudfront.net/828/1033/el/7/package_files/1305009.rpm?t=1669561193_b7657897acf0012634d1db181f00c0b527f201b8
Resolving d28dx6y1hfq314.cloudfront.net (d28dx6y1hfq314.cloudfront.net)... 13.225.95.31, 13.225.95.224, 13.225.95.111, ...
Connecting to d28dx6y1hfq314.cloudfront.net (d28dx6y1hfq314.cloudfront.net)|13.225.95.31|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 15836454 (15M) [application/x-rpm]
Saving to: ‘rabbitmq-server-3.8.13-1.el7.noarch.rpm’

100%[============================================================================================>] 15,836,454  13.5MB/s   in 1.1s   

2022-11-27 22:54:55 (13.5 MB/s) - ‘rabbitmq-server-3.8.13-1.el7.noarch.rpm’ saved [15836454/15836454]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

接着,安装已下载的rpm包

yum localinstall erlang-22.3.4.12-1.el7.x86_64.rpm

[root@VM-8-17-centos new]# yum localinstall erlang-22.3.4.12-1.el7.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Examining erlang-22.3.4.12-1.el7.x86_64.rpm: erlang-22.3.4.12-1.el7.x86_64
Marking erlang-22.3.4.12-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package erlang.x86_64 0:22.3.4.12-1.el7 will be installed
--> Finished Dependency Resolution
rabbitmq_erlang/x86_64/signature                                                                               |  833 B  00:00:00     
rabbitmq_erlang/x86_64/signature                                                                               | 1.8 kB  00:00:00 !!! 
rabbitmq_erlang-source/signature                                                                               |  819 B  00:00:00     
rabbitmq_erlang-source/signature                                                                               |  951 B  00:00:00 !!! 

Dependencies Resolved

======================================================================================================================================
 Package                Arch                   Version                           Repository                                      Size
======================================================================================================================================
Installing:
 erlang                 x86_64                 22.3.4.12-1.el7                   /erlang-22.3.4.12-1.el7.x86_64                  34 M

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

Total size: 34 M
Installed size: 34 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : erlang-22.3.4.12-1.el7.x86_64                                                                                      1/1 
  Verifying  : erlang-22.3.4.12-1.el7.x86_64                                                                                      1/1 

Installed:
  erlang.x86_64 0:22.3.4.12-1.el7                                                                                                     

Complete!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

二 RabbitMQ下载安装
下面依旧通过wget命令完成RabbitMQ的下载。

wget --content-disposition https://packagecloud.io/rabbitmq/rabbitmq-server/packages/el/7/rabbitmq-server-3.8.13-1.el7.noarch.rpm/download.rpm
  • 1

当你下载完成后,你需要运行下面的命令来将 Key 导入,执行命令:

rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
  • 1

yum安装

yum localinstall rabbitmq-server-3.8.13-1.el7.noarch.rpm
[root@VM-8-17-centos new]# rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
[root@VM-8-17-centos new]# yum localinstall rabbitmq-server-3.8.13-1.el7.noarch.rpm
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Examining rabbitmq-server-3.8.13-1.el7.noarch.rpm: rabbitmq-server-3.8.13-1.el7.noarch
Marking rabbitmq-server-3.8.13-1.el7.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package rabbitmq-server.noarch 0:3.8.13-1.el7 will be installed
--> Processing Dependency: socat for package: rabbitmq-server-3.8.13-1.el7.noarch
Loading mirror speeds from cached hostfile
 * centos-sclo-rh: mirrors.bupt.edu.cn
--> 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:
 rabbitmq-server              noarch              3.8.13-1.el7                /rabbitmq-server-3.8.13-1.el7.noarch               16 M
Installing for dependencies:
 socat                        x86_64              1.7.3.2-2.el7               os                                                290 k

Transaction Summary
======================================================================================================================================
Install  1 Package (+1 Dependent package)

Total size: 16 M
Total download size: 290 k
Installed size: 17 M
Is this ok [y/d/N]: y
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
  Installing : socat-1.7.3.2-2.el7.x86_64                                                                                         1/2 
  Installing : rabbitmq-server-3.8.13-1.el7.noarch                                                                                2/2 
  Verifying  : rabbitmq-server-3.8.13-1.el7.noarch                                                                                1/2 
  Verifying  : socat-1.7.3.2-2.el7.x86_64                                                                                         2/2 

Installed:
  rabbitmq-server.noarch 0:3.8.13-1.el7                                                                                               

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

Complete!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53

如此RabbitMQ安装成功就安装成功了,安装完成后,需要启动 rabbitmq 服务器,执行命令:

systemctl start rabbitmq-server
  • 1

设置开机自动启动,执行命令:

systemctl enable rabbitmq-server
  • 1

在目录下启动的命令

/sbin/service rabbitmq-server start  #启动

/sbin/service rabbitmq-server status #状态

/sbin/service rabbitmq-server stop #停止
  • 1
  • 2
  • 3
  • 4
  • 5

三 RabbitMQ Web界面管理
默认情况下,是没有安装web端的客户端插件,需要安装才可以生效 。执行命令:

[root@VM-8-17-centos new]# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@VM-8-17-centos:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@VM-8-17-centos...
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.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

安装完毕以后,重启服务即可,执行命令:

[root@VM-8-17-centos new]# systemctl restart rabbitmq-server
  • 1

注意,请在服务器上开放 15672 端口

firewall-cmd --zone=public --add-port=15672/tcp --permanent

systemctl restart firewalld
  • 1
  • 2
  • 3

新增用户。

[root@VM-8-17-centos new]# rabbitmqctl add_user admin 123456
Adding user "admin" ...
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
  • 1
  • 2
  • 3

设置用户分配操作权限。

[root@VM-8-17-centos new]# rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...
  • 1
  • 2

设置 vhost的用户权限

[root@VM-8-17-centos new]# rabbitmqctl set_permissions -p / admin ".*" ".*" ".*" 
Setting permissions for user "admin" in vhost "/" ...
  • 1
  • 2

最后就可以输入IP:15672登录web界面了

在这里插入图片描述
总结使用rpm包安装方式是最快捷的一种方式,不过还有源码安装方式,
但是比如 :erlang环境
wget http://www.erlang.org/download/otp_src_24.0.tar.gz,下载慢如蜗牛
顺便贴下过程,我这里使用otp_src_21.1.tar.gz演示

(1)安装erlang所需要的依赖
1 运行以下命令,安装erlang所需要的依赖

yum install -y make gcc gcc-c++ m4 openssl openssl-devel ncurses-devel unixODBC unixODBC-devel java java-devel
  • 1

2 运行以下命令,下载erlang安装包

wget http://erlang.org/download/otp_src_21.1.tar.gz
  • 1

3 运行以下命令,解压erlang安装包

tar -zxvf otp_src_21.1.tar.gz
  • 1

4 运行以下命令,进入erlang安装包的解压路径,并为erlang创建一个新的目录

cd otp_src_21.1
mkdir -p /usr/local/erlang
  • 1
  • 2

5 依次运行以下命令,编译并安装erlang

./configure --prefix=/usr/local/erlang
make && make install
  • 1
  • 2

6 安装完成后,运行以下命令,为erlang配置环境变量

echo 'export PATH=$PATH:/usr/local/erlang/bin' >> /etc/profile
  • 1

7 运行以下命令,使环境变量立即生效

source /etc/profile
  • 1

8 运行以下命令,返回系统的/root目录,然后查看erlang版本,确认是否安装成功

cd
erl -version
  • 1
  • 2

(2)下载并安装RabbitMQ
RabbitMQ对Erlang的版本具有一定限制,更多信息,请参见RabbitMQ Erlang Version Requirements。本示例使用的Erlang为21.1版本,因此选择下载RabbitMQ 3.7.8版本

1、运行以下命令,下载RabbitMQ安装包

wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.8/rabbitmq-server-generic-unix-3.7.8.tar.xz
  • 1

2、运行以下命令,解压RabbitMQ安装包

tar -xvf rabbitmq-server-generic-unix-3.7.8.tar.xz
  • 1

3、解压完成后,运行以下命令,为RabbitMQ配置环境变量

echo 'export PATH=$PATH:/root/rabbitmq_server-3.7.8/sbin' >> /etc/profile
  • 1

4、运行以下命令,使环境变量立即生效

source /etc/profile
  • 1

(3)配置RabbitMQ。
1、运行以下命令,启动RabbitMQ并后台运行

rabbitmq-server -detached
  • 1

注意 该命令只在当前运行的系统环境下启动RabbitMQ,一旦服务器重启,RabbitMQ服务将不会自动启动。因此,建议您通过阿里云的云助手功能,设置RabbitMQ开机自启动。具体操作,请参见通过云助手设置RabbitMQ开机自启动。

2、运行以下命令,启动RabbitMQ监控插件。

rabbitmq-plugins enable rabbitmq_management
  • 1

如果您需要关闭RabbitMQ监控插件,可以运行
rabbitmq-plugins disable rabbitmq_management命令。

3、为保证数据安全,建议您运行以下命令,删除默认用户。

RabbitMQ默认的账号用户名和密码都是guest。

rabbitmqctl delete_user guest
  • 1

4、创建RabbitMQ管理员用户。

a 运行以下命令,创建一个新用户

rabbitmqctl add_user <用户名> <密码>
  • 1

其中,<用户名>和<密码>为您自定义的信息。

b 运行以下命令,将创建的新用户设置为管理员。

rabbitmqctl set_user_tags <用户名> administrator
  • 1

c 运行以下命令,赋予新创建的用户所有权限

rabbitmqctl set_permissions -p / <用户名> ".*" ".*" ".*"
  • 1

(4)配置RabbitMQ的rabbitmq-server文件。

1.1 运行以下命令,编辑rabbitmq-server文件。

vi /root/rabbitmq_server-3.7.8/sbin/rabbitmq-server
  • 1

1.2 按下shift+:组合键,然后输入set nu查看文件的行号。

1.3 按下shift+:组合键,然后输入189跳转至189行。

1.4 按下i键,进入编辑模式

在189行新增以下内容:

export PATH=$PATH:/usr/local/erlang/bin
export HOME=/root/rabbitmq_server-3.7.8/
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/678215
推荐阅读
相关标签
  

闽ICP备14008679号