RabbitMQ的远程Web管理与监控工具
RabbitMQ提供了完善的管理和监控工具,分management plugin 和 rabbitmqctl 两种类型的工具。
1、management plugin
rabbitmq-management plugin提供HTTP API来管理和监控RabbitMQ Server,具体包含如下功能:
删除、生成、列表,包括:exchanges,queues,bindings,users,virtual hosts and permissions。
监视 queue 长度,每个 channel的message rates ,每个连接的data rates,等等。
发送和接收messages。
监控Erlang processes,file descriptors,memory use。
导出/导出object definitions to JSON。
强制关闭 connections,清空 queues。
management plugin默认就在RabbitMQ的发布版本中,只需要enable就可以了,执行以下命令:
$ cd /usr/lib/rabbitmq/bin/ $ sudo rabbitmq-plugins enable rabbitmq_management
看到这一幕后,重启RabbitMQ就可以了。需要注意的是,mochiweb 必须得有,mochiweb是一个用来构建Web应用的轻便,高效的HTTP应用框架的Erlang库。
下面可以通过以下两种方式来访问管理和监控界面:
2、Web UI管理消息服务器
打开浏览器,输入 http://[server-name]:15672/ 如 http://localhost:15672/ ,会要求输入用户名和密码,用默认的guest/guest即可(guest/guest用户只能从localhost地址登录,如果要配置远程登录,必须另创建用户),确认后会出现下面界面:
接下来你就可以掌控RabbitMQ了。
3、添加远程管理账户
如果要从远程登录怎么做呢?处于安全考虑,guest这个默认的用户只能通过http://localhost:15672来登录,其他的IP无法直接用这个guest帐号。这里我们可以通过配置文件来实现从远程登录管理界面,只要编辑/etc/rabbitmq/rabbitmq.config文件(没有就新增),添加以下配置就可以了。
[ {rabbit, [{tcp_listeners, [5672]}, {loopback_users, ["asdf"]}]} ].
现在添加了一个新授权用户asdf,可以远程使用这个用户名。记得要先用命令添加这个命令才行:
$ cd /usr/lib/rabbitmq/bin/ #用户名与密码 $ sudo rabbitmqctl add_user asdf 123456 #用户设置为administrator才能远程访问 $ sudo rabbitmqctl set_user_tags asdf administrator $ sudo rabbitmqctl set_permissions -p / asdf ".*" ".*" ".*"
其实也可以通过管理平台页面直接添加用户和密码等信息。如果还不能远程访问或远程登录检查是不是5672, 15672端口没有开放!!!!!!
4、远程管理接口的命令行工具
Management command line tool(rabbitmqadmin)拥有跟Web UI同样的功能,可能还更便于脚本使用。rabbitmqadmin仅仅是一个定制的HTTP客户端,如果想在自己的程序中引入 rabbitmqadmin的话,可以直接使用HTTP API。rabbitmqadmin可以在http://server-name:15672/cli页面下载。
下载rabbitmqadmin.txt后,将其重命名为rabbitmqadmin,拷贝到 /usr/local/bin 或者你想要的路径,并增加可执行权限。使用:
1
|
$
sudo
rabbitmqadmin --help
|
可以查看使用指南。
5、rabbitmqctl命令行管理工具
rabbitmqctl是一个简单的命令行工具用于管理RabbitMQ Server,适合通过ssh登陆的管理。
在shell中执行如下命令,能看到各种命令简价:
Usage:
rabbitmqctl [-n <node>] [-q] <command> [<command options>]
Options:
-n node
-q
Default node is "rabbit@server", where server is the local host. On a host named "server.example.com", the node name of the RabbitMQ Erlang node will usually be rabbit@server (unless RABBITMQ_NODENAME has been set to some non-default value at broker startup time). The output of hostname -s is usually the correct suffix to use after the "@" sign. See rabbitmq-server(1) for
details of configuring the RabbitMQ broker.
Quiet output mode is selected with the "-q" flag. Informational messages are
suppressed when quiet mode is in effect.
Commands:
stop [<pid_file>]
stop_app
start_app
wait <pid_file>
reset
force_reset
rotate_logs <suffix>
join_cluster <clusternode>[<--ram>]
cluster_status
change_cluster_node_type disc | ram
forget_cluster_node [--offline]
update_cluster_nodes clusternode
add_user <username> <password>
delete_user <username>
change_password <username> <newpassword>
clear_password <username>
set_user_tags <username> <tag> ...
list_users
add_vhost <vhostpath>
delete_vhost <vhostpath>
list_vhosts [<vhostinfoitem> ...]
set_permissions [-p <vhostpath>] <user> <conf> <write> <read>
clear_permissions [-p <vhostpath>] <username>
list_permissions [-p <vhostpath>]
list_user_permissions <username>
set_parameter [-p <vhostpath>] <component_name> <name> <value>
clear_parameter [-p <vhostpath>] <component_name> <key>
list_parameters [-p <vhostpath>]
set_policy [-p <vhostpath>] <name> <pattern> <definition> [<priority>]
clear_policy [-p <vhostpath>] <name>
list_policies [-p <vhostpath>]
list_queues [-p <vhostpath>] [<queueinfoitem> ...]
list_exchanges [-p <vhostpath>] [<exchangeinfoitem> ...]
list_bindings [-p <vhostpath>] [<bindinginfoitem> ...]
list_connections [<connectioninfoitem> ...]
list_channels [<channelinfoitem> ...]
list_consumers [-p <vhostpath>]
status
environment
report
eval <expr>
close_connection <connectionpid> <explanation>
trace_on [-p <vhost>]
trace_off [-p <vhost>]
set_vm_memory_high_watermark <fraction>
<vhostinfoitem> must be a member of the list [name, tracing].
The list_queues, list_exchanges and list_bindings commands accept an optional virtual host parameter for which to display results. The default value is "/".
<queueinfoitem> must be a member of the list [name, durable, auto_delete, arguments, policy, pid, owner_pid, exclusive_consumer_pid, exclusive_consumer_tag, messages_ready, messages_unacknowledged, messages, consumers, active_consumers, memory, slave_pids, synchronised_slave_pids].
<exchangeinfoitem> must be a member of the list [name, type, durable, auto_delete, internal, arguments, policy].
<bindinginfoitem> must be a member of the list [source_name, source_kind, destination_name, destination_kind, routing_key, arguments].
<connectioninfoitem> must be a member of the list [pid, name, port, host, peer_port, peer_host, ssl, ssl_protocol, ssl_key_exchange, ssl_cipher, ssl_hash, peer_cert_subject, peer_cert_issuer, peer_cert_validity, last_blocked_by, last_blocked_age, state, channels, protocol, auth_mechanism, user, vhost, timeout, frame_max, client_properties, recv_oct, recv_cnt, send_oct, send_cnt, send_pend].
<channelinfoitem> must be a member of the list [pid, connection, name, number, user, vhost, transactional, confirm, consumer_count, messages_unacknowledged, messages_uncommitted, acks_uncommitted, messages_unconfirmed, prefetch_count, client_flow_blocked].
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。