一、前言
本篇文章适用范围?
- RabbitMQ 3.7
- CentOS 7
环境信息?
- CentOS 7.X
- Erlang 20.2(RabbitMQ要求是19.3-20.2.x)
- RabbitMQ 3.7.x
二、RabbitMQ安装
- 安装Erlang(19.3 )
https://cloud.tencent.com/developer/article/1333846
- 安装 socat
sudo yum install -y socat
- RPM安装
官网下载地址:https://www.rabbitmq.com/install-rpm.html
代码语言:javascript复制sudo rpm -Uvh https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.3/rabbitmq-server-3.7.3-1.el7.noarch.rpm
如果遇到erlang已安装且版本正确,但是RabbitMQ检测失败的情况 可以追加参数 —nodeps (不验证软件包依赖)
- 启动RabbitMQ服务
#启动服务
sudo systemctl start rabbitmq-server
#查看状态
sudo systemctl status rabbitmq-server
#设置为开机启动
sudo systemctl enable rabbitmq-server
三、RabbitMQ配置
- 添加用户
#添加用户
sudo rabbitmqctl add_user admin pwd
#设置用户角色
sudo rabbitmqctl set_user_tags admin administrator
#tag(administrator,monitoring,policymaker,management)
#设置用户权限(接受来自所有Host的所有操作)
sudo rabbitmqctl set_permissions -p "/" admin '.*' '.*' '.*'
#查看用户权限
sudo rabbitmqctl list_user_permissions admin
- 配置远程访问
#修改配置文件
sudo vi /etc/rabbitmq/rabbitmq.config
#保存以下内容
[
{rabbit, [{tcp_listeners, [5672]}, {loopback_users, ["admin"]}]}
].
- 重启服务
sudo systemctl restart rabbitmq-server
- 开放端口
#开放端口
sudo firewall-cmd --add-port=5672/tcp --permanent
#重新加载防火墙配置
sudo firewall-cmd --reload
备注
- RabbitMQ常用命令
# 添加用户
sudo rabbitmqctl add_user <username> <password>
# 删除用户
sudo rabbitmqctl delete_user <username>
# 修改用户密码
sudo rabbitmqctl change_password <username> <newpassword>
# 清除用户密码(该用户将不能使用密码登陆,但是可以通过SASL登陆如果配置了SASL认证)
sudo rabbitmqctl clear_password <username>
# 设置用户tags(相当于角色,包含administrator,monitoring,policymaker,management)
sudo rabbitmqctl set_user_tags <username> <tag>
# 列出所有用户
sudo rabbitmqctl list_users
# 创建一个vhosts
sudo rabbitmqctl add_vhost <vhostpath>
# 删除一个vhosts
sudo rabbitmqctl delete_vhost <vhostpath>
# 列出vhosts
sudo rabbitmqctl list_vhosts [<vhostinfoitem> ...]
# 针对一个vhosts给用户赋予相关权限;
sudo rabbitmqctl set_permissions [-p <vhostpath>] <user> <conf> <write> <read>
# 清除一个用户对vhosts的权限;
sudo rabbitmqctl clear_permissions [-p <vhostpath>] <username>
# 列出哪些用户可以访问该vhosts;
sudo rabbitmqctl list_permissions [-p <vhostpath>]
# 列出用户访问权限;
sudo rabbitmqctl list_user_permissions <username>
- 本文参考
https://www.rabbitmq.com/download.html
https://github.com/judasn/Linux-Tutorial/blob/master/RabbitMQ-Install-And-Settings.md
http://blog.csdn.net/zyz511919766/article/details/42292655