CentOS 系统部署 RabbitMQ-越努力,越幸运!-51CTO博客 | 中间件 centos7 centos 8 安装 rabbitmq

简介

MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法。应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们。消息传递指的是程序之间通过在消息中发送数据进行通信,而不是通过直接调用彼此来通信,直接调用通常是用于诸如远程过程调用的技术。排队指的是应用程序通过 队列来通信。队列的使用除去了接收和发送应用程序同时执行的要求。

概念介绍

RabbitMQ 是目前流行的开源消息队列系统,用Erlang语言开发。RabbitMQ 是AMQP(高级消息队列)的标准实现。下面是它的几个关键概念:
Broker:简单来说就是消息队列服务器实体。
Exchange:消息交换机,它指定消息按什么规则,路由到哪个队列。
Queue:消息队列载体,每个消息都会被投入到一个或多个队列。
Binding:绑定,它的作用就是把exchange和queue按照路由规则绑定起来。
Routing Key:路由关键字,exchange根据这个关键字进行消息投递。
vhost:虚拟主机,一个broker里可以开设多个vhost,用作不同用户的权限分离。
producer:消息生产者,就是投递消息的程序。
consumer:消息消费者,就是接受消息的程序。
channel:消息通道,在客户端的每个连接里,可建立多个channel,每个channel代表一个会话任务。

消息队列的使用过程:

1.客户端连接消息队列服务器,打开一个Channel。
2.客户端声明一个EXchange,并设置相关属性。
3.客户端声明一个Queue,并设置相关属性。
4.客户端使用Routing Key,在EXchange 和Queue之间建立好绑定关系。
5.客户端投递消息到EXchange。

RabbitMQ的应用场景

常用的使用场景:异步处理,应用解耦,流量削锋和消息通讯四个场景

部署过程

CentOS 7系统上部署:

1.关闭防火墙及Selinux

setenforce 0
systemctl stop firewalld

2.更新epel源

yum -y install epel-release

3.下载RabbitMQ

yum -y install rabbitmq-server

4.查看已安装的插件

rabbitmq-plugins list

CentOS 系统部署 RabbitMQ

5.启动管理服务

rabbitmq-plugins enable rabbitmq_management

CentOS 系统部署 RabbitMQ

6.启动rabbitmq服务

systemctl start rabbitmq-server

CentOS 系统部署 RabbitMQ

7.网页登录

访问网站:http://192.168.0.103:15672

CentOS 系统部署 RabbitMQ
CentOS 系统部署 RabbitMQ

CentOS 8系统上部署:

1.关闭防火墙及Selinux

setenforce 0
systemctl stop firewalld

2.配置yum源

cd /etc/yum.repos.d/ #进入目录
vim rabbitmq-erlang.repo
[rabbitmq-erlang] 
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq-erlang/rpm/erlang/21/el/7
gpgcheck=1
gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1
vim rabbitmq.repo
[bintray-rabbitmq-server]
name=bintray-rabbitmq-rpm
baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.8.x/el/8/
gpgcheck=0
repo_gpgcheck=0
enabled=1

3.下载RabbitMQ

yum -y install rabbitmq-server

4.查看已安装的插件

rabbitmq-plugins list

CentOS 系统部署 RabbitMQ

5.启动管理服务

rabbitmq-plugins enable rabbitmq_management

CentOS 系统部署 RabbitMQ

6.启动RabbitMQ服务

systemctl start rabbitmq-server

CentOS 系统部署 RabbitMQ

7.网页登录

访问网站:http://192.168.0.102:15672

CentOS 系统部署 RabbitMQ

登录结果:使用guest证号无法登录

8.排错过程

1.查看日志

vim /var/log/rabbitmq/rabbit@centos8.log

CentOS 系统部署 RabbitMQ

2.上网查资料

了解原因: rabbitmq从3.3.0开始禁止使用guest/guest权限通过除localhost外的访问

解决办法:修改配置文件

vim /usr/lib/rabbitmq/lib/rabbitmq_server-3.8.2/ebin/rabbit.app

CentOS 系统部署 RabbitMQ
CentOS 系统部署 RabbitMQ

systemctl restart rabbitmq-server.service #重启服务

访问网页测试:

CentOS 系统部署 RabbitMQ

结果:成功访问,修改成功!

RabbitMQ相关命令

> systemctl start rabbitmq-server #开启  
> systemctl stop rabbitmq-server #关闭  
> systemctl status rabbitmq-server 查看状态  
> systemctl restart rabbitmq-server #重启  
> rabbitmqctl add_user admin password #创建用户  
> #赋予权限  
> rabbitmqctl set\_user\_tags admin administrator  
> rabbitmqctl set_permissions -p / admin "._" "._" ".*"
[root@localhost mnt1t]# yum -y install rabbitmq-server
Loaded plugins: fastestmirror, langpacks, nvidia
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * elrepo: elrepo.reloumirrors.net
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * nux-dextop: mirror.li.nux.ro
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package rabbitmq-server.noarch 0:3.3.5-34.el7 will be installed
--> Processing Dependency: erlang-erts >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-kernel >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-mnesia >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-os_mon >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-public_key >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-sasl >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-ssl >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-stdlib >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-tools >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-xmerl >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-sd_notify for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Running transaction check
---> Package erlang-erts.x86_64 0:R16B-03.18.el7 will be installed
---> Package erlang-kernel.x86_64 0:R16B-03.18.el7 will be installed
---> Package erlang-mnesia.x86_64 0:R16B-03.18.el7 will be installed
---> Package erlang-os_mon.x86_64 0:R16B-03.18.el7 will be installed
--> Processing Dependency: erlang-otp_mibs(x86-64) = R16B-03.18.el7 for package: erlang-os_mon-R16B-03.18.el7.x86_64
--> Processing Dependency: erlang-snmp(x86-64) = R16B-03.18.el7 for package: erlang-os_mon-R16B-03.18.el7.x86_64
---> Package erlang-public_key.x86_64 0:R16B-03.18.el7 will be installed
--> Processing Dependency: erlang-asn1(x86-64) = R16B-03.18.el7 for package: erlang-public_key-R16B-03.18.el7.x86_64
--> Processing Dependency: erlang-crypto(x86-64) = R16B-03.18.el7 for package: erlang-public_key-R16B-03.18.el7.x86_64
---> Package erlang-sasl.x86_64 0:R16B-03.18.el7 will be installed
---> Package erlang-sd_notify.x86_64 0:0.1-1.el7 will be installed
---> Package erlang-ssl.x86_64 0:R16B-03.18.el7 will be installed
---> Package erlang-stdlib.x86_64 0:R16B-03.18.el7 will be installed
--> Processing Dependency: erlang-compiler(x86-64) = R16B-03.18.el7 for package: erlang-stdlib-R16B-03.18.el7.x86_64
---> Package erlang-tools.x86_64 0:R16B-03.18.el7 will be installed
--> Processing Dependency: erlang-inets(x86-64) = R16B-03.18.el7 for package: erlang-tools-R16B-03.18.el7.x86_64
--> Processing Dependency: erlang-runtime_tools(x86-64) = R16B-03.18.el7 for package: erlang-tools-R16B-03.18.el7.x86_64
---> Package erlang-xmerl.x86_64 0:R16B-03.18.el7 will be installed
--> Running transaction check
---> Package erlang-asn1.x86_64 0:R16B-03.18.el7 will be installed
---> Package erlang-compiler.x86_64 0:R16B-03.18.el7 will be installed
--> Processing Dependency: erlang-hipe(x86-64) = R16B-03.18.el7 for package: erlang-compiler-R16B-03.18.el7.x86_64
---> Package erlang-crypto.x86_64 0:R16B-03.18.el7 will be installed
---> Package erlang-inets.x86_64 0:R16B-03.18.el7 will be installed
---> Package erlang-otp_mibs.x86_64 0:R16B-03.18.el7 will be installed
---> Package erlang-runtime_tools.x86_64 0:R16B-03.18.el7 will be installed
---> Package erlang-snmp.x86_64 0:R16B-03.18.el7 will be installed
--> Running transaction check
---> Package erlang-hipe.x86_64 0:R16B-03.18.el7 will be installed
--> Processing Dependency: erlang-syntax_tools(x86-64) = R16B-03.18.el7 for package: erlang-hipe-R16B-03.18.el7.x86_64
--> Running transaction check
---> Package erlang-syntax_tools.x86_64 0:R16B-03.18.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                    Arch         Version               Repository  Size
================================================================================
Installing:
 rabbitmq-server            noarch       3.3.5-34.el7          epel       4.0 M
Installing for dependencies:
 erlang-asn1                x86_64       R16B-03.18.el7        epel       758 k
 erlang-compiler            x86_64       R16B-03.18.el7        epel       1.0 M
 erlang-crypto              x86_64       R16B-03.18.el7        epel        86 k
 erlang-erts                x86_64       R16B-03.18.el7        epel       2.5 M
 erlang-hipe                x86_64       R16B-03.18.el7        epel       2.4 M
 erlang-inets               x86_64       R16B-03.18.el7        epel       800 k
 erlang-kernel              x86_64       R16B-03.18.el7        epel       1.1 M
 erlang-mnesia              x86_64       R16B-03.18.el7        epel       700 k
 erlang-os_mon              x86_64       R16B-03.18.el7        epel       115 k
 erlang-otp_mibs            x86_64       R16B-03.18.el7        epel        32 k
 erlang-public_key          x86_64       R16B-03.18.el7        epel       538 k
 erlang-runtime_tools       x86_64       R16B-03.18.el7        epel       179 k
 erlang-sasl                x86_64       R16B-03.18.el7        epel       293 k
 erlang-sd_notify           x86_64       0.1-1.el7             epel       9.1 k
 erlang-snmp                x86_64       R16B-03.18.el7        epel       1.5 M
 erlang-ssl                 x86_64       R16B-03.18.el7        epel       588 k
 erlang-stdlib              x86_64       R16B-03.18.el7        epel       2.2 M
 erlang-syntax_tools        x86_64       R16B-03.18.el7        epel       336 k
 erlang-tools               x86_64       R16B-03.18.el7        epel       566 k
 erlang-xmerl               x86_64       R16B-03.18.el7        epel       998 k

Transaction Summary
================================================================================
Install  1 Package (+20 Dependent packages)

Total download size: 21 M
Installed size: 36 M
Downloading packages:
(1/21): erlang-compiler-R16B-03.18.el7.x86_64.rpm          | 1.0 MB   00:00     
(2/21): erlang-asn1-R16B-03.18.el7.x86_64.rpm              | 758 kB   00:00     
(3/21): erlang-crypto-R16B-03.18.el7.x86_64.rpm            |  86 kB   00:00     
(4/21): erlang-erts-R16B-03.18.el7.x86_64.rpm              | 2.5 MB   00:00     
(5/21): erlang-hipe-R16B-03.18.el7.x86_64.rpm              | 2.4 MB   00:00     
(6/21): erlang-inets-R16B-03.18.el7.x86_64.rpm             | 800 kB   00:00     
(7/21): erlang-kernel-R16B-03.18.el7.x86_64.rpm            | 1.1 MB   00:00     
(8/21): erlang-mnesia-R16B-03.18.el7.x86_64.rpm            | 700 kB   00:00     
(9/21): erlang-os_mon-R16B-03.18.el7.x86_64.rpm            | 115 kB   00:00     
(10/21): erlang-otp_mibs-R16B-03.18.el7.x86_64.rpm         |  32 kB   00:00     
(11/21): erlang-runtime_tools-R16B-03.18.el7.x86_64.rpm    | 179 kB   00:00     
(12/21): erlang-public_key-R16B-03.18.el7.x86_64.rpm       | 538 kB   00:00     
(13/21): erlang-sasl-R16B-03.18.el7.x86_64.rpm             | 293 kB   00:00     
(14/21): erlang-sd_notify-0.1-1.el7.x86_64.rpm             | 9.1 kB   00:00     
(15/21): erlang-ssl-R16B-03.18.el7.x86_64.rpm              | 588 kB   00:00     
(16/21): erlang-snmp-R16B-03.18.el7.x86_64.rpm             | 1.5 MB   00:00     
(17/21): erlang-syntax_tools-R16B-03.18.el7.x86_64.rpm     | 336 kB   00:00     
(18/21): erlang-stdlib-R16B-03.18.el7.x86_64.rpm           | 2.2 MB   00:00     
(19/21): erlang-tools-R16B-03.18.el7.x86_64.rpm            | 566 kB   00:00     
(20/21): erlang-xmerl-R16B-03.18.el7.x86_64.rpm            | 998 kB   00:00     
(21/21): rabbitmq-server-3.3.5-34.el7.noarch.rpm           | 4.0 MB   00:00     
--------------------------------------------------------------------------------
Total                                              5.2 MB/s |  21 MB  00:03     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : erlang-syntax_tools-R16B-03.18.el7.x86_64                   1/21 
  Installing : erlang-crypto-R16B-03.18.el7.x86_64                         2/21 
  Installing : erlang-kernel-R16B-03.18.el7.x86_64                         3/21 
  Installing : erlang-stdlib-R16B-03.18.el7.x86_64                         4/21 
  Installing : erlang-erts-R16B-03.18.el7.x86_64                           5/21 
  Installing : erlang-compiler-R16B-03.18.el7.x86_64                       6/21 
  Installing : erlang-hipe-R16B-03.18.el7.x86_64                           7/21 
  Installing : erlang-mnesia-R16B-03.18.el7.x86_64                         8/21 
  Installing : erlang-runtime_tools-R16B-03.18.el7.x86_64                  9/21 
  Installing : erlang-snmp-R16B-03.18.el7.x86_64                          10/21 
  Installing : erlang-otp_mibs-R16B-03.18.el7.x86_64                      11/21 
  Installing : erlang-xmerl-R16B-03.18.el7.x86_64                         12/21 
  Installing : erlang-sd_notify-0.1-1.el7.x86_64                          13/21 
  Installing : erlang-asn1-R16B-03.18.el7.x86_64                          14/21 
  Installing : erlang-public_key-R16B-03.18.el7.x86_64                    15/21 
  Installing : erlang-ssl-R16B-03.18.el7.x86_64                           16/21 
  Installing : erlang-inets-R16B-03.18.el7.x86_64                         17/21 
  Installing : erlang-tools-R16B-03.18.el7.x86_64                         18/21 
  Installing : erlang-sasl-R16B-03.18.el7.x86_64                          19/21 
  Installing : erlang-os_mon-R16B-03.18.el7.x86_64                        20/21 
  Installing : rabbitmq-server-3.3.5-34.el7.noarch                        21/21 
  Verifying  : erlang-tools-R16B-03.18.el7.x86_64                          1/21 
  Verifying  : erlang-xmerl-R16B-03.18.el7.x86_64                          2/21 
  Verifying  : rabbitmq-server-3.3.5-34.el7.noarch                         3/21 
  Verifying  : erlang-sd_notify-0.1-1.el7.x86_64                           4/21 
  Verifying  : erlang-public_key-R16B-03.18.el7.x86_64                     5/21 
  Verifying  : erlang-erts-R16B-03.18.el7.x86_64                           6/21 
  Verifying  : erlang-runtime_tools-R16B-03.18.el7.x86_64                  7/21 
  Verifying  : erlang-snmp-R16B-03.18.el7.x86_64                           8/21 
  Verifying  : erlang-syntax_tools-R16B-03.18.el7.x86_64                   9/21 
  Verifying  : erlang-sasl-R16B-03.18.el7.x86_64                          10/21 
  Verifying  : erlang-stdlib-R16B-03.18.el7.x86_64                        11/21 
  Verifying  : erlang-os_mon-R16B-03.18.el7.x86_64                        12/21 
  Verifying  : erlang-crypto-R16B-03.18.el7.x86_64                        13/21 
  Verifying  : erlang-compiler-R16B-03.18.el7.x86_64                      14/21 
  Verifying  : erlang-mnesia-R16B-03.18.el7.x86_64                        15/21 
  Verifying  : erlang-inets-R16B-03.18.el7.x86_64                         16/21 
  Verifying  : erlang-asn1-R16B-03.18.el7.x86_64                          17/21 
  Verifying  : erlang-kernel-R16B-03.18.el7.x86_64                        18/21 
  Verifying  : erlang-ssl-R16B-03.18.el7.x86_64                           19/21 
  Verifying  : erlang-hipe-R16B-03.18.el7.x86_64                          20/21 
  Verifying  : erlang-otp_mibs-R16B-03.18.el7.x86_64                      21/21 

Installed:
  rabbitmq-server.noarch 0:3.3.5-34.el7                                         

Dependency Installed:
  erlang-asn1.x86_64 0:R16B-03.18.el7                                           
  erlang-compiler.x86_64 0:R16B-03.18.el7                                       
  erlang-crypto.x86_64 0:R16B-03.18.el7                                         
  erlang-erts.x86_64 0:R16B-03.18.el7                                           
  erlang-hipe.x86_64 0:R16B-03.18.el7                                           
  erlang-inets.x86_64 0:R16B-03.18.el7                                          
  erlang-kernel.x86_64 0:R16B-03.18.el7                                         
  erlang-mnesia.x86_64 0:R16B-03.18.el7                                         
  erlang-os_mon.x86_64 0:R16B-03.18.el7                                         
  erlang-otp_mibs.x86_64 0:R16B-03.18.el7                                       
  erlang-public_key.x86_64 0:R16B-03.18.el7                                     
  erlang-runtime_tools.x86_64 0:R16B-03.18.el7                                  
  erlang-sasl.x86_64 0:R16B-03.18.el7                                           
  erlang-sd_notify.x86_64 0:0.1-1.el7                                           
  erlang-snmp.x86_64 0:R16B-03.18.el7                                           
  erlang-ssl.x86_64 0:R16B-03.18.el7                                            
  erlang-stdlib.x86_64 0:R16B-03.18.el7                                         
  erlang-syntax_tools.x86_64 0:R16B-03.18.el7                                   
  erlang-tools.x86_64 0:R16B-03.18.el7                                          
  erlang-xmerl.x86_64 0:R16B-03.18.el7                                          

Complete!
[root@localhost mnt1t]# rabbitmq-plugins list
[ ] amqp_client                       3.3.5
[ ] cowboy                            0.5.0-rmq3.3.5-git4b93c2d
[ ] eldap                             3.3.5-gite309de4
[ ] mochiweb                          2.7.0-rmq3.3.5-git680dba8
[ ] rabbitmq_amqp1_0                  3.3.5
[ ] rabbitmq_auth_backend_ldap        3.3.5
[ ] rabbitmq_auth_mechanism_ssl       3.3.5
[ ] rabbitmq_consistent_hash_exchange 3.3.5
[ ] rabbitmq_federation               3.3.5
[ ] rabbitmq_federation_management    3.3.5
[ ] rabbitmq_management               3.3.5
[ ] rabbitmq_management_agent         3.3.5
[ ] rabbitmq_management_visualiser    3.3.5
[ ] rabbitmq_mqtt                     3.3.5
[ ] rabbitmq_shovel                   3.3.5
[ ] rabbitmq_shovel_management        3.3.5
[ ] rabbitmq_stomp                    3.3.5
[ ] rabbitmq_test                     3.3.5
[ ] rabbitmq_tracing                  3.3.5
[ ] rabbitmq_web_dispatch             3.3.5
[ ] rabbitmq_web_stomp                3.3.5
[ ] rabbitmq_web_stomp_examples       3.3.5
[ ] sockjs                            0.3.4-rmq3.3.5-git3132eb9
[ ] webmachine                        1.10.3-rmq3.3.5-gite9359c7
[root@localhost mnt1t]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
  mochiweb
  webmachine
  rabbitmq_web_dispatch
  amqp_client
  rabbitmq_management_agent
  rabbitmq_management
Plugin configuration has changed. Restart RabbitMQ for changes to take effect.
[root@localhost mnt1t]# service rabbitmq start
Redirecting to /bin/systemctl start rabbitmq.service
Failed to start rabbitmq.service: Unit not found.


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

Original url: Access
Created at: 2020-09-14 09:40:21
Category: default
Tags: none

请先后发表评论
  • 最新评论
  • 总共0条评论