RabbitMQ单机安装

2020-11-24 10:33:06 浏览数 (1)

RabbitMQ介绍

1.RabbitMQ简介

官网:https://www.rabbitmq.com

RabbitMQ是一款在全球范围内使用非常广泛的开源消息队列中间件。它轻量级、易部署、并支持多种协议。它基于Erlang开发,天生拥有高并发的能力。

RabbitMQ相关术语 生产者----产生消息的进程或服务 消费者----接收消息的进程或服务 队列----RabbitMQ是消息队列中间件,而真正储存消息数据的就是队列,队列可以有很多。 交换器----类似于网络设备交换机,它可以根据不同的关键字,将消息发送到不同的队列。

虚拟主机: 虚拟主机类似于Apache的虚拟主机,如果没有虚拟主机,当RabbitMQ中的数据越来越庞大,队列越来越多,随之而来的是令人头痛的管理问题,比如队列、交换器命名冲突,它们相互影响等等。虚拟主机能够解决这些问题,而不需要我们部署多个RabbitMQ来负责不同的业务。 虚拟主机提供了资源的逻辑分组和分隔,每一个虚拟主机本质上是mini版的RabbitMQ服务器,他们有用自己的连接、队列、绑定、交换器,更重要的是有用自己的权限机制,这有点类似服务器和运行在服务器上的虚拟机一样。

2.Centos7上安装RabbitMQ(单机)

官方文档: https://www.rabbitmq.com/install-rpm.html

2.1 安装erlang

代码语言:javascript复制
[root@linux-01 ~]# curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
Detected operating system as centos/7.
Checking for curl...
Detected curl...
Downloading repository file: https://packagecloud.io/install/repositories/rabbitmq/erlang/config_file.repo?os=centos&dist=7&source=script
done.
Installing pygpgme to verify GPG signatures...
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                                                                                     | 3.7 kB  00:00:00
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; 拒绝连接"
正在尝试其它镜像。
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; 未知的错误"
正在尝试其它镜像。
base                                                                                                                                                                                     | 3.6 kB  00:00:00
epel                                                                                                                                                                                     | 4.7 kB  00:00:00
extras                                                                                                                                                                                   | 2.9 kB  00:00:00
jenkins                                                                                                                                                                                  | 2.9 kB  00:00:00
rabbitmq_erlang-source/signature                                                                                                                                                         |  819 B  00:00:00
从 https://packagecloud.io/rabbitmq/erlang/gpgkey 检索密钥
导入 GPG key 0xDF309A0B:
 用户ID     : "https://packagecloud.io/rabbitmq/erlang (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>"
 指纹       : 2ebd e413 d3ce 5d35 bcd1 5b7c 71c6 3471 df30 9a0b
 来自       : https://packagecloud.io/rabbitmq/erlang/gpgkey
rabbitmq_erlang-source/signature                                                                                                                                                         |  951 B  00:00:00 !!!
updates                                                                                                                                                                                  | 2.9 kB  00:00:00
(1/5): jenkins/primary_db                                                                                                                                                                |  35 kB  00:00:01
(2/5): updates/7/x86_64/primary_db                                                                                                                                                       | 4.5 MB  00:00:06
(3/5): epel/x86_64/group_gz                                                                                                                                                              |  95 kB  00:00:19
(4/5): epel/x86_64/updateinfo                                                                                                                                                            | 1.0 MB  00:03:20
epel/x86_64/primary_db         FAILED                                                     49% [======================================-                                        ]   40 B/s | 6.1 MB  46:27:30 ETA
https://mirror.yer.az/fedora-epel/7/x86_64/repodata/f33d3153c04f90e1f73f7b160861324a276a8b4dac0fdf2b0b5d125a7bdda55e-primary.sqlite.bz2: [Errno 12] Timeout on https://mirror.yer.az/fedora-epel/7/x86_64/repodata/f33d3153c04f90e1f73f7b160861324a276a8b4dac0fdf2b0b5d125a7bdda55e-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
epel/x86_64/primary_db         FAILED                                                     84% [==================================================================-            ]  2.3 B/s |  11 MB 247:11:05 ETA
https://download.nus.edu.sg/mirror/epel/7/x86_64/repodata/f33d3153c04f90e1f73f7b160861324a276a8b4dac0fdf2b0b5d125a7bdda55e-primary.sqlite.bz2: [Errno 12] Timeout on https://download.nus.edu.sg/mirror/epel/7/x86_64/repodata/f33d3153c04f90e1f73f7b160861324a276a8b4dac0fdf2b0b5d125a7bdda55e-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
epel/x86_64/primary_db         FAILED
http://epel.mirror.angkasa.id/pub/epel/7/x86_64/repodata/f33d3153c04f90e1f73f7b160861324a276a8b4dac0fdf2b0b5d125a7bdda55e-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to epel.mirror.angkasa.id:80;Connection refused"
正在尝试其它镜像。
(5/5): epel/x86_64/primary_db                                                                                                                                                            | 6.9 MB  00:00:08
rabbitmq_erlang-source/primary                                                                                                                                                           |  175 B  00:00:04
软件包 pygpgme-0.3-9.el7.x86_64 已安装并且是最新版本
无须任何处理
Installing yum-utils...
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
rabbitmq_erlang-source/signature                                                                                                                                                         |  819 B  00:00:00
rabbitmq_erlang-source/signature                                                                                                                                                         |  951 B  00:00:00 !!!
正在解决依赖关系
--> 正在检查事务
---> 软件包 yum-utils.noarch.0.1.1.31-54.el7_8 将被 安装
--> 正在处理依赖关系 python-kitchen,它被软件包 yum-utils-1.1.31-54.el7_8.noarch 需要
--> 正在检查事务
---> 软件包 python-kitchen.noarch.0.1.1.1-5.el7 将被 安装
--> 正在处理依赖关系 python-chardet,它被软件包 python-kitchen-1.1.1-5.el7.noarch 需要
--> 正在检查事务
---> 软件包 python-chardet.noarch.0.2.2.1-3.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================================================================================================================================================
 Package                                              架构                                         版本                                                     源                                             大小
================================================================================================================================================================================================================
正在安装:
 yum-utils                                            noarch                                       1.1.31-54.el7_8                                          updates                                       122 k
为依赖而安装:
 python-chardet                                       noarch                                       2.2.1-3.el7                                              base                                          227 k
 python-kitchen                                       noarch                                       1.1.1-5.el7                                              base                                          267 k

事务概要
================================================================================================================================================================================================================
安装  1 软件包 ( 2 依赖软件包)

总下载量:616 k
安装大小:2.8 M
Downloading packages:
(1/3): python-chardet-2.2.1-3.el7.noarch.rpm                                                                                                                                             | 227 kB  00:00:00
(2/3): python-kitchen-1.1.1-5.el7.noarch.rpm                                                                                                                                             | 267 kB  00:00:00
(3/3): yum-utils-1.1.31-54.el7_8.noarch.rpm                                                                                                                                              | 122 kB  00:00:00
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                            812 kB/s | 616 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : python-chardet-2.2.1-3.el7.noarch                                                                                                                                                           1/3
  正在安装    : python-kitchen-1.1.1-5.el7.noarch                                                                                                                                                           2/3
  正在安装    : yum-utils-1.1.31-54.el7_8.noarch                                                                                                                                                            3/3
  验证中      : python-kitchen-1.1.1-5.el7.noarch                                                                                                                                                           1/3
  验证中      : yum-utils-1.1.31-54.el7_8.noarch                                                                                                                                                            2/3
  验证中      : python-chardet-2.2.1-3.el7.noarch                                                                                                                                                           3/3

已安装:
  yum-utils.noarch 0:1.1.31-54.el7_8

作为依赖被安装:
  python-chardet.noarch 0:2.2.1-3.el7                                                                    python-kitchen.noarch 0:1.1.1-5.el7

完毕!
Generating yum cache for rabbitmq_erlang...
导入 GPG key 0xDF309A0B:
 用户ID     : "https://packagecloud.io/rabbitmq/erlang (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>"
 指纹       : 2ebd e413 d3ce 5d35 bcd1 5b7c 71c6 3471 df30 9a0b
 来自       : https://packagecloud.io/rabbitmq/erlang/gpgkey
Generating yum cache for rabbitmq_erlang-source...

The repository is setup! You can now install packages.

## 查看rabbitmq_erlang.repo中的内容信息
[root@linux-01 ~]# cat  /etc/yum.repos.d/rabbitmq_erlang.repo
[rabbitmq_erlang]
name=rabbitmq_erlang
baseurl=https://packagecloud.io/rabbitmq/erlang/el/7/$basearch
repo_gpgcheck=1
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_erlang-source]
name=rabbitmq_erlang-source
baseurl=https://packagecloud.io/rabbitmq/erlang/el/7/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300


[root@linux-01 ~]# yum install -y erlang
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: my.mirrors.thegigabit.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
https://packagecloud.io/rabbitmq/erlang/el/7/x86_64/repodata/repomd.xml: [Errno 12] Timeout on https://d28dx6y1hfq314.cloudfront.net/828/1039/el/7/x86_64/repodata/b52156a6708c0cfc469ea0e158e7bb8917beb3ce5f4bbca173a718f7d9d99373-repomd.xml?t=1605536717_077a01b9c029cb1020d6222229967e2ac128e797: (28, 'Operation timed out after 30745 milliseconds with 0 out of 0 bytes received')
正在尝试其它镜像。
rabbitmq_erlang/x86_64/signature                                                                                                                                                         |  833 B  00:00:00
rabbitmq_erlang/x86_64/signature                                                                                                                                                         | 1.0 kB  00:00:00 !!!
rabbitmq_erlang-source/signature                                                                                                                                                         |  819 B  00:00:00
rabbitmq_erlang-source/signature                                                                                                                                                         |  951 B  00:00:00 !!!
正在解决依赖关系
--> 正在检查事务
---> 软件包 erlang.x86_64.0.23.1.2-1.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================================================================================================================================================
 Package                                       架构                                          版本                                                  源                                                      大小
================================================================================================================================================================================================================
正在安装:
 erlang                                        x86_64                                        23.1.2-1.el7                                          rabbitmq_erlang                                         19 M

事务概要
================================================================================================================================================================================================================
安装  1 软件包

总下载量:19 M
安装大小:34 M
Downloading packages:
erlang-23.1.2-1.el7.x86_64.rpm                                                                                                                                                           |  19 MB  00:19:40
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : erlang-23.1.2-1.el7.x86_64                                                                                                                                                                  1/1
  验证中      : erlang-23.1.2-1.el7.x86_64                                                                                                                                                                  1/1

已安装:
  erlang.x86_64 0:23.1.2-1.el7

完毕!

2.2 安装rabbitmq

代码语言:javascript复制
[root@linux-01 ~]# rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
[root@linux-01 ~]# rpm --import https://packagecloud.io/gpg.key
[root@linux-01 ~]# rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc

## 添加rabbitmsq的yum源
[root@linux-01 ~]# vi /etc/yum.repos.d/rabbitmq.repo

[bintray-rabbitmq-server]
name=bintray-rabbitmq-rpm
baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.8.x/el/7/
gpgcheck=0
repo_gpgcheck=0
enabled=1


[root@linux-01 ~]# yum install -y rabbitmq-server
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
bintray-rabbitmq-server                                                                                                                                                                  | 1.3 kB  00:00:00
rabbitmq_erlang/x86_64/signature                                                                                                                                                         |  833 B  00:00:00
rabbitmq_erlang/x86_64/signature                                                                                                                                                         | 1.0 kB  00:00:00 !!!
rabbitmq_erlang-source/signature                                                                                                                                                         |  819 B  00:00:00
rabbitmq_erlang-source/signature                                                                                                                                                         |  951 B  00:00:00 !!!
bintray-rabbitmq-server/primary                                                                                                                                                          | 5.8 kB  00:00:02
bintray-rabbitmq-server                                                                                                                                                                                   10/10
正在解决依赖关系
--> 正在检查事务
---> 软件包 rabbitmq-server.noarch.0.3.8.9-1.el7 将被 安装
--> 正在处理依赖关系 socat,它被软件包 rabbitmq-server-3.8.9-1.el7.noarch 需要
--> 正在检查事务
---> 软件包 socat.x86_64.0.1.7.3.2-2.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================================================================================================================================================
 Package                                            架构                                      版本                                             源                                                          大小
================================================================================================================================================================================================================
正在安装:
 rabbitmq-server                                    noarch                                    3.8.9-1.el7                                      bintray-rabbitmq-server                                     15 M
为依赖而安装:
 socat                                              x86_64                                    1.7.3.2-2.el7                                    base                                                       290 k

事务概要
================================================================================================================================================================================================================
安装  1 软件包 ( 1 依赖软件包)

总下载量:15 M
安装大小:16 M
Downloading packages:
(1/2): socat-1.7.3.2-2.el7.x86_64.rpm                                                                                                                                                    | 290 kB  00:00:00
(2/2): rabbitmq-server-3.8.9-1.el7.noarch.rpm                                                                                                                                            |  15 MB  00:08:02
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                             32 kB/s |  15 MB  00:08:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : socat-1.7.3.2-2.el7.x86_64                                                                                                                                                                  1/2
  正在安装    : rabbitmq-server-3.8.9-1.el7.noarch                                                                                                                                                          2/2
  验证中      : socat-1.7.3.2-2.el7.x86_64                                                                                                                                                                  1/2
  验证中      : rabbitmq-server-3.8.9-1.el7.noarch                                                                                                                                                          2/2

已安装:
  rabbitmq-server.noarch 0:3.8.9-1.el7

作为依赖被安装:
  socat.x86_64 0:1.7.3.2-2.el7

完毕!

2.3 启动rabbitmq

代码语言:javascript复制
[root@linux-01 ~]# systemctl start rabbitmq-server
[root@linux-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:25672           0.0.0.0:*               LISTEN      7516/beam.smp
tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN      7646/epmd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      6467/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      6742/master
tcp6       0      0 :::5672                 :::*                    LISTEN      7516/beam.smp
tcp6       0      0 :::8080                 :::*                    LISTEN      6900/java
tcp6       0      0 :::4369                 :::*                    LISTEN      7646/epmd
tcp6       0      0 :::22                   :::*                    LISTEN      6467/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      6742/master
[root@linux-01 ~]# ps -ef |grep rabbit
rabbitmq   7516      1 30 23:02 ?        00:00:10 /usr/lib64/erlang/erts-11.1.2/bin/beam.smp -W w -K true -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -- -root /usr/lib64/erlang -progname erl -- -home /var/lib/rabbitmq -- -pa  -noshell -noinput -s rabbit boot -boot start_sasl -lager crash_log false -lager handlers []
rabbitmq   7621   7516  0 23:02 ?        00:00:00 erl_child_setup 32768
rabbitmq   7646      1  0 23:02 ?        00:00:00 /usr/lib64/erlang/erts-11.1.2/bin/epmd -daemon
rabbitmq   7669   7621  0 23:02 ?        00:00:00 inet_gethost 4
rabbitmq   7670   7669  0 23:02 ?        00:00:00 inet_gethost 4
root       7688   7021  0 23:02 pts/0    00:00:00 grep --color=auto rabbit

2.4 开启RabbitMQ网页访问

rabbitmq监听的端口是4369和25672,如果需要访问RabbitMQ的web控制台还需要安装一个插件rabbitmq_management。安装好这个插件后,RabbitMQ网页访问端口是15672,可以通过netstat查看监听端口。

代码语言:javascript复制
[root@linux-01 ~]# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@linux-01:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@linux-01...
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

started 3 plugins.

[root@linux-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:25672           0.0.0.0:*               LISTEN      7516/beam.smp
tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN      7646/epmd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      6467/sshd
tcp        0      0 0.0.0.0:15672           0.0.0.0:*               LISTEN      7516/beam.smp
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      6742/master
tcp6       0      0 :::5672                 :::*                    LISTEN      7516/beam.smp
tcp6       0      0 :::8080                 :::*                    LISTEN      6900/java
tcp6       0      0 :::4369                 :::*                    LISTEN      7646/epmd
tcp6       0      0 :::22                   :::*                    LISTEN      6467/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      6742/master

可以使用ip:port形式访问RabbitMQ,使用的用户名是:guest,密码guest。发现这个用户名只可以在localhost访问,可以通过nginx反向代理实现访问,如下。

代码语言:javascript复制
[root@linux-01 ~]# cd /usr/local/nginx/conf/vhost/
[root@linux-01 vhost]# vim ra.ceshi.com.conf

server {
        listen 80;
        server_name ra.ceshi.com;

        location /
        {
            proxy_pass http://127.0.0.1:15672;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}
[root@linux-01 vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@linux-01 vhost]# /usr/local/nginx/sbin/nginx -s reload

修改密码需要进入RabbitMQ上修改,如下图:

3.rabbitmq常用命令

3.1 虚拟机管理

  • rabbitmqctl list_vhosts #列出所有的虚拟主机
  • rabbitmqctl add_vhost <虚拟主机名字> #创建虚拟主机 如:rabbitmqctl add_vhost aming #创建aming虚拟主机
  • rabbitmqctl delete_vhost <虚拟主机名字> #删除虚拟主机,注意vhost不要加s。
代码语言:javascript复制
[root@linux-01 vhost]# rabbitmqctl list_vhosts
Listing vhosts ...
name
/
[root@linux-01 vhost]# rabbitmqctl add_vhost  ceshi
Adding vhost "ceshi" ...
[root@linux-01 vhost]# rabbitmqctl list_vhosts
Listing vhosts ...
name
/
ceshi
[root@linux-01 vhost]# rabbitmqctl delete_vhost  ceshi
Deleting vhost "ceshi" ...
[root@linux-01 vhost]# rabbitmqctl list_vhosts
Listing vhosts ...
name
/
[root@linux-01 vhost]#

3.2 用户管理

3.2.1 用户的增删改密

  • rabbitmqctl add_user #创建用户 如:rabbitmqctl add_user user1 user1_passwd #创建user1用户,密码为user1_passwd
  • rabbitmqctl list_users #列出所有用户
  • rabbitmqctl change_password #更改用户密码 如:rabbitmqctl change_password user1 new_passwd #更改user1的密码为new_passwd
  • rabbitmqctl delete_user #删除用户
  • rabbitmqctl clear_password #清除用户密码
代码语言:javascript复制
[root@linux-01 vhost]# rabbitmqctl add_user  ceshi ceshi
Adding user "ceshi" ...
[root@linux-01 vhost]#

添加一个ceshi用户来访问rabbitmq,创建好发现没有权限访问,这个是没有给这个用户添加权限,可以登录guest用户来查看是否有此用户,发现已经有此用户,如下图。

代码语言:javascript复制
## 修改ceshi用户的密码
[root@linux-01 vhost]# rabbitmqctl change_password  ceshi ceshi1
Changing password for user "ceshi" ...
[root@linux-01 vhost]# rabbitmqctl add_user  ceshi1  ceshi1
Adding user "ceshi1" ...
## 查看rabbitmq都有哪些用户
[root@linux-01 vhost]# rabbitmqctl list_users
Listing users ...
user	tags
ceshi1	[]
guest	[administrator]
ceshi	[]
代码语言:javascript复制
## 清楚掉ceshi1用户的密码,在rabbitmq控制台上可以看到ceshi1用户的密码是空的圈,如下图
[root@linux-01 vhost]# rabbitmqctl  clear_password ceshi1
Clearing password for user "ceshi1" ...
代码语言:javascript复制
## 删除用户,可以看到控制台上的用户会同步删除,其实在控制台也是可以添加用户和密码,包含tags
[root@linux-01 vhost]# rabbitmqctl delete_user ceshi1
Deleting user "ceshi1" ...

3.2.2用户的tags

(1) 超级管理员(administrator) 可登陆管理控制台(启用management plugin的情况下),可查看所有的信息,并且可以对用户,策略(policy)进行操作。

(2) 监控者(monitoring) 可登陆管理控制台(启用management plugin的情况下),同时可以查看rabbitmq节点的相关信息(进程数,内存使用情况,磁盘使用情况等)

(3) 策略制定者(policymaker) 可登陆管理控制台(启用management plugin的情况下), 同时可以对policy进行管理。但无法查看节点的相关信息。

(4) 普通管理者(management) 仅可登陆管理控制台(启用management plugin的情况下),无法看到节点信息,也无法对策略进行管理。

(5) 其他 无法登陆管理控制台,通常就是普通的生产者和消费者。

  • rabbitmqctl set_user_tags #赋予用户某个角色 如:rabbitmqctl set_user_tags user1 managemnet #赋予user1用户management角色 rabbitmqctl set_user_tags user2 monitoring management #同时赋予多个角色
  • rabbitmqctl set_permissions -p #给用户设置权限 如:rabbitmqctl set_permissions -p vhost1 user1 ‘.’ '.’ ‘.*’ #针对vhost1虚拟主机给user1用户设置所有的配置、读写queue和exchange的权限。 说明:用户权限指的是用户对exchange,queue的操作权限,包括配置权限,读写权限。配置权限会影响到exchange,queue的声明和删除。读写权限影响到从queue里取消息,向exchange发送消息以及queue和exchange的绑定(bind)操作。例如: 将queue绑定到某exchange上,需要具有queue的可写权限,以及exchange的可读权限;向exchange发送消息需要具有exchange的可写权限;从queue里取数据需要具有queue的可读权限。
  • rabbitmqctl list_user_permissions #列出某用户的权限,即该用户对哪个虚拟主机有权限
  • rabbitmqctl list_permissions -p #列出指定虚拟主机下所有用户的权限,即哪些用户对该虚拟主机有权限
  • rabbitmqctl clear_permissions -p #清除某用户在指定虚拟机上的授权 如:rabbitmqctl clear_permissions -p vhost1 user1
代码语言:javascript复制
```bash
## 给ceshi用户添加tags 
[root@linux-01 vhost]# rabbitmqctl set_user_tags ceshi managemnet
Setting tags for user "ceshi" to [managemnet] ...
代码语言:javascript复制
## 给用户添加多个tags
[root@linux-01 vhost]# rabbitmqctl set_user_tags ceshi managemnet  administrator
Setting tags for user "ceshi" to [managemnet, administrator] ...
代码语言:javascript复制
[root@linux-01 vhost]# rabbitmqctl set_user_tags ceshi managemnet
Setting tags for user "ceshi" to [managemnet] ...
[root@linux-01 vhost]# rabbitmqctl set_user_tags ceshi managemnet  administrator
Setting tags for user "ceshi" to [managemnet, administrator] ...
[root@linux-01 vhost]# rabbitmqctl add_vhost lololo
Adding vhost "lololo" ...
[root@linux-01 vhost]# rabbitmqctl list_vhosts
Listing vhosts ...
name
lololo
/
[root@linux-01 vhost]# rabbitmqctl set_permissions -p lololo ceshi '.*' '.*' '.*'
Setting permissions for user "ceshi" in vhost "lololo" ...
代码语言:javascript复制
[root@linux-01 vhost]# rabbitmqctl list_user_permissions ceshi
Listing permissions for user "ceshi" ...
vhost	configure	write	read
lololo	.*	.*	.*
[root@linux-01 vhost]# rabbitmqctl list_permissions -p lololo
Listing permissions for vhost "lololo" ...
user	configure	write	read
ceshi	.*	.*	.*
[root@linux-01 vhost]# rabbitmqctl clear_permissions -p  lololo ceshi
Clearing permissions for user "ceshi" in vhost "lololo" ...
[root@linux-01 vhost]# rabbitmqctl list_permissions -p lololo
Listing permissions for vhost "lololo" ...

[root@linux-01 vhost]#

3.2.3 插件管理

  • rabbitmq-plugins list #获取RabbitMQ插件列表
  • rabbitmq-plugins enable <插件名字> #安装RabbitMQ插件
  • rabbitmq-plugins disable <插件名字> #卸载某个插件
代码语言:javascript复制
[root@linux-01 vhost]# rabbitmq-plugins list
Listing plugins with pattern ".*" ...
 Configured: E = explicitly enabled; e = implicitly enabled
 | Status: * = running on rabbit@linux-01
 |/
[  ] rabbitmq_amqp1_0                  3.8.9
[  ] rabbitmq_auth_backend_cache       3.8.9
[  ] rabbitmq_auth_backend_http        3.8.9
[  ] rabbitmq_auth_backend_ldap        3.8.9
[  ] rabbitmq_auth_backend_oauth2      3.8.9
[  ] rabbitmq_auth_mechanism_ssl       3.8.9
[  ] rabbitmq_consistent_hash_exchange 3.8.9
[  ] rabbitmq_event_exchange           3.8.9
[  ] rabbitmq_federation               3.8.9
[  ] rabbitmq_federation_management    3.8.9
[  ] rabbitmq_jms_topic_exchange       3.8.9
[E*] rabbitmq_management               3.8.9
[e*] rabbitmq_management_agent         3.8.9
[  ] rabbitmq_mqtt                     3.8.9
[  ] rabbitmq_peer_discovery_aws       3.8.9
[  ] rabbitmq_peer_discovery_common    3.8.9
[  ] rabbitmq_peer_discovery_consul    3.8.9
[  ] rabbitmq_peer_discovery_etcd      3.8.9
[  ] rabbitmq_peer_discovery_k8s       3.8.9
[  ] rabbitmq_prometheus               3.8.9
[  ] rabbitmq_random_exchange          3.8.9
[  ] rabbitmq_recent_history_exchange  3.8.9
[  ] rabbitmq_sharding                 3.8.9
[  ] rabbitmq_shovel                   3.8.9
[  ] rabbitmq_shovel_management        3.8.9
[  ] rabbitmq_stomp                    3.8.9
[  ] rabbitmq_top                      3.8.9
[  ] rabbitmq_tracing                  3.8.9
[  ] rabbitmq_trust_store              3.8.9
[e*] rabbitmq_web_dispatch             3.8.9
[  ] rabbitmq_web_mqtt                 3.8.9
[  ] rabbitmq_web_mqtt_examples        3.8.9
[  ] rabbitmq_web_stomp                3.8.9
[  ] rabbitmq_web_stomp_examples       3.8.9

3.2.4 限制

  • rabbitmqctl set_vhost_limits -p vhost_name ‘{“max-connections”: 256}’ #设置虚拟主机的最大连接数
  • rabbitmqctl set_vhost_limits -p vhost_name ‘{“max-connections”: 0}’ #不允许客户端连接虚拟主机
  • rabbitmqctl set_vhost_limits -p vhost_name ‘{“max-connections”: -1}’ #不限制连接数
  • rabbitmqctl set_vhost_limits -p vhost_name ‘{“max-queues”: 1024}’ #限制虚拟主机里最大的队列数
  • rabbitmqctl set_vhost_limits -p vhost_name ‘{“max-queues”: -1}’ #不限制队列数

3.2.4 其他

  • rabbitmqctl list_exchanges #列出所有的交换器
  • rabbitmqctl list_bindings #列出所有的绑定,即把exchange和queue按照路由规则绑定起来
  • rabbitmqctl list_queues #分别查看当前系统种存在的Exchange和Exchange上绑定的Queue信息。
  • rabbitmqctl status #查看运行信息

0 人点赞