转载地址http://blog.youkuaiyun.com/u010416588/article/details/54599341
RabbitMQ官网 http://www.rabbitmq.com
下载地址 http://www.rabbitmq.com/download.html
一 Windows下安装RabbitMq
1.1 下载安装包
1.1.1 下载RabbitMq
安装参考 http://www.rabbitmq.com/install-windows.html
官网上说明,在windows上安装rabbitmq-server时,需要先安装Erlang Windows Binary File,如果Windows环境中曾经装过32位的,现在要升级为64位的,必须先卸载。官网原话
If you have an existing installation and are planning to upgrade the Erlang VM from a 32bit to a 64bit version then you must uninstall the broker before upgrading the VM.
1.1.1 下载Erlang
Erlang 下载安装地址 http://www.erlang.org/downloads
关于Erlang的介绍请参考文章
http://blog.youkuaiyun.com/zzhongcy/article/details/38823197
1.2 安装Erlang
1.2.1 运行安装
下载otp_win64_19.2.exe
运行安装otp_win64_19.2.exe
1.2.2 修改环境变量
1) 添加系统环境变量ERLANG_HOME,值为安装目录.
2) 修改系统环境变量Path,在PATH变量中添加“%ERL_HOME%\bin”
3) 重启电脑后,在控制台输入 erl,如果出现类似“Eshell V6.1 (abort with ^G)”字样,说明安装成功。
**官方说明上没有这块,试了下,不设置环境变量也是可以运行RabbitMQ的**
1.3 安装RabbitMq
1.3.1 运行安装
下载rabbitmq-server-3.6.6.exeWindows版本
运行安装rabbitmq-server-3.6.6.exe
1.3.2 运行服务
rabbitMq默认自启动
可以修改rabbitmq的配置文件,也可以用默认配置运行。在开始菜单栏里可以看到运行指令reinstall/remove/start/stop

或者直接打开RabbitMQ Command Prompt命令框。

1.3.3 端口号访问
当防火墙或者其他安全工具阻止RabbitMQ端口号绑定时,服务启动会失败。确保下列端口可以打开:
4369 (epmd)
5672, 5671 (AMQP 0-9-1 and 1.0 without and with TLS)
25672. This port used by Erlang distribution for inter-node and CLI tools communication and is allocated from a dynamic range (limited to a single port by default, computed as AMQP port + 20000). See networking guide for details.
15672 (if management plugin is enabled)
61613, 61614 (if STOMP is enabled)
1883, 8883 (if MQTT is enabled)
1.3.4 默认用户访问
该代理创建了一个默认的账号“guest”密码“guest”的访问账号。未配置的客户端默认使用该账号凭据,但仅限于访问本地。如果是网络访问则需要另外配置。其他用户访问参考访问控制文档
1.3.5 管理服务
使用rabbitmqctl 管理服务,参见官方文档
http://www.rabbitmq.com/man/rabbitmqctl.1.man.html
-n node 默认node名称是"rabbit@server",如果你的主机是'server.example.com',那么node名是rabbit@server
-q 安静输出模式,信息会被禁止输出
rabbitmqctl [-n node] [-t timeout] [-q] {command} [command options...]
1.3.5.1 基本管理功能
stop [<pid_file>]
stop_app
start_app
wait <pid_file>
reset
force_reset
rotate_logs <suffix>
1.3.5.2 cluster管理
join_cluster <clusternode> [
cluster_status
change_cluster_node_type disc | ram
forget_cluster_node [
update_cluster_nodes clusternode
sync_queue queue
cancel_sync_queue queue
1.3.5.3 用户管理
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>]
- 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
- 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
1.3.5.4 policy管理
policy管理,策略用来控制和修改queues和exchange在集群中的行为,策略可以应用到vhost
set_policy [-p <vhostpath>] [--priority <priority>] [--apply-to <apply-to>]
<name> <pattern> <definition>
#name 策略名称,pattern 正则表达式,用来匹配资源,符合的就会应用设置的策略,apply-to 表示策略应用到什么类型的地方,一般有queues、exchange和all,默认是all。priority 是个整数优先级,definition 是json格式设置的策略。
clear_policy [-p <vhostpath>] <name>
#清除一个策略
list_policies [-p <vhostpath>]
#列出已有的策略
1.3.5.5 queue&exchange状态信息
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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
1.3.6 插件管理
rabbitmq支持各种插件,开启插件可以使用rabbitmq-plugins命令
rabbitmq-plugins <command> [<command options>]
Commands:
list [-v] [-m] [-E] [-e] [<pattern>] 显示所有的的插件。-v 显示版本 -m 显示名称 -E 显示明确已经开启的 -e显示明确的和暗中开启的
enable <plugin> ... 开启一个插件
disable <plugin> ... 关闭一个插件

如图,启动插件后重启服务,在浏览器打开http://localhost:15672
登录,用户名密码都是guest

1.3.7 服务日志
服务日志记录在RABBITMQ_NODENAME.log,在文件夹RABBITMQ_LOG_BASE中。其他的日志记录在RABBITMQ_NODENAME-sasl.log.
rabbitmqctl rotate_logs {stuffix}
指示RabbitMQ node循环日志文件.
RabbitMQ 中间件会将原来日志文件中的内容追加到原始名称和后辍的日志文件中,然后再将原始日志文件内容复制到新创建的日志上。实际上,当前日志内容会移到以此后辍结尾的文件上。当目标文件不存在时,将会进行创建。如果不指定后辍,则不会发生循环,日志文件只是重新打开。
rabbitmqctl rotate_logs.1
此命令指示RabbitMQ node将日志文件的内容追加到新日志文件(文件名由原日志文件名和.1后辍构成)中。如. rabbit@mymachine.log.1 和 ra