RabbitMQ安装配置

安装

1.      安装erlang虚拟机

Rabbitmq基于erlang语言开发所有需要安装erlang虚拟机

#wget  http://www.erlang.org/download/otp_src_R15B01.tar.gz

#tar zxvf otp_src_R15B01.tar.gz&& cdotp_src_R15B01

#./configure &&make install

2.      安装rabbitmqserver

#wget http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.2/rabbitmq-server-generic-unix-2.8.2.tar.gz

#tarrabbitmq-server-generic-unix-2.8.2.tar.gz&& cd/rabbitmq-server-generic-unix-2.8.2

修改Makeifle ,添加以下参数,指定安装目录

SBIN_DIR = /usr/sbin

MAN_DIR = /usr/share/man

TARGET= /usr/lib/rabbitmq

最后

#make && makeinstall

注意:安装脚本最后会从一个网站上拉man手册,有时连不上这个网站,安装脚本就会停住,这时可以Ctrl-c结束安装进程,这时其实已经安装完成只差man手册。

 

2.YUM安装:

wgethttp://mirrors.ustc.edu.cn/fedora/epel//6/x86_64/epel-release-6-8.noarch.rpm

yum install epel-release-6-8.noarch.rpm

         yum install rabbitmq-server -y

 

重要目录以及文件

[root@node121 ~]# /usr/lib/rabbitmq/bin/rabbitmq-       

rabbitmq-defaults rabbitmq-env      rabbitmq-plugins  rabbitmq-server   

[root@node121 ~]# /usr/lib/rabbitmq/bin/rabbitmq-

[root@node121 ~]#/usr/lib/rabbitmq/bin/rabbitmq-plugins list

[ ] amqp_client                       3.1.5

[ ] cowboy                           0.5.0-rmq3.1.5-git4b93c2d

[ ] eldap                             3.1.5-gite309de4

[ ] mochiweb                         2.7.0-rmq3.1.5-git680dba8

[ ] rabbitmq_amqp1_0                  3.1.5

[ ] rabbitmq_auth_backend_ldap        3.1.5

显示所有队列

[root@node121 ~]# rabbitmqctl list_queues

Listing queues ...

...done.

 

 

 

 

配置

1.      配置文件

Rabbitmq的配置文件有三个位于/etc/rabbitmq/

这三个文件分别是

1enabled_plugins, 设置允许的插件列表该配置文档的格式为erlang的列表格式如

[rabbitmq_management,rabbitmq_visualiser].

2rabbitmq.conf,设置rabbitmq的运行参数。该配置文件中的每个参数为一个erlang tuple,结构为{KeyValue, Keyatom类型, Value为一个term。其中几个关键参数为:

tcp_listerners 设置rabbimq的监听端口,默认为[5672]

disk_free_limit  磁盘低水位线,若磁盘容量低于指定值则停止接收数据,默认值为

{mem_relative, 1.0},即与内存相关联11,也可定制为多少byte.

vm_memory_high_watermark,设置内存低水位线,若低于该水位线,则开启流控机制,默认值是0.4,即内存总量的40%

hipe_compile 将部分rabbimq代码用HighPerformance Erlangcompiler编译,可提升性能,该参数是实验性,若出现erlang vmsegfaults,应关掉。

force_fine_statistics该参数属于rabbimq_management,若为true则进行精细化的统计,但会影响性能。

3rabbitmq-env.conf  rabbitmq的环境参数配置

RABBITMQ_NODE_PORT 端口设置,默认为5672

RABBITMQ_NODENAME  节点名称,默认为rabbit

MNESIA_BASE 后端存储目录 ,默认为/var/lib/rabbitmq/mnesia

LOG_BASE 日志目录,默认为/var/log/rabbitmq/

 

 

其它参数详情请见:http://www.rabbitmq.com/configure.html

管理

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

1.      服务器启动与关闭

启动: rabbitmq-server �Cdetached

关闭:rabbitmqctl stop

若单机有多个实例,则在rabbitmqctlh后加�Cn 指定名称

2.      插件管理

开启某个插件:rabbitmq-pluginsenable xxx

关闭某个插件:rabbitmq-pluginsdisable xxx

注意:重启服务器后生效。

3.      virtual_host管理

新建virtual_host: rabbitmqctladd_vhost xxx

[root@node121 ~]#rabbitmqctl  add_vhost gmy

Creating vhost "gmy"...

...done.

[root@node121 ~]# rabbitmqctllist_vhosts

Listing vhosts ...

/

gmy

rsc

...done.

遍历所有虚拟主机信息:rabbitmqctllist_vhosts

撤销virtual_host:rabbitmqctl delete_vhost xxx

4.      用户管理

新建用户:rabbitmqctladd_user xxx pwd

[root@node121 ~]# rabbitmqctladd_user test test

Creating user "test"...

...done.

 

删除用户:   rabbitmqctl delete_userxxx

改密码: rabbimqctl change_password{username} {newpassword}

设置用户角色:rabbitmqctlset_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}

