RabbitMQ之管理與監控

RabbitMQ提供了完善的管理和監控工具,分management plugin 和 rabbitmqctl 兩種類型的工具。node

一. management plugin web

rabbitmq-management plugin提供HTTP API來管理和監控RabbitMQ Server,具體包含以下功能:shell

  • Declare,list and delete exchanges,queues,bindings,users,virtual hosts and permissions。瀏覽器

  • Monitor queue length,message rates globally and per channel,data rates per connection,etc。安全

  • Send and receive messages。app

  • Monitor Erlang processes,file descriptors,memory use。框架

  • Export / inport object definitions to JSON。less

  • Force close connections,purge queues。tcp

management plugin默認就在RabbitMQ的發佈版本中,只須要enable就能夠了,執行如下命令:工具

$ cd /usr/lib/rabbitmq/bin/$ sudo rabbitmq-plugins enable rabbitmq_management

看到這一幕後,重啓RabbitMQ就能夠了。須要注意的是,mochiweb 必須得有,mochiweb是一個用來構建Web應用的輕便,高效的HTTP應用框架的Erlang庫。

下面能夠經過如下兩種方式來訪問管理和監控界面:

1. Web UI 

打開瀏覽器,輸入 http://[server-name]:15672/ 如 http://localhost:15672/  ,會要求輸入用戶名和密碼,用默認的guest/guest便可(guest/guest用戶只能從localhost地址登陸,若是要配置遠程登陸,必須另建立用戶),確認後會出現下面界面:

接下來你就能夠盡情掌控RabbitMQ了。

若是要從遠程登陸怎麼作呢?處於安全考慮,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端口沒有開放!!!!!!

2. 命令行工具

Management command line tool(rabbitmqadmin)擁有跟Web UI一樣的功能,可能還更便於腳本使用。rabbitmqadmin僅僅是一個定製的HTTP客戶端,若是想在本身的程序中引入rabbitmqadmin的話,能夠直接使用HTTP API。rabbitmqadmin能夠在http://server-name:15672/cli頁面下載。

下載rabbitmqadmin.txt後,將其重命名爲rabbitmqadmin,拷貝到 /usr/local/bin 或者你想要的路徑,並增長可執行權限。使用:

$ sudo rabbitmqadmin --help

能夠查看使用指南。

二. rabbitmqctl

rabbitmqctl是一個簡單的命令行工具用於管理RabbitMQ Server,在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].

相關文章
相關標籤/搜索