您的位置:首页 > 其它

RabbitMQ 安装配置与管理

2012-08-29 12:13 477 查看

RabbitMQ 安装配置与管理

安装平台红帽5.5 64位系统

1. 安装erlang虚拟机
下载链接http://binaries.erlang-solutions.com/sources/otp_src_R15B01.tar.gz
Rabbitmq基于erlang语言开发,所有需要安装erlang虚拟机
#tar zxvf otp_src_R15B01.tar.gz&& cd otp_src_R15B01
#./configure && make install
2. 安装Python
如果Python版本低,编译simplejson时会报错。请安装Python-2.7.3.tar.bz2
下载地址:http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar xjvf Python-2.7.3.tar.bz2
cd Python-2.7.3
./confiugure && make && make install
Python -V 查看版本

3. 安装simplejson
如果 机器上python 版本为2.6以下版本 会提 示You don't appear to have simplejson.py installed 安装。
下载链接:http://pypi.python.org/packages/source/s/simplejson/simplejson-2.6.1.tar.gz
tar xvzf simplejson-2.6.1.tar.gz

cd simplejson-2.6.1

python setup.py install

4. 安装rabbitmq server
下载:http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.6/rabbitmq-server-generic- unix- 2.8.6.tar.gz

tar xvzf rabbitmq-server-generic-unix-2.8.6.tar.gz

cd rabbitmq_server-2.8.6/

./rabbitmq-server 启动服务即可

配置

一般情况下,RabbitMQ的默认配置就足够了。如果希望特殊设置的话,有两个途径:
一个是环境变量的配置文件 rabbitmq-env.conf ;

一个是配置信息的配置文件 rabbitmq.config;

注意,这两个文件默认是没有的,如果需要必须自己创建。

rabbitmq-env.conf这个文件的位置是确定和不能改变的,位于:/etc/rabbitmq目录下(这个目录需要自己创建)。

文件的内容包括了RabbitMQ的一些环境变量,配置下面:

RABBITMQ_MNESIA_BASE=/rabbitmq/data //需要使用的MNESIA数据库的路径

RABBITMQ_LOG_BASE=/rabbitmq/log //log的路径

RABBITMQ_PLUGINS_DIR=/rabbitmq/plugins //插件的路径

具体的列表见:http://www.rabbitmq.com/configure.html#define-environment-variables

rabbitmq.config

这是一个标准的erlang配置文件。它必须符合erlang配置文件的标准。

它既有默认的目录,也可以在rabbitmq-env.conf文件中配置。

集群配置

(1)配置erlang
Rabbitmq的集群是依赖于erlang的集群来工作的,所以必须先构建起erlang的集群环境。Erlang的集群中各节 点是通过一个magic cookie来实现的,这个cookie存放在$HOME/.Erlang.cookie 中,文件是400的权限。所以必须保证各节点cookie保持一致,否则节点之间就无法通信。
将其中一台节点上的.erlang.cookie值复制下来保存到其他节点上。或者使用scp的方法也 可,但是要注意文件的权限和属主属组。
$ cat .erlang.cookie
IYZNFNJIUWABJUELIUFE
将值保存到其他节点上: 先更改文件权限,给予其可写权限:
$chmod 700 .erlang.cookie
$ echo -n " IYZNFNJIUWABJUELIUFE" >$HOME/.erlang.cookie
$chmod 400 .erlang.cookie
直接把.erlang.cookie这个文件scp到其它节点也可以。

(2) 配置各节点下的hosts文件,确保节点之间主机名称可以相互解析。
192.168.1.**   nodename
192.168.1.**   nodename
192.168.1.**   nodename
192.168.1.**   nodename
(1)手动配置rabbitmq集群
a)首先在每个节点上启动RabbitMq
host1#rabbitmq-server -detached
host2#rabbitmq-server -detached
host3#rabbitmq-server -detached
此时每个节点自成集群,每个集群只有本节点
可以通过export RABBITMQ_NAME=xxx 指定节点名称,若不指定默认为rabbit
完整的节点名为xxx@hostname
b)加入集群
让host2 和host3上的rabbitmq节点加入到 host1的rabbitmq集群
使用rabbitmqctl命令对rabbitmq进行操作