rabbitmqctl set_permissions -pv_host user ".*" ".*" ".*" 绑定权限,并且具备读写的权限

[root@node121 ~]# rabbitmqctlset_permissions -p test test ".*" ".*" ".*"

Setting permissions for user"test" in vhost "test" ...

...done.

 

Vhostpath

Vhost路径

user

用户名

Conf

一个正则表达式match哪些配置资源能够被该用户访问。

Write

一个正则表达式match哪些配置资源能够被该用户读。

Read

一个正则表达式match哪些配置资源能够被该用户访问。

 

 

6.      获取服务器状态信息

服务器状态:rabbitmqctlstatus

队列信息:rabbitmqctllist_queues [-p vhostpath] [queueinfoitem ...]

Queueinfoitem可以为:name durableauto_deleteargumentsmessages_ready

messages_unacknowledgedmessagesconsumersmemory

 [root@node121 ~]# rabbitmqctllist_queues -p test

Listing queues ...

...done.

 

Exchange信息:rabbitmqctl list_exchanges[-p vhostpath][exchangeinfoitem ...]

Exchangeinfoitem有:name typedurableauto_deleteinternalarguments.

 

Binding信息:rabbitmqctl list_bindings[-p vhostpath][bindinginfoitem ...]

Bindinginfoitem有:source_namesource_kinddestination_namedestination_kindrouting_keyarguments

 

Connection信息:rabbitmqctllist_connections [connectioninfoitem ...]

Connectioninfoitem有:recv_octrecv_cntsend_octsend_cntsend_pend等。

 

Channel信息:rabbitmqctl list_channels [channelinfoitem ...]

Channelinfoitemconsumer_countmessages_unacknowledgedmessages_uncommitted

acks_uncommittedmessages_unconfirmedprefetch_countclient_flow_blocked

 

更多的信息请参考:http://www.rabbitmq.com/man/rabbitmqctl.1.man.html

 

发送消息:

 

 

 

 

 

2.      集群配置

1)手动配置

a)首先在每个节点上启动RabbitMq

host1#rabbitmq-server-detached

host2#rabbitmq-server-detached

host3#rabbitmq-server-detached

此时每个节点自成集群,每个集群只有本节点

可以通过exportRABBITMQ_NAME=xxx 指定节点名称,若不指定默认为rabbit

完整的节点名为xxx@hostname

b)加入集群

host2 host3上的rabbitmq节点加入到 host1rabbitmq集群

使用rabbitmqctl命令对rabbitmq进行操作

加入集群前必须停止当前app,加入后在重启app,过程如下:

host2#rabbitmqctlstop_app

host2#rabbitmqctlclusterrabbit@host1

host2#rabbitmqctlstart_app

host3#rabbitmqctlstop_app

host3#rabbitmqctlclusterrabbit@host1

host3#rabbitmqctlstart_app

 

关于节点类型(ram |disk

ram节点的状态保存在内存中,disk节点保存在磁盘中

被加入的节点为disk,如本例中rabbit@host1disk节点,rabbit@host2rabbit@host3ram节点

可以通过rabbitmqctlcluster命令改变加入的集群以及节点类型该命令后可以加多个节点名称,指定的节点就会变成disk节点

如可以将本例中所有节点都改成disk节点

host2#rabbitmqctlstop_app

host2#rabbitmqctlreset

host2#rabbitmqctlclusterrabbit@host1 rabbit@host2

host2#rabbitmqctlstart_app

host3#rabbitmqctlstop_app

host3#rabbitmqctlreset

host3#rabbitmqctlclusterrabbit@host1 rabbit@host3

host3#rabbitmqctlstart_app

2自动配置:

rabbitmq的默认配置脚本为

/etc/rabbitmq/rabbitmq.conf

在其中添加

[

...

{rabbit, [

...

{cluster_nodes,['rabbit@host1','rabbit@host2', 'rabbit@host3']},

...

]},

...

].

分别启动每个rabbitmq节点

rabbitmq-detached

rabbitmq就自动组成集群了

注意事项

1)每个节点的erlangcookie须相同可以在启动服务器加�Csetcookie参数设置相同的参数也可以在home目录下设置相同的.erlang.cookie文件。

2)节点间应该能相互解析,可以通过修改/etc/hosts文件实现

 

 

 

 

 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS