本文共 4740 字,大约阅读时间需要 15 分钟。
RabbitMQ自带插件管理系统,可以使用工具[rabbitmq-plugins]进行管理和使用。查看当前插件状态[tRabbitMQ@iZ250x18mnzZ ~]$ rabbitmq-plugins list Configured: E = explicitly enabled; e = implicitly enabled | Status: [failed to contact rabbit@iZ250x18mnzZ - status not shown] |/[e ] amqp_client 3.6.0[ ] cowboy 1.0.3[ ] cowlib 1.0.1[e ] mochiweb 2.13.0[ ] rabbitmq_amqp1_0 3.6.0[ ] rabbitmq_auth_backend_ldap 3.6.0[ ] rabbitmq_auth_mechanism_ssl 3.6.0[ ] rabbitmq_consistent_hash_exchange 3.6.0[ ] rabbitmq_event_exchange 3.6.0[ ] rabbitmq_federation 3.6.0[ ] rabbitmq_federation_management 3.6.0[E ] rabbitmq_management 3.6.0[e ] rabbitmq_management_agent 3.6.0[ ] rabbitmq_management_visualiser 3.6.0[ ] rabbitmq_mqtt 3.6.0[ ] rabbitmq_recent_history_exchange 1.2.1[ ] rabbitmq_sharding 0.1.0[ ] rabbitmq_shovel 3.6.0[ ] rabbitmq_shovel_management 3.6.0[ ] rabbitmq_stomp 3.6.0[ ] rabbitmq_tracing 3.6.0[e ] rabbitmq_web_dispatch 3.6.0[ ] rabbitmq_web_stomp 3.6.0[ ] rabbitmq_web_stomp_examples 3.6.0[ ] sockjs 0.3.4[e ] webmachine git启用插件[tRabbitMQ@iZ250x18mnzZ ~]$ sudo rabbitmq-plugins enable rabbitmq_managementThe following plugins have been enabled: mochiweb webmachine rabbitmq_web_dispatch amqp_client rabbitmq_management_agent rabbitmq_managementApplying plugin configuration to rabbit@iZ250x18mnzZ... started 6 plugins.停用插件[tRabbitMQ@iZ250x18mnzZ ~]$ sudo rabbitmq-plugins disable rabbitmq_managementThe following plugins have been disabled: mochiweb webmachine rabbitmq_web_dispatch amqp_client rabbitmq_management_agent rabbitmq_managementApplying plugin configuration to rabbit@iZ250x18mnzZ... stopped 6 plugins.具体的命令使用参考官网资料:除系统安装自带的插件,RabbtiMQ还提供了一些其他插件可下载使用:不再对其他的插件相关内容做分析,大家有兴趣的可以点击以下链接到官网学习
管理插件在安装RabbtiMQ时就已经同步安装,只需使用上面的启动命令启动插件即可。
管理插件提供了一套对RabbitMQ服务的管理及监控的HTTP API,以及基于浏览器服的用户界面、命令行工具以及rabbitmqadmin(工具)。
主要有以下功能:
1、 声明、查询、删除交换机、队列、bindings、用户、虚拟机以及权限 2、 监控队列、通道、数据连接等信息 3、 发送和接收消息 4、 监控Erlang进程、内存使用、文件描述符 5、 导入或导出json对象 6、 强制关闭连接,清理队列
按照上述方式启动之后。
1、web访问地址:http://server-name:15672/ 端口可自定义配置
2、http api访问地址:http://server-name:15672/api/ 也可以参考官网:
3、下载工具rabbitmqadmin:http://server-name:15672/cli/ 关于客户端使用方法:
其他相关使用方法,参考官网:
安装RabbitMQ自带的用户guest,只能在本地使用,所以公网中用户guest无法登录management提供的插件,下面是新建用户并增加。
3.1.用户管理
创建用户[tRabbitMQ@iZ250x18mnzZ ~]$ sudo rabbitmqctl add_user rabbitmq rabbitmqCreating user "rabbitmq" ...删除用户[tRabbitMQ@iZ250x18mnzZ ~]$ sudo rabbitmqctl delete_user rabbitmqDeleting user "rabbitmq" ...查看用户[tRabbitMQ@iZ250x18mnzZ ~]$ sudo rabbitmqctl list_usersListing users ...rabbitmq []guest [administrator]修改用户密码[tRabbitMQ@iZ250x18mnzZ ~]$ sudo rabbitmqctl change_password rabbitmq rabbitmqChanging password for user "rabbitmq" ...[tRabbitMQ@iZ250x18mnzZ ~]$命令参考资料:
3.2. 用户角色管理
创建用户之后,还需要给用户添加权限,在插件management中基于RabbitMQ权限模型进行了封装与扩展,对用户指定类似标签的方式决定用户的权限,提供以下几类标签:
标签 功能 (None) No access to the management plugin management Anything the user could do via AMQP plus:
- List virtual hosts to which they can log in via AMQP
- View all queues, exchanges and bindings in "their" virtual hosts
- View and close their own channels and connections
- View "global" statistics covering all their virtual hosts, including activity by other users within them
policymaker Everything "management" can plus:
- View, create and delete policies and parameters for virtual hosts to which they can log in via AMQP
monitoring Everything "management" can plus:
- List all virtual hosts, including ones they could not log in to via AMQP
- View other users's connections and channels
- View node-level data such as memory use and clustering
- View truly global statistics for all virtual hosts
administrator Everything "policymaker" and "monitoring" can plus:
- Create and delete virtual hosts
- View, create and delete users
- View, create and delete permissions
- Close other users's connections
给用户设置标签[tRabbitMQ@iZ250x18mnzZ ~]$ sudo rabbitmqctl set_user_tags rabbitmq administratorSetting tags for user "rabbitmq" to [administrator] ...[tRabbitMQ@iZ250x18mnzZ ~]$也可以给用户设置多个角色,除上述系统内置角色外,还可以自定义角色,具体可参考官网给出的命令管理工具角色参考官网:命令参考资料:3.3. 权限管理
权限大致分为两个级别:1. 访问权限
决定是否可以连接上相应的服务
按照前两步的方法,创建用户,给用户设置用户角色,我就可以登录到web2. 操作权限操作权限又分为两类,配置权限和读写权限,只要针对资源(queue、exchange)配置权限影响资源的创建和删除。读写权限影响消息的读取和写入,例如发送消息要有可写权限,接收消息要有可读权限。具体说明可见官网资料,而给用户设置相应的权限,使用rabbitmqctl执行即可,下面也有提供具体的手机用方法。RabbitMQ权限模型说明参考资料:命令参考资料: