安装
主机部署
http://www.rabbitmq.com/install-rpm.html
选择RPM包下载,选择对应平台,本次安装在CentOS 7,其它平台类似。
由于使用了erlang语言开发,所以需要erlang的包。erlang和RabbitMQ的兼容性
参考https://www.rabbitmq.com/which-erlang.html#compatibility-matrix
下载rabbitmq-server-3.7.16-1.el7.noarch.rpm、erlang-21.3.8.6-1.el7.x86_64.rpm。socat在CentOS中源中有
# yum install erlang-21.3.8.6-1.el7.x86_64.rpm rabbitmq-server-3.7.16-1.el7.noarch.rpm
或者在线安装
https://www.rabbitmq.com/install-rpm.html#yum-legacy
新建yum源
$ vim /etc/yum.repos.d/rabbitmq.repo
##
## Zero dependency Erlang
##
[rabbitmq_erlang]
name=rabbitmq_erlang
baseurl=https://packagecloud.io/rabbitmq/erlang/el/7/$basearch
repo_gpgcheck=0
gpgcheck=0
enabled=1
# PackageCloud's repository key and RabbitMQ package signing key
gpgkey=https://packagecloud.io/rabbitmq/erlang/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_erlang-source]
name=rabbitmq_erlang-source
baseurl=https://packagecloud.io/rabbitmq/erlang/el/7/SRPMS
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
##
## RabbitMQ server
##
[rabbitmq_server]
name=rabbitmq_server
baseurl=https://packagecloud.io/rabbitmq/rabbitmq-server/el/7/$basearch
repo_gpgcheck=0
gpgcheck=0
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=0
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
更新所有软件
$ yum update -y
安装依赖
$ yum install socat logrotate -y
安装
$ yum install erlang rabbitmq-server -y
容器部署
docker-compose容器编排清单
version: '3'
services:
rabbitmq:
image: rabbitmq:3.11.7-management
restart: always
ports:
- "15672:15672"
- "5672:5672"
container_name: rabbitmq
environment:
RABBITMQ_DEFAULT_USER: admin
RABBITMQ_DEFAULT_PASS: admin
volumes:
- ./data/:/var/lib/rabbitmq
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
启动插件
$ docker-compose exec rabbitmq rabbitmq-plugins enable rabbitmq_management rabbitmq_mqtt rabbitmq_web_mqtt
配置
http://www.rabbitmq.com/configure.html#config-location
环境变量
使用系统环境变量,如果没有使用rabbitmq-env.conf 中定义环境变量,否则使用缺省值
RABBITMQ_NODE_IP_ADDRESS the empty string, meaning that it should bind to all network interfaces.
RABBITMQ_NODE_PORT 5672
RABBITMQ_DIST_PORT RABBITMQ_NODE_PORT + 20000 内部节点和客户端工具通信用
RABBITMQ_CONFIG_FILE 配置文件路径默认为/etc/rabbitmq/rabbitmq
环境变量文件,可以不配置
插件管理
列出所有可用插件
$ rabbitmq-plugins list
启动WEB管理插件,会依赖启用其它几个插件。
$ rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
set 3 plugins.
[E ] rabbitmq_management 3.7.16
[e ] rabbitmq_management_agent 3.7.16
[e ] rabbitmq_web_dispatch 3.7.16
启动服务
$ systemctl start rabbitmq-server
启动中,可能出现下面的错误
Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces
就是这个文件的权限问题,修改属主、属组为rabbitmq即可
$ chown rabbitmq.rabbitmq /var/lib/rabbitmq/.erlang.cookie: eacces
服务启动成功
$ ss -ntlp| grep 5672
LISTEN 0 128 *:15672 *:* users:(("beam.smp",pid=90005,fd=35))
LISTEN 0 128 *:25672 *:* users:(("beam.smp",pid=90005,fd=18))
LISTEN 0 128 [::]:5672 [::]:* users:(("beam.smp",pid=90005,fd=33))
用户管理
新建管理员用户
使用guest/guest只能本地地登录,远程登录会报错
rabbitmqctl
rabbitmqctl [-n <node>][-t timeout] [-l][-q] <command> [<command options>]
General options:
-n node
-q, --quiet
-t,--timeout timeout
-l longnames
Commands:
add_user <username> <password> 添加用户
list_users 列出用户
delete_user username 删除用户
change_password <username> <password> 修改用户名、密码
set_user_tags <username> <tag> [...] 设置用户tag
list_user_permissions <username> 列出用户权限
添加用户:
rabbitmqctl add_user username password
删除用户:
rabbitmqctl delete_user username
更改密码:
rabbitmqctl change_password username newpassword
设置权限Tags,其实就是分配组
rabbitmqctl set_user_tags username tag
查看所有用户
rabbitmqctl list_users
设置hxg用户为管理员tag后登录
$ rabbitmqctl add_user hxg hxg
Adding user "hxg" ...
$ rabbitmqctl list_users
Listing users ...
hxg []
guest [administrator]
$ rabbitmqctl set_user_tags hxg administrator
Setting tags for user "hxg" to [administrator] ...
$ rabbitmqctl list_users
Listing users ...
hxg [administrator]
guest [administrator]
登录
开始登录WEB界面,http://10.0.0.5:15672
tag的意义如下
administrator 可以管理用户、权限、虚拟主机。
基本信息
虚拟主机
/为确实虚拟主机
缺省虚拟主机,默认只能是guest用户在本机连接。上图新建的用户hxg默认无法访问任何虚拟主机。
新建虚拟主键
Pika库
Pika是纯Python实现的支持AMQP协议的库
$ pip install pika