加入集群前必须停止当前app,加入后在重启app,过程如下:
host2#rabbitmqctl stop_app
host2#rabbitmqctl cluster rabbit@host1
host2#rabbitmqctl start_app
host3#rabbitmqctl stop_app
host3#rabbitmqctl cluster rabbit@host1
host3#rabbitmqctl start_app
关于节点类型(ram |disk)
ram节点的状态保存在内存中,disk节点保存在磁盘中被加入的节点为disk,如本例中rabbit@host1为disk节点,rabbit@host2,rabbit@host3为ram节点可以通过rabbitmqctl cluster命令改变加入的集群以及节点类型该命令后可以加多个节点名称,指定的节点就会变成disk节点
如可以将本例中所有节点都改成disk节点
host2#rabbitmqctl stop_app
host2#rabbitmqctl reset
host2#rabbitmqctl cluster rabbit@host1 rabbit@host2
host2#rabbitmqctl start_app
host3#rabbitmqctl stop_app
host3#rabbitmqctl reset
host3#rabbitmqctl cluster rabbit@host1 rabbit@host3
host3#rabbitmqctl start_app
(2)自动配置rabbitmq集群:
rabbitmq的默认配置脚本为
/etc/rabbitmq/rabbitmq.conf
在其中添加

[
...
{rabbit, [
...
{cluster_nodes, ['rabbit@host1', 'rabbit@host2', 'rabbit@host3']},
...
]},
...
].
分别启动每个rabbitmq节点
rabbitmq -detached
rabbitmq就自动组成集群了
注意事项:
1) 每个节点的erlang cookie须相同,可以在启动服务器加–setcookie参数设置相同的参数, 也可以在home目录下设置相同的.erlang.cookie文件。
2) 节点间应该能相互解析,可以通过修改/etc/hosts文件实现

监控

RabbitMQ提供了一个web的监控页面系统,这个系统是以Plugin的方式进行调用的。
首先,确定rabbitmq-env.conf中配置好的plugins目录的位置
启动管理插件命令 :
rabbitmq-plugins enable rabbitmq_management
重新启动RabbitMQ,输入http://server-name:55672/mgmt/ 就能够进入到监控页面。默认 的用户名和密码是: guest 和 guest。如图:





管理

Rabbitmq服务器的主要通过rabbitmqctl和rabbimq-plugins两个工具来管理,以下是一些常用功能。

1. 服务器启动与关闭
启动: rabbitmq-server –detached
关闭:rabbitmqctl stop
若单机有多个实例,则在rabbitmqctlh后加–n 指定名称
2. 插件管理
开启某个插件:rabbitmq-plugins enable xxx
关闭某个插件:rabbitmq-plugins disablexxx
注意:重启服务器后生效。
3. virtual_host管理
新建virtual_host: rabbitmqctl add_vhost xxx
撤销virtual_host:rabbitmqctl delete_vhost xxx
4. 用户管理
新建用户:rabbitmqctl add_user xxx pwd
删除用户: rabbitmqctl delete_user xxx
改密码: rabbimqctl change_password {username} {newpassword}
设置用户角色:rabbitmqctl set_user_tags {username} {tag ...}
Tag可以为 administrator, monitoring, management
Tag
Capabilities
(None)
No access to the management plugin
management
Anything the user could do via AMQP plus:
List virtual hosts to which they can log in via AMQP
View all queues, exchanges and bindings in "their" virtual hosts
View and close their own channels and connections
View "global" statistics covering all their virtual hosts, including activity by other users within them
monitoring
Everything "management" can plus:
List all virtual hosts, including ones they could not log in to via AMQP
View other users's connections and channels
View node-level data such as memory use and clustering
View truly global statistics for all virtual hosts
administrator
Everything "monitoring" can plus:
Create and delete virtual hosts
View, create and delete users
View, create and delete permissions
Close other users's connections
5. 权限管理
权限设置:set_permissions [-p vhostpath] {user} {conf} {write} {read}
Vhostpath
Vhost路径
user
用户名
Conf
一个正则表达式match哪些配置资源能够被该用户访问。
Write
一个正则表达式match哪些配置资源能够被该用户读。
Read
一个正则表达式match哪些配置资源能够被该用户访问。
6. 获取服务器状态信息
服务器状态:rabbitmqctl status

队列信息:rabbitmqctl list_queues [-p vhostpath] [queueinfoitem ...]
Queueinfoitem可以为:name,durable,auto_delete,arguments,messages_ready,
messages_unacknowledged,messages,consumers,memory

Exchange信息:rabbitmqctllist_exchanges [-p vhostpath] [exchangeinfoitem ...]
Exchangeinfoitem有:name,type,durable,auto_delete,internal,arguments.

Binding信息:rabbitmqctllist_bindings [-p vhostpath] [bindinginfoitem ...] Bindinginfoitem有:source_name,source_kind,destination_name,destination_kind,routing_key,arguments

Connection信息:rabbitmqctl list_connections [connectioninfoitem ...]
Connectioninfoitem有:recv_oct,recv_cnt,send_oct,send_cnt,send_pend等。

Channel信息:rabbitmqctl list_channels[channelinfoitem ...]
Channelinfoitem有consumer_count,messages_unacknowledged,messages_uncommitted
,acks_uncommitted,messages_unconfirmed,prefetch_count,client_flow_blocked

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息