RabbitMQ
安装部署 - MacOS
https://www.rabbitmq.com/install-homebrew.html
安装部署 - RHEL
先安装ErLang
bash
sudo yum install -y erlang-26.2.5-1.el9.x86_64.rpm
sudo yum install -y erlang-26.2.5-1.el8.x86_64.rpm
sudo yum install -y erlang-26.2.5-1.el7.x86_64.rpm
安装RabbitMQ
bash
sudo yum install -y rabbitmq-server-3.13.3-1.el8.noarch.rpm
系统服务
bash
# 开机启动
sudo systemctl enable rabbitmq-server.service
# 禁用开机启动
sudo systemctl disable rabbitmq-server.service
# 启动服务
sudo systemctl start rabbitmq-server.service
# 重启服务
sudo systemctl restart rabbitmq-server.service
# 关闭服务
sudo systemctl stop rabbitmq-server.service
# 查看状态
sudo systemctl status rabbitmq-server.service
检查
bash
# 查看安装路径
whereis rabbitmq
# 检查端口
netstat -lanp | grep 5672
netstat -lanp | grep 15672
netstat -lanp | grep 25672
# 查看进程
ps -ef | grep rabbitmq
常用操作
bash
# 查看当前状态
sudo rabbitmqctl status
# 启用管理插件
sudo rabbitmq-plugins enable rabbitmq_management
账号授权
bash
# 添加账号
sudo rabbitmqctl add_user admin admin
# 授权
sudo rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
# 授予管理员角色
sudo rabbitmqctl set_user_tags admin administrator
# 安全风险考虑,建议删除默认账号
sudo rabbitmqctl delete_user guest
VHost
bash
# 创建
sudo rabbitmqctl add_vhost platform
# 授权
sudo rabbitmqctl set_permissions -p "platform" admin ".*" ".*" ".*"
sudo rabbitmqctl set_permissions -p "platform" guest ".*" ".*" ".*"
重置
bash
# 创建
sudo rabbitmqctl stop_app
sudo rabbitmqctl reset
sudo rabbitmqctl start_app
# 授权
sudo rabbitmqctl set_permissions -p "platform" admin ".*" ".*" ".*"
sudo rabbitmqctl set_permissions -p "platform" guest ".*" ".*" ".*"
卸载
bash
# 卸载
#
# 1. Erlang
#
yum list | grep erlang
#
yum -y remove erlang-*
# 查找安装目录
whereis erlang
# 删除安装目录
rm -rf /usr/lib64/erlang
#
# 2. rabbitmq
#
yum list | grep rabbitmq
#
yum -y remove rabbitmq-server.noarch
WSL
默认情况下,RabbitMQ在WSL里面只绑定了IPv6地址,这样子导致无法连接,所以需要在配置文件里面增加配置项来绑定IPv4地址。
bash
sudo vi /etc/rabbitmq/rabbitmq.conf
增加以下内容
bash
listeners.tcp.default=127.0.0.1:5672
安装部署 - Windows
RabbitMQ依赖于Erlang,所以需要先安装Erlang。
安装目录
bash
|---D
|---|---Tools --
|---|---|---RabbitMQ -- RabbitMQ安装目录
|---|---|---ErLang -- ErLang安装目录
把ErLang和RabbitMQ安装到对应的目录下,并设置好环境变量
bash
%ERLANG_HOME%=D:\Tools\Erlang
%RABBITMQ_HOME%=D:\Tools\RabbitMQ
%PATH%=%PATH%;D:\Tools\RabbitMQ\sbin;D:\Tools\Erlang\bin;
常用操作
bash
# 安装系统服务
rabbitmq-service.bat install
# 删除系统服务
rabbitmq-service.bat remove
# 启动系统服务
rabbitmq-service.bat start
# 停止系统服务
rabbitmq-service.bat stop
# 检查当前状态
rabbitmqctl.bat status
# 启用管理插件
rabbitmq-plugins.bat enable rabbitmq_management
# 添加用户
rabbitmqctl.bat add_user admin admin
# 删除用户
rabbitmqctl.bat delete_user guest
# 授予管理员角色
rabbitmqctl.bat set_user_tags admin administrator
# 创建虚拟主机
sudo rabbitmqctl add_vhost platform
# 虚拟主机授权
sudo rabbitmqctl set_permissions -p "platform" admin ".*" ".*" ".*"
sudo rabbitmqctl set_permissions -p "platform" guest ".*" ".*" ".*"