RabbitMQ

type
status
date
slug
summary
tags
category
icon
password

安装RabbitMQ

安装前配置

  1. 修改hostname(方便后续的集群搭建),然后重启系统(reboot)
  1. 关闭防火墙

安装前置依赖

安装RabbitMQ之前,需要先安装其依赖:erlang和socat
  1. 安装erlang
  • 下载erlang的rpm包,下载地址为:
  • 下载完成后,将rpm包上传至服务器的/tmp目录下
notion image
  • 使用以下指令进行安装
notion image
  • 使用如下指令查看erlang是否安装成功
显示如下信息就表示安装成功
 
notion image
  1. 安装socat
  • 将yum源配置成阿里的yum源
  • 安装socat
notion image

安装RabbitMQ

  1. 下载rabbitmq的rpm包
  1. 将rabbitmq的rpm包上传至linux系统的/tmp目录下
notion image
  1. 使用如下命令安装
notion image
  1. 查看安装情况
notion image

启动RabbitMQ

notion image
  • 其他常用操作

配置web管理页面

  1. 安装插件
报错信息如下:
notion image
其解决方式
  • 修改/etc/hosts文件为以下内容
notion image
  • 重启rabbitmq服务
notion image
  • 再次执行安装插件看看
notion image
  1. 重启rabbitmq服务
  1. 访问web控制台
notion image
  1. 登录web控制台
可以使用默认的guest/guest用户登录,但是默认情况下只允许localhost本地登录,远程访问是无法登录的
notion image
可以创建一个管理员账户来登录
使用admin/admin登录成功
notion image

RabbitMQ集群的搭建

搭建普通集群

  1. 在3台机器中分别都安装rabbitmq-server
  • rabbit@chaoy
notion image
  • rabbit@worker1
notion image
  • rabbit@worker2
notion image
  1. 将rabbit@chaoy主节点中/var/lib/rabbitmq/.erlang.cookie文件中的内容分别复制并替换rabbit@worker1和rabbit@worker2这两个从节点中/var/lib/rabbitmq/.erlang.cookie文件中的内容
.erlang.cookie是一个隐藏文件,使用ls -a进行查看
notion image
  1. 将rabbit@worker1和rabbit@worker2这两个服务加入到rabbit@chaoy的集群中
  • 在rabbit@worker1中执行如下命令
notion image
  • 在rabbit@worker2中执行如下命令
notion image
  1. 查看集群的状态
notion image

搭建镜像集权

  1. 配置镜像策略
针对固定的虚拟主机(virtual host)配置镜像策略
rabbitmq中的virtual host可以类比mysql中的库,针对每个虚拟主机,可以配置不同的权限、策略等,并且不同虚拟主机之间的数据是相互隔离的
  • 在主节点(rabbit@chaoy)创建一个/mirror的虚拟主机,然后再添加对应的镜像策略
notion image

测试集群

  1. 创建队列
在任意一个节点创建一个队列
notion image
notion image
  1. 发送消息
notion image
notion image
  1. 接受消息
notion image

RabbitMQ的常用编程模型

基础概念

  • 虚拟主机(virtual host)
    • 交换机(Exchange)
    • 队列(Queue)
    • 路由(routing)
  • 连接Connection
    • 信道(Channel)

原生API

 
Prev
Minio
Next
Django开发
Loading...
Article List