如何在CentOS 7部署RabbitMQ服务

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

RabbitMQ 简介
安装RabbitMQ的消息代理软件,实现了AMQP(高级消息队列协议)
RabbitMQ 教程: http://www.rabbitmq.com/getstarted.html
RabbitMQ 安装:http://www.rabbitmq.com/download.html
RabbitMQ 安装
# Install from EPEL 
[root@vdevops~]# yum --enablerepo=epel -y install rabbitmq-server 
[root@vdevops~]# systemctl start rabbitmq-server 
[root@vdevops /]# journalctl -xe 
Nov 12 01:30:01 vdevops.org CROND[3856]: (root) CMD (/usr/lib64/sa/sa1 1 1) 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: DIAGNOSTICS 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: =========== 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: attempted to contact: [rabbit@vdevops] 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: rabbit@vdevops: 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: * unable to connect to epmd (port 4369) on vdevops: timeout (timed out) 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: current node details: 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: - node name: rabbitmqctl3831@vdevops 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: - home dir: /var/lib/rabbitmq 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: - cookie hash: s++dDMtIhAufFItw+ercBw== 
Nov 12 01:30:04 vdevops.org polkitd[1007]: Unregistered Authentication Agent for unix-process:3798:36632 (system bus name :1.23, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected f 
Nov 12 01:30:04 vdevops.org systemd[1]: rabbitmq-server.service: control process exited, code=exited status=2 
Nov 12 01:30:04 vdevops.org systemd[1]: Failed to start RabbitMQ broker. 
-- Subject: Unit rabbitmq-server.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --  -- Unit rabbitmq-server.service has failed. --  -- The result is failed. Nov 12 01:30:04 vdevops.org systemd[1]: Unit rabbitmq-server.service entered failed state. Nov 12 01:30:04 vdevops.org systemd[1]: rabbitmq-server.service failed. Nov 12 01:30:42 vdevops.org systemd[1]: Got automount request for /proc/sys/fs/binfmt_misc, triggered by 3860 (find) Nov 12 01:30:42 vdevops.org systemd[1]: Mounting Arbitrary Executable File Formats File System... -- Subject: Unit proc-sys-fs-binfmt_misc.mount has begun start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --  -- Unit proc-sys-fs-binfmt_misc.mount has begun starting up. Nov 12 01:30:42 vdevops.org systemd[1]: Mounted Arbitrary Executable File Formats File System. -- Subject: Unit proc-sys-fs-binfmt_misc.mount has finished start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --  -- Unit proc-sys-fs-binfmt_misc.mount has finished starting up. --  -- The start-up result is done.  
rabbitmq-server启动报错:Failed to start RabbitMQ broker
度娘解析:主机hostname配置错误,原本hostname为vdevops.org,更改为vdevops,修改hosts文件中hostname设置
# Install from EPEL 
[root@vdevops~]# yum --enablerepo=epel -y install rabbitmq-server 
[root@vdevops~]# systemctl start rabbitmq-server 
[root@vdevops /]# journalctl -xe 
Nov 12 01:30:01 vdevops.org CROND[3856]: (root) CMD (/usr/lib64/sa/sa1 1 1) 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: DIAGNOSTICS 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: =========== 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: attempted to contact: [rabbit@vdevops] 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: rabbit@vdevops: 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: * unable to connect to epmd (port 4369) on vdevops: timeout (timed out) 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: current node details: 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: - node name: rabbitmqctl3831@vdevops 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: - home dir: /var/lib/rabbitmq 
Nov 12 01:30:04 vdevops.org rabbitmqctl[3831]: - cookie hash: s++dDMtIhAufFItw+ercBw== 
Nov 12 01:30:04 vdevops.org polkitd[1007]: Unregistered Authentication Agent for unix-process:3798:36632 (system bus name :1.23, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected f 
Nov 12 01:30:04 vdevops.org systemd[1]: rabbitmq-server.service: control process exited, code=exited status=2 
Nov 12 01:30:04 vdevops.org systemd[1]: Failed to start RabbitMQ broker. 
-- Subject: Unit rabbitmq-server.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --  -- Unit rabbitmq-server.service has failed. --  -- The result is failed. Nov 12 01:30:04 vdevops.org systemd[1]: Unit rabbitmq-server.service entered failed state. Nov 12 01:30:04 vdevops.org systemd[1]: rabbitmq-server.service failed. Nov 12 01:30:42 vdevops.org systemd[1]: Got automount request for /proc/sys/fs/binfmt_misc, triggered by 3860 (find) Nov 12 01:30:42 vdevops.org systemd[1]: Mounting Arbitrary Executable File Formats File System... -- Subject: Unit proc-sys-fs-binfmt_misc.mount has begun start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --  -- Unit proc-sys-fs-binfmt_misc.mount has begun starting up. Nov 12 01:30:42 vdevops.org systemd[1]: Mounted Arbitrary Executable File Formats File System. -- Subject: Unit proc-sys-fs-binfmt_misc.mount has finished start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --  -- Unit proc-sys-fs-binfmt_misc.mount has finished starting up. --  -- The start-up result is done.  
防火墙设置
[root@linuxprobe~]# firewall-cmd --add-port=5672/tcp --permanent success [root@linuxprobe~]# firewall-cmd --reload success 
要使用RabbitMQ,请先添加用户
[root@vdevops ~]# rabbitmqctl add_user linuxprobe password 
Creating user "linuxprobe" ... 
...done. 
[root@vdevops ~]# rabbitmqctl list_users 
Listing users ... 
guest   [administrator] 
linuxprobe  [] 
...done. 
# granting admin role to a user is like follows 
[root@vdevops ~]# rabbitmqctl change_password linuxprobe strongpassword 
Changing password for user "linuxprobe" ... 
...done. 
# granting admin role to a user is like follows 
[root@vdevops ~]# rabbitmqctl set_user_tags linuxprobe administrator 
Setting tags for user "linuxprobe" to [administrator] ... 
...done. 
# deleting a user is like follows 
[root@vdevops ~]# rabbitmqctl delete_user linuxprobe  
Deleting user "linuxprobe " ... 
...done. 
要使用RabbitMQ,也要添加虚拟主机
[root@vdevops ~]# rabbitmqctl add_vhost /my_vhost 
Creating vhost "/my_vhost" ... 
...done. 
[root@vdevops ~]# rabbitmqctl list_vhosts  
Listing vhosts ... 
/my_vhost 
...done. 
[root@vdevops ~]# rabbitmqctl delete_vhost /my_vhost 
Deleting vhost "/my_vhost" ... 
...done. 
给虚拟主机的用户授予权限,请如下配置
# rabbitmqctl set_permissions [-p vhost] [user] [permission ? (modify) (write) (read)] 
[root@vdevops ~]# rabbitmqctl set_permissions -p /my_vhost linuxprobe ".*" ".*" ".*" 
Setting permissions for user "linuxprobe" in vhost "/my_vhost" ... 
...done. 
#  
[root@vdevops ~]#  rabbitmqctl list_user_permissions linuxprobe 
Listing permissions for user "linuxprobe" ... 
/my_vhost   .*  .*  .* 
...done. 
# deleting permission of a specific user is like follows 
[root@vdevops ~]# rabbitmqctl clear_permissions -p /my_vhost linuxprobe 
Clearing permissions for user "linuxprobe" in vhost "/my_vhost" ... 
...done. 
RabbitMQ:使用Web UI
[root@vdevops ~]# 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@vdevops ~]# systemctl restart rabbitmq-server 
客户端访问
http://vdevops:15672/


rabbitmqadmin使用
可以配置RabbitMQ使用rabbitmqadmin命
在Web UI上下载rabbitmqadmin。 登录到Web UI并移动到“http://(主机名或IP地址):15672 / cli”,然后显示以下屏幕,您可以在这里下载rabbitmqadmin,点击here右键保存rabbitmqadmin.txt,然后上传到服务器上面更改为rabbitmqadmin,并添加执行权限

将rabbitmqadmin上传到RabbitMQ服务器并设置合适的权限,此示例显示如下设置
[root@localhost ~]# ll /usr/local/bin/rabbitmqadmin  
-rwxr-xr-x. 1 root root 36112 Nov 11 17:23 /usr/local/bin/rabbitmqadmin 
[root@vdevops bin]# rabbitmqadmin list users 
+------------+------------------------------+---------------+ |    name    |        password_hash         |     tags      | +------------+------------------------------+---------------+ | guest      | k2rhpzCrZBKkY5WRhUWrGm5DCkg= | administrator | | linuxprobe | P+YxK1QXIYrJpek5i//rPjn5SME= | administrator | +------------+------------------------------+---------------+ [root@vdevops bin]# cd [root@vdevops ~]# rabbitmqadmin list users +------------+------------------------------+---------------+ |    name    |        password_hash         |     tags      | +------------+------------------------------+---------------+ | guest      | k2rhpzCrZBKkY5WRhUWrGm5DCkg= | administrator | | linuxprobe | P+YxK1QXIYrJpek5i//rPjn5SME= | administrator | +------------+------------------------------+---------------+ [root@vdevops ~]# rabbitmqadmin list vhosts +-----------+---------+ |   name    | tracing | +-----------+---------+ | /         | False   | | /my_vhost | False   | +-----------+---------+ 
rabbitmqadmin 更多使用教程参考:http://www.rabbitmq.com/management-cli.html 
 
[root@vdevops ~]# rabbitmqadmin declare user name=centos password=password tags=administrator  
user declared 
[root@vdevops ~]# rabbitmqadmin declare permission vhost=/vhost01 user=centos configure=".*" write=".*" read=".*"  
*** vhost_or_user_not_found 
[root@vdevops ~]# rabbitmqadmin declare vhost name=/vhost01  
vhost declared 
[root@vdevops ~]# rabbitmqadmin declare permission vhost=/vhost01 user=centos configure=".*" write=".*" read=".*"  
permission declared 
[root@vdevops ~]# rabbitmqadmin -V /vhost01 -u centos -p password declare queue name=my_queue01  
queue declared 
[root@vdevops ~]# rabbitmqadmin -V /vhost01 -u centos -p password publish routing_key=my_queue01 payload='Hello RabbitMQ World!' exchange=amq.default  
Message published 
[root@vdevops ~]# rabbitmqadmin -V /vhost01 -u centos -p password get queue=my_queue01 requeue=false 
+-------------+----------+---------------+-----------------------+---------------+------------------+------------+-------------+ 
<>| routing_key | exchange | message_count |        payload        | payload_bytes | payload_encoding | properties | redelivered | 
+-------------+----------+---------------+-----------------------+---------------+------------------+------------+-------------+ 
| my_queue01  |          | 0             | Hello RabbitMQ World! | 21            | string           |            | False       | 
+-------------+----------+---------------+-----------------------+---------------+------------------+------------+-------------+ 
[root@vdevops ~]# rabbitmqadmin -V /vhost01 -u centos -p password publish routing_key=my_queue01 payload='Hello LinuxProbe!' exchange=amq.default  
Message published 
[root@vdevops ~]# rabbitmqadmin -V /vhost01 -u centos -p password get queue=my_queue01 requeue=false 
+-------------+----------+---------------+-------------------+---------------+------------------+------------+-------------+ 
| routing_key | exchange | message_count |      payload      | payload_bytes | payload_encoding | properties | redelivered | 
+-------------+----------+---------------+-------------------+---------------+------------------+------------+-------------+ 
| my_queue01  |          | 0             | Hello LinuxProbe! | 17            | string           |            | False       | 
+-------------+----------+---------------+-------------------+---------------+------------------+------------+-------------+ 





作者:王辉
来源:51CTO
相关实践学习
消息队列RocketMQ版:基础消息收发功能体验
本实验场景介绍消息队列RocketMQ版的基础消息收发功能,涵盖实例创建、Topic、Group资源创建以及消息收发体验等基础功能模块。
消息队列 MNS 入门课程
1、消息队列MNS简介 本节课介绍消息队列的MNS的基础概念 2、消息队列MNS特性 本节课介绍消息队列的MNS的主要特性 3、MNS的最佳实践及场景应用 本节课介绍消息队列的MNS的最佳实践及场景应用案例 4、手把手系列:消息队列MNS实操讲 本节课介绍消息队列的MNS的实际操作演示 5、动手实验:基于MNS,0基础轻松构建 Web Client 本节课带您一起基于MNS,0基础轻松构建 Web Client
目录
相关文章
|
2月前
|
监控 前端开发 Linux
centos7系统安装部署zabbix5.0
【9月更文挑战第23天】在CentOS 7系统上部署Zabbix 5.0的步骤包括:安装MariaDB数据库及必要软件包,配置Zabbix仓库,设置数据库并导入Zabbix数据库架构,配置Zabbix服务器与前端参数,启动相关服务,并通过浏览器访问Web界面完成安装向导。
160 0
|
2月前
|
Oracle Java 关系型数据库
CentOS 7.6操作系统部署JDK实战案例
这篇文章介绍了在CentOS 7.6操作系统上通过多种方式部署JDK的详细步骤,包括使用yum安装openjdk、基于rpm包和二进制包安装Oracle JDK,并提供了配置环境变量的方法。
282 80
|
1月前
|
消息中间件 编解码 Docker
【Docker项目实战】Docker部署RabbitMQ消息中间件
【10月更文挑战第8天】Docker部署RabbitMQ消息中间件
98 1
【Docker项目实战】Docker部署RabbitMQ消息中间件
|
1月前
|
存储 Linux 开发者
虚拟机centos7.9一键部署docker
本文介绍了如何在 CentOS 7.9 虚拟机上安装 Docker 社区版 (Docker-ce-20.10.20)。通过使用阿里云镜像源,利用 `wget` 下载并配置 Docker-ce 的 YUM 仓库文件,然后通过 `yum` 命令完成安装。安装后,通过 `systemctl` 设置 Docker 开机自启并启动 Docker 服务。最后,使用 `docker version` 验证安装成功,并展示了客户端与服务器的版本信息。文中还提供了列出所有可用 Docker-ce 版本的命令。
195 0
虚拟机centos7.9一键部署docker
|
2月前
|
存储 Kubernetes 负载均衡
CentOS 7.9二进制部署K8S 1.28.3+集群实战
本文详细介绍了在CentOS 7.9上通过二进制方式部署Kubernetes 1.28.3+集群的全过程,包括环境准备、组件安装、证书生成、高可用配置以及网络插件部署等关键步骤。
460 3
CentOS 7.9二进制部署K8S 1.28.3+集群实战
|
2月前
|
NoSQL 关系型数据库 Redis
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
mall在linux环境下的部署(基于Docker容器),docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongodb、minio详细教程,拉取镜像、运行容器
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
|
2月前
|
消息中间件 Linux
centos7安装rabbitmq
centos7安装rabbitmq
|
1月前
|
消息中间件
实践部署《云消息队列RabbitMQ实践》测评
《云消息队列RabbitMQ实践》解决方案原理清晰,尤其在异步通信和解耦方面解释详尽。对初学者而言,部分术语如消息持久化、确认机制及集群性能优化可更细致。部署过程文档详实,涵盖主要环节,但插件配置等细节存在环境问题,需查阅社区资料解决。该方案展示了RabbitMQ的高吞吐量、灵活路由和可靠消息传递能力,但在高可用性和消息丢失处理上可提供更深入配置建议。适用于高并发和解耦场景,如订单处理、日志收集,有助于提升系统可扩展性。总体部署体验良好,实用性较强。
54 0
|
2月前
|
Kubernetes Linux API
CentOS 7.6使用kubeadm部署k8s 1.17.2测试集群实战篇
该博客文章详细介绍了在CentOS 7.6操作系统上使用kubeadm工具部署kubernetes 1.17.2版本的测试集群的过程,包括主机环境准备、安装Docker、配置kubelet、初始化集群、添加节点、部署网络插件以及配置k8s node节点管理api server服务器。
126 0
CentOS 7.6使用kubeadm部署k8s 1.17.2测试集群实战篇
|
2月前
|
消息中间件 Linux
linux之centos安装rabbitmq
linux之centos安装rabbitmq
下一篇
无影云桌面