RabbitMQ搭建和管理

原文地址: http://my.oschina.net/feichexia/blog/205236?p=1


1、安装

    在Mac下安装RabbitMQ是非常简单的,一般默认RabbitMQ服务器依赖的Erlang已经安装,只需要用下面两个命令就可以完成RabbitMQ的安装(前提是homebrew已经被安装):

?
1
2
brew update
brew install rabbitmq

    安装完成后需要将/usr/local/sbin添加到$PATH,可以将下面这两行加到~/.bash_profile或者~/.profile:

?
1
2
# RabbitMQ Config
export PATH=$PATH: /usr/local/sbin

    在Windows下安装稍微麻烦些,需要先安装ErLang,然后下载RabbitMQ可执行文件安装


2、启动RabbitMQ服务

    上面配置完成后,需要关闭终端窗口,重新打开,然后输入下面命令即可启动RabbitMQ服务:

?
1
rabbitmq-server

    可以在后面加-detatched选项参数表示以守护进程方式启动


3、命令行管理RabbitMQ

    RabbitMQ提供了rabbitmqctl和rabbitmqadmin命令行管理工具,它们都是RabbitMQ的插件,可以通过rabbitmq-plugins list查看所有插件信息。rabbitmqctl的完整命令列表如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
     sync_queue queue
     cancel_sync_queue queue
 
     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>] [--priority <priority>] [--apply-to <apply-to>]
<name> <pattern>  <definition>
     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>

    start_app、stop_app分别是启动和停止RabbitMQ应用。其他的list_queues、list_exchanges等是显示RabbitMQ队列、RabbitMQ交换机信息。

    rabbitmqadmin的完整命令列表如下(Mac下安装好了就带了这个命令,Windows下貌似还需要从http://server-name:15672/cli/下载,并可能需要通过rabbitmq-plugins enable rabbitmq management启用这个插件):

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Usage
=====
   rabbitmqadmin [options] subcommand
 
   where subcommand is one of:
 
Options
=======
--help, -h              show this help message and exit
--config=CONFIG, -c CONFIG
                         configuration file [default: ~/.rabbitmqadmin.conf]
--node=NODE, -N NODE    node described in the configuration file [default:
                         'default' only if configuration file is specified]
--host=HOST, -H HOST    connect to host HOST [default: localhost]
--port=PORT, -P PORT    connect to port PORT [default: 15672]
--vhost=VHOST, -V VHOST
                         connect to vhost VHOST [default: all vhosts for list,
                         '/' for declare ]
--username=USERNAME, -u USERNAME
                         connect using username USERNAME [default: guest]
--password=PASSWORD, -p PASSWORD
                         connect using password PASSWORD [default: guest]
--quiet, -q             suppress status messages [default: True]
--ssl, -s               connect with ssl [default: False]
--ssl-key- file =SSL_KEY_FILE
                         PEM format key file for SSL
--ssl-cert- file =SSL_CERT_FILE
                         PEM format certificate file for SSL
-- format =FORMAT, -f FORMAT
                         format for listing commands - one of [raw_json, long,
                         pretty_json, kvp, tsv, table, bash ] [default: table]
-- sort =SORT, -S SORT    sort key for listing queries
-- sort -reverse, -R      reverse the sort order
--depth=DEPTH, -d DEPTH
                         maximum depth to recurse for listing tables [default:
                         1]
-- bash -completion       Print bash completion script [default: False]
--version               Display version and exit
 
Display
=======
 
   list users [<column>...]
   list vhosts [<column>...]
   list connections [<column>...]
   list exchanges [<column>...]
   list bindings [<column>...]
   list permissions [<column>...]
   list channels [<column>...]
   list parameters [<column>...]
   list queues [<column>...]
   list policies [<column>...]
   list nodes [<column>...]
   show overview [<column>...]
 
Object Manipulation
===================
 
   declare queue name=... [node=... auto_delete=... durable=... arguments=...]
   declare vhost name=... [tracing=...]
   declare user name=... password=... tags=...
   declare exchange name=... type =... [auto_delete=... internal=... durable=... arguments=...]
   declare policy name=... pattern=... definition=... [priority=... apply-to=...]
   declare parameter component=... name=... value=...
   declare permission vhost=... user=... configure=... write=... read =...
   declare binding source =... destination=... [arguments=... routing_key=... destination_type=...]
   delete queue name=...
   delete vhost name=...
   delete user name=...
   delete exchange name=...
   delete policy name=...
   delete parameter component=... name=...
   delete permission vhost=... user=...
   delete binding source =... destination_type=... destination=... properties_key=...
   close connection name=...
   purge queue name=...
 
Broker Definitions
==================
 
   export < file >
   import < file >
 
Publishing and Consuming
========================
 
   publish routing_key=... [payload=... payload_encoding=... exchange=...]
   get queue=... [count=... requeue=... payload_file=... encoding=...]
 
   * If payload is not specified on publish, standard input is used
 
   * If payload_file is not specified on get, the payload will be shown on
     standard output along with the message metadata
 
   * If payload_file is specified on get, count must not be set


4、Web界面管理RabbitMQ

    默认可以通过http://serverip:15672访问RabbitMQ的Web管理界面,默认用户名密码都是guest。(注意:RabbitMQ 3.0之前的版本默认端口是55672,下同)


5、RabbitMQ提供的HTTP API接口

    RabbitMQ还提供了HTTP API接口,这样可以通过编程方式监控RabbitMQ的运行状态,HTTP API接口的地址为:http://serverip:15672/api/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值