如何在RHEL 8/CentOS 8上安装RabbitMQ
如何在RHEL 8/CentOS 8服务器上安装RabbitMQ服务器?本指南旨在在RHEL/CentOS 8服务器或者工作站上安装最新版本的RabbitMQ。 RabbitMQ是实现高级消息队列协议(AMQP)的开源消息代理软件。
RabbitMQ的工作原理是接收来自发布者(发布它们的应用程序)的消息,并将其路由到使用者(处理它们的应用程序)。
请按照下面的步骤在RHEL/CentOS 8服务器上安装并运行RabbitMQ服务器。
安装EPEL储存库
EPEL信息库中有很多依赖项,请使用下面的指南在系统上启用它。
如何在RHEL 8/CentOS 8上启用EPEL存储库
更新系统
添加EPEL存储库后,更新系统
sudo yum -y update
添加PackageCloud Yum存储库
PackageCloud可提供带有RabbitMQ软件包的Yum存储库。
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
在RHEL 8/CentOS 8上安装RabbitMQ
配置RabbitMQ存储库后,通过运行以下命令在RHEL/CentOS 8上安装RabbitMQ Server。
sudo yum makecache -y --disablerepo='*' --enablerepo='rabbitmq_rabbitmq-server' sudo yum -y install rabbitmq-server
可以使用带有-qi选项的rpm命令查询软件包的详细信息。
$rpm -qi rabbitmq-server Name : rabbitmq-server Version : 3.8.1 Release : 1.el8 Architecture: noarch Install Date: Mon 04 Nov 2019 08:30:42 AM EAT Group : Development/Libraries Size : 13589089 License : MPLv1.1 and MIT and ASL 2.0 and BSD Signature : RSA/SHA256, Fri 01 Nov 2019 02:35:54 AM EAT, Key ID 6b73a36e6026dfca Source RPM : rabbitmq-server-3.8.1-1.el8.src.rpm Build Date : Fri 01 Nov 2019 02:35:53 AM EAT Build Host : 056175bc-c207-4458-54e3-fe5f1985b0ae Relocations : (not relocatable) URL : https://www.rabbitmq.com/ Summary : The RabbitMQ server Description : RabbitMQ is an open source multi-protocol messaging broker.
启动RabbitMQ服务
现在,我们已经在RHEL 8上安装了RabbitMQ,启动并启用该服务以在系统引导时启动。
echo "127.0.0.1 $(hostname -s)" | sudo tee -a /etc/hosts sudo systemctl enable --now rabbitmq-server.service
使用以下命令检查RabbitMQ的状态:
$systemctl status rabbitmq-server.service ● rabbitmq-server.service - RabbitMQ broker Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2019-11-04 08:31:49 EAT; 7s ago Main PID: 20790 (beam.smp) Status: "Initialized" Tasks: 85 (limit: 11512) Memory: 86.5M CGroup: /system.slice/rabbitmq-server.service ├─20790 /usr/lib64/erlang/erts-10.4.4/bin/beam.smp -W w -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048> ├─20965 /usr/lib64/erlang/erts-10.4.4/bin/epmd -daemon ├─21092 erl_child_setup 32768 ├─21113 inet_gethost 4 └─21114 inet_gethost 4 Nov 04 08:31:49 centos8.novalocal rabbitmq-server[20790]: Doc guides: https://rabbitmq.com/documentation.html Nov 04 08:31:49 centos8.novalocal rabbitmq-server[20790]: Support: https://rabbitmq.com/contact.html Nov 04 08:31:49 centos8.novalocal rabbitmq-server[20790]: Tutorials: https://rabbitmq.com/getstarted.html Nov 04 08:31:49 centos8.novalocal rabbitmq-server[20790]: Monitoring: https://rabbitmq.com/monitoring.html Nov 04 08:31:49 centos8.novalocal rabbitmq-server[20790]: Logs: /var/log/rabbitmq/theitroad@localhost Nov 04 08:31:49 centos8.novalocal rabbitmq-server[20790]: /var/log/rabbitmq/theitroad@localhost_upgrade.log Nov 04 08:31:49 centos8.novalocal rabbitmq-server[20790]: Config file(s): (none) Nov 04 08:31:49 centos8.novalocal rabbitmq-server[20790]: Starting broker...systemd unit for activation check: "rabbitmq-server.service" Nov 04 08:31:49 centos8.novalocal systemd[1]: Started RabbitMQ broker. Nov 04 08:31:49 centos8.novalocal rabbitmq-server[20790]: completed with 0 plugins.
RabbitMQ内部详细信息位于:
sudo rabbitmqctl status
第6步:启用RabbitMQ管理仪表板(可选)
我们可以选择启用RabbitMQ管理Web仪表板,以便于管理。
$sudo rabbitmq-plugins enable rabbitmq_management Enabling plugins on node theitroad@localhost: rabbitmq_management The following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch Applying plugin configuration to theitroad@localhost… The following plugins have been enabled: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch started 3 plugins.
Web服务应在TCP端口15672上侦听
# ss -tunelp | grep 15672 tcp LISTEN 0 128 0.0.0.0:15672 0.0.0.0:* users:(("beam.smp",pid=9525,fd=71)) uid:111 ino:39934 sk:9 <->
如果我们有活动的防火墙服务,请允许端口" 5672"和" 15672"
sudo firewall-cmd --add-port={5672,15672}/tcp --permanent sudo firewall-cmd --reload
通过打开URLhttp://[serverIP | Hostname]:15672访问它
默认情况下,guestuser存在,并且只能从localhost连接。我们可以使用密码guest在本地用该用户登录
为了能够在网络上登录,请创建一个如下的管理员用户:
$sudo rabbitmqctl add_user admin StrongPassword Adding user "admin" … $sudo rabbitmqctl set_user_tags admin administrator Setting tags for user "admin" to [administrator] …
使用此管理员用户名和分配的密码登录。我们应该看到类似于以下的界面。
要使用" rabbitmqadmin"命令行工具,请将其复制到$PATH中。
sudo updatedb sudo cp locate rabbitmqadmin /usr/local/bin/rabbitmqadmin sudo chmod +x /usr/local/bin/rabbitmqadmin
我们需要安装并配置" python"以运行rabbitmqadmin,请参见下文
如何在RHEL 8上安装Python 3/Python 2.7
RabbitMQ用户管理命令
删除用户:
sudo rabbitmqctl delete_user user
更改用户密码:
sudo rabbitmqctl change_password user strongpassword
创建新的虚拟主机:
sudo rabbitmqctl add_vhost /my_vhost
列出可用的虚拟主机:
sudo rabbitmqctl list_vhosts
删除虚拟主机:
sudo rabbitmqctl delete_vhost /myvhost
授予用户对vhost的权限:
sudo rabbitmqctl set_permissions -p /myvhost user ".*" ".*" ".*"
列出虚拟主机权限:
sudo rabbitmqctl list_permissions -p /myvhost
列出用户权限:
rabbitmqctl list_user_permissions user
删除用户权限:
rabbitmqctl clear_permissions -p /myvhost user