在Mac下安装RabbitMQ是非常简单的,一般默认RabbitMQ服务器依赖的Erlang已经安装,只需要用下面两个命令就可以完成RabbitMQ的安装(前提是homebrew已经被安装):
brew update
brew install rabbitmq
安装完成后需要将/usr/local/sbin添加到$PATH,可以将下面这两行加到~/.bash_profile或者~/.profile:
# RabbitMQ Config
export PATH=$PATH:/usr/local/sbin
在Windows下安装稍微麻烦些,需要先安装ErLang,然后下载RabbitMQ可执行文件安装
2、启动RabbitMQ服务
上面配置完成后,需要关闭终端窗口,重新打开,然后输入下面命令即可启动RabbitMQ服务:
rabbitmq-server
可以在后面加-detatched选项参数表示以守护进程方式启动
3、命令行管理RabbitMQ
RabbitMQ提供了rabbitmqctl和rabbitmqadmin命令行管理工具,它们都是RabbitMQ的插件,可以通过rabbitmq-plugins list查看所有插件信息。rabbitmqctl的完整命令列表如下:
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下貌似还需要从:15672/cli/下载,并可能需要通过rabbitmq-plugins enable rabbitmq management启用这个插件):
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
默认可以通过:15672访问RabbitMQ的Web管理界面,默认用户名密码都是guest。(注意:RabbitMQ 3.0之前的版本默认端口是55672,下同)
5、RabbitMQ提供的HTTP API接口
RabbitMQ还提供了HTTP API接口,这样可以通过编程方式监控RabbitMQ的运行状态,HTTP API接口的地址为::15672/api/
CentOS 5.6 安装RabbitMQ
用Python尝试RabbitMQ
Ubuntu下PHP + RabbitMQ使用