官方文档: Downloading and Installing RabbitMQ
RabbitMQ 与 Erlang 的版本对应: Erlang/OTP for RabbitMQ
Erlang 下载地址: Erlang
系统环境
JDK 1.8
Centos7-64位
Erlang-OTP 23
RabbitMQ-3.9.3
安装 JDK(略)
安装 Erlang
添加 Erlang YUM 镜像仓库
1
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
查看所有可用的 erlang 版本
1
yum list erlang --showduplicates |sort -r
安装 Erlang 23.3.4 版本
1
yum install -y erlang-23.3.4.5-1.el7.x86_64
检查 erlang 的版本
1
2
3
4
5[root@redis ~]# erl
Erlang/OTP 23 [erts-11.2.2.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Eshell V11.2.2.4 (abort with ^G)
1>
安装 RabbitMQ
导入 RPM 需要的 key
1
2
3
4
5## primary RabbitMQ signing key
rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
## RabbitMQ server repository
rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey添加 RabbitMQ YUM 镜像仓库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23[rabbitmq_server]
name=rabbitmq_server
baseurl=https://packagecloud.io/rabbitmq/rabbitmq-server/el/7/$basearch
repo_gpgcheck=1
gpgcheck=1
enabled=1
# PackageCloud's repository key and RabbitMQ package signing key
gpgkey=https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
[rabbitmq_server-source]
name=rabbitmq_server-source
baseurl=https://packagecloud.io/rabbitmq/rabbitmq-server/el/7/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300查看可用的 RabbitMQ 版本
1
yum list rabbitmq-server --showduplicates |sort -r
安装 RabbitMQ 3.9.3 版本
1
2
3yum makecache fast
yum install -y socatsyst logrotate
yum install -y rabbitmq-server-3.9.3-1.el7启动 RabbitMQ 并配置开机启动
1
systemctl enable --now rabbitmq-server.service
RabbitMq 无法访问
http://localhost:1567,Failed to start Ranch listener {acceptor,{0,0,0,0,0,0,0,0},5672
,启动失败时,检查端口是否被占用;如果无法访问 RabbitMQ web 页面,并且服务器上显示 15672 端口未监听,则需要开启 rabbitmq_management 服务,如下
1
rabbitmq-plugins enable rabbitmq_management
访问 RabbitMQ
浏览器访问
http://192.168.64.16:15672/
,输入默认账号/密码guest/guest
,但是如果使用guest
登录,会出现报错如下:这是因为 RabbitMQ 3.3 以后,guest账号只能在本机登录。
创建 admin 用户并授权
1
2
3rabbitmqctl add_user admin 123456 # 添加用户
rabbitmqctl set_user_tags admin administrator # 设置用户标签
rabbitmqctl set_permissions -p / admin "." "." ".*" # 设置用户权限重启 RabbitMQ
1
systemctl restart rabbitmq-server.service
使用 admin 账号登录 RabbitMQ
RabbitMQ 常用命令
Rabbitmq 控制台命令帮助信息查看
1 | rabbitmqctl --help |
以下是常用的操作命令
添加用户 wms
1
rabbitmqctl add_user wms 123456
设置用户权限
1
rabbitmqctl set_permissions -p / wms "." "." ".*"
设置用户角色
1
rabbitmqctl set_user_tags wms management
查看权限
1
2
3
4
5
6rabbitmqctl list_permissions
Listing permissions for vhost "/" ...
user configure write read
wms . . .*
admin . . .*
guest .* .* .*