第一步:安装yum仓库
导入签名KEY:
代码语言:javascript复制## primary RabbitMQ signing key
## 这一步如果因为网络问题下载不成功,可以先将签名文件下载下来,本地导入
rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
## modern Erlang repository
rpm --import https://packagecloud.io/rabbitmq/erlang/gpgkey
## RabbitMQ server repository
rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
手动配置Yum源: 新建文件“/etc/yum.repos.d/rabbitmq.repo”,编辑如下内容:
代码语言:javascript复制# 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
https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
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
https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
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
# PackageCloud's repository key and RabbitMQ package signing key
gpgkey=https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
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
第二步:执行安装
更新Yum包元数据:
代码语言:javascript复制yum update -y
特别地,在腾讯云主机CentOS 8.2操作系统上安装时遇到无法从AppStream下载
问题,解决办法参考:完美解决CentOS8 yum安装AppStream报错,更新yum后无法makecache的问题
另外还要注意:腾讯云主机的CentOS 8.2操作系统基础yum仓库文件的名字都是“CentOS-Linux-.repo”,而不是标准的“CentOS-.repo”命名方式,所以修改的时候不要搞错文件。
安装依赖:
代码语言:javascript复制## install these dependencies from standard OS repositories
yum install socat logrotate -y
安装Erlang和RabbitMQ:
代码语言:javascript复制## install RabbitMQ and zero dependency Erlang from the above repositories,
## ignoring any versions provided by the standard repositories
yum install --repo rabbitmq_erlang --repo rabbitmq_server erlang rabbitmq-server -y
第三步:启动服务
设置开机启动:
代码语言:javascript复制chkconfig rabbitmq-server on
安装服务工具:
代码语言:javascript复制yum -y install initscripts
启动服务:
代码语言:javascript复制# 启动服务
/sbin/service rabbitmq-server start
# 查看服务状态
/sbin/service rabbitmq-server status
# 停止服务
/sbin/service rabbitmq-server stop
查看服务端口是否已经正常:
代码语言:javascript复制netstat -anpt
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 84521/beam.smp
tcp6 0 0 :::5672 :::* LISTEN 84521/beam.smp
默认服务端口5672
已经处于监听状态,表明RabbitMQ服务启动成功。
第四步:启用Web管理
RabbitMQ的Web管理界面是通过插件实现的,默认并不启用,所以在查看端口的时候也不会看到管理端口“15672”在监听。
手动启用Web管理插件:rabbitmq-plugins enable rabbitmq_management
。
再次查看监听端口:
netstat -anpt
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 84521/beam.smp
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 84521/beam.smp
tcp6 0 0 :::5672 :::* LISTEN 84521/beam.smp
查看插件列表状态;
代码语言:javascript复制rabbitmq-plugins list
Listing plugins with pattern ".*" ...
Configured: E = explicitly enabled; e = implicitly enabled
| Status: * = running on rabbit@VM-24-10-centos
|/
[ ] rabbitmq_amqp1_0 3.9.13
[ ] rabbitmq_auth_backend_cache 3.9.13
[ ] rabbitmq_auth_backend_http 3.9.13
[ ] rabbitmq_auth_backend_ldap 3.9.13
[ ] rabbitmq_auth_backend_oauth2 3.9.13
[ ] rabbitmq_auth_mechanism_ssl 3.9.13
[ ] rabbitmq_consistent_hash_exchange 3.9.13
[ ] rabbitmq_event_exchange 3.9.13
[ ] rabbitmq_federation 3.9.13
[ ] rabbitmq_federation_management 3.9.13
[ ] rabbitmq_jms_topic_exchange 3.9.13
[E*] rabbitmq_management 3.9.13
[e*] rabbitmq_management_agent 3.9.13
[ ] rabbitmq_mqtt 3.9.13
[ ] rabbitmq_peer_discovery_aws 3.9.13
[ ] rabbitmq_peer_discovery_common 3.9.13
[ ] rabbitmq_peer_discovery_consul 3.9.13
[ ] rabbitmq_peer_discovery_etcd 3.9.13
[ ] rabbitmq_peer_discovery_k8s 3.9.13
[ ] rabbitmq_prometheus 3.9.13
[ ] rabbitmq_random_exchange 3.9.13
[ ] rabbitmq_recent_history_exchange 3.9.13
[ ] rabbitmq_sharding 3.9.13
[ ] rabbitmq_shovel 3.9.13
[ ] rabbitmq_shovel_management 3.9.13
[ ] rabbitmq_stomp 3.9.13
[ ] rabbitmq_stream 3.9.13
[ ] rabbitmq_stream_management 3.9.13
[ ] rabbitmq_top 3.9.13
[ ] rabbitmq_tracing 3.9.13
[ ] rabbitmq_trust_store 3.9.13
[e*] rabbitmq_web_dispatch 3.9.13
[ ] rabbitmq_web_mqtt 3.9.13
[ ] rabbitmq_web_mqtt_examples 3.9.13
[ ] rabbitmq_web_stomp 3.9.13
[ ] rabbitmq_web_stomp_examples 3.9.13
可以看到跟Web管理相关的插件都启用了。
至此,虽然RabbitMQ的Web管理插件已经启用,但是只能在通过本机地址打开Web界面,如果希望从远程访问Web界面(大多数场景就是这样的),还需要进行配置。
默认情况下,启动RabbitMQ Server是没有明确指定配置文件的,也就是我们无法修改允许远程访问Web管理界面的参数。
代码语言:javascript复制# grep 'config file' /var/log/rabbitmq/rabbit@VM-24-10-centos.log
2022-03-17 16:51:36.534481 08:00 [info] <0.230.0> config file(s) : (none) # 从这里可以看出RabbitMQ在启动时没有明确指定配置文件
解决办法:
(1)通过环境变量RABBITMQ_CONFIG_FILE
指定RabbitMQ配置文件路径
# vim .bashrc
export RABBITMQ_CONFIG_FILE=/etc/rabbitmq/rabbitmq.conf
文件/etc/rabbitmq/rabbitmq.conf
可能不存在,创建一个即可。
RabbitMQ的配置文件参数示例:rabbitmq.conf.example,可以直接下载下来使用,里面都是默认配置参数。
(2)修改允许远程访问Web界面的参数:将loopback_users.guest
参数修改为false
loopback_users.guest = false
(3)重启RabbitMQ服务
代码语言:javascript复制/sbin/service rabbitmq-server stop
/sbin/service rabbitmq-server start
现在再来看RabbitMQ是否在启动时使用了指定配置文件:
代码语言:javascript复制grep 'config file' /var/log/rabbitmq/rabbit@VM-24-10-centos.log
2022-03-17 16:51:36.534481 08:00 [info] <0.230.0> config file(s) : (none)
2022-03-17 17:22:09.174170 08:00 [info] <0.230.0> config file(s) : /etc/rabbitmq/rabbitmq.conf # 显然,从启动日志看RabbitMQ现在使用了指定的配置文件
【参考】 https://github.com/rabbitmq/rabbitmq-server/blob/master/deps/rabbit/docs/rabbitmq.conf.example RabbitMQ官方配置文件示例 https://www.rabbitmq.com/relocate.html RabbitMQ环境变量含义 https://blog.csdn.net/qq_27198345/article/details/115384898 RabbitMQ的默认配置文件地址 https://blog.csdn.net/PacosonSWJTU/article/details/114198834 rabbitmq启动失败-报Failed to load advanced configuration file解决方法