RabbitMQ开源企业级消息队列系统实现方案(集群版)

RabbitMQ集群配置

一.集群环境配置

1.1集群环境说明

[root@linuxblind~]# lsb_release -a          #查看系统版本

LSB Version:   :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:

printing-4.0-amd64:printing-4.0-noarch

Distributor ID: CentOS

Description:   CentOS release 6.2 (Final)

Release:        6.2

Codename:       Final

[root@linuxblind~]# uname -a          #查看内核版本

Linux linuxblind2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64GNU/Linux

[root@linuxblind~]#hostname       #查看主机名(上面信息中也有)

linuxblind

注:现在拥有的机器分别是:

192.168.245.129 linuxblind    –master

192.168.245.128 linuxblind2   –slaver1

192.168.245.130 linuxblind3     –slaver2

1.2 集群环境配置

1.2.1 配置hosts,确保机器间可以相互ping通

[root@linuxblind ~]# cat >> /etc/hosts <<EOF         #需分别在每台机器上执行

> 192.168.245.129 linuxblind

> 192.168.245.128linuxblind2

> 192.168.245.130linuxblind3

> EOF

 

1.2.2 配置erlang群集

#安装erlang,需在每台机器上执行

[root@linuxblindzdh]# wget -O /etc/yum.repos.d/epel-erlang.repo \

http://binaries.erlang-solutions.com/rpm/centos/erlang_solutions.repo

[root@linuxblindzdh]# yum install esl-erlang

 

#安装rabbitmq

[root@linuxblindzdh]# tar zxf rabbitmq-server-generic-unix-3.1.1.tar.gz-C /usr/local/

[root@linuxblindzdh]# cd /usr/local

[root@linuxblindzdh]# mv rabbitmq-server-3.1.1 rabbitmq

 

#配置rabbitmq服务的环境变量

[root@linuxblindrabbitmq]# vim etc/rabbitmq/rabbitmq-env.conf

RABBITMQ_NODE_IP_ADDRESS=192.168.245.129

RABBITMQ_NODE_PORT=5672

RABBITMQ_LOG_BASE=/u1/logs/rabbitmq/log

RABBITMQ_MNESIA_BASE=/u1/logs/rabbitmq/mnesia

RABBITMQ_PLUGINS_DIR=/usr/local/rabbitmq/plugins

 

#配置rabbitmqweb管理插件

[root@gy02rabbitmq]#vim etc/rabbitmq/rabbitmq.config

[{rabbitmq_management,

[{listener, [{port, 15672},

{ip, "192.168.245.129"}

]}

]}

].

 

#修改${rabbitmq_home}/sbin/rabbitmqctl和rabbitmq-server脚本

[root@linuxblindsbin]#catrabbitmqctl

exec ${ERL_DIR}erl \

-pa “${RABBITMQ_HOME}/ebin” \

-noinput \

-hidden \

${RABBITMQ_CTL_ERL_ARGS} \

-sname rabbitmqctl$$ \

-boot “${CLEAN_BOOT_FILE}” \

-s rabbit_control_main \

-nodename $RABBITMQ_NODENAME \

-setcookie cookie \           <—-添加

-extra “$@”
[root@linuxblindsbin]# cat rabbitmq-server

-mnesia dir”\”${RABBITMQ_MNESIA_DIR}\”" \

-setcookie cookie \           <—-添加

${RABBITMQ_SERVER_START_ARGS} \

“$@”

 

#激活rabbitmq管理插件并启动服务

[root@linuxblindsbin]# ./rabbitmq-plugins enable rabbitmq_management

[root@linuxblindsbin]# ./rabbitmq-server –detached

[root@linuxblindsbin]# ./rabbitmqctl stop#关闭服务用以同步

#查看erlang集群中必须的cookie值,且要保证此值在全局中的唯一性

[root@linuxblindlocal]#catrabbitmq/.erlang.cookie

RSKHIGVPROEERJUYXLFT

 

#同步rabbitmq至128和130服务器,其目的是保持集群环境一致

[root@linuxblindlocal]# tar zcf rabbitmq.tar.gz rabbitmq

[root@linuxblindlocal]# scp rabbitmq.tar.gz 192.168.245.128:/usr/local/

[root@linuxblindlocal]# scp rabbitmq.tar.gz192.168.245.130:/usr/local/

 

#以下是在slaver机器上操作,以128为例(130同样)

[root@linuxblind2local]# mkdir -p /u1/logs/rabbitmq/{log,mnesia}

[root@linuxblind2local]# tar zxf rabbitmq.tar.gz

[root@linuxblind2local]# vim rabbitmq/etc/rabbitmq/rabbitmq-env.conf

RABBITMQ_NODE_IP_ADDRESS=192.168.245.128

[root@linuxblind2local]# vim rabbitmq/etc/rabbitmq/rabbitmq.config

[{rabbitmq_management,

[{listener, [{port, 15672},

{ip, "192.168.245.128"}

]}

]}

].

1.3 编写rabbitmq集群脚本

#master上

[root@linuxblind sbin]# cat cluster.sh

/usr/local/rabbitmq/sbin/rabbitmqctl stop_app

/usr/local/rabbitmq/sbin/rabbitmqctl reset

/usr/local/rabbitmq/sbin/rabbitmqctl start_app

[root@linuxblind sbin]# chmod +x cluster.sh

 

#slaver上

[root@linuxblind2 sbin]#cat cluster.sh

/usr/local/rabbitmq/sbin/rabbitmqctl stop_app

/usr/local/rabbitmq/sbin/rabbitmqctl reset

/usr/local/rabbitmq/sbin/rabbitmqctl join_cluster –ramrabbit@linuxblind

/usr/local/rabbitmq/sbin/rabbitmqctl start_app

[root@linuxblind2 sbin]# chmod +x cluster.sh

 

1.4 启动与验证

#先启动master,以disk方式加入集群; 然后再启动slaver机器,以ram方式加入集群

#启动服务

[root@linuxblind sbin]# ./rabbitmq-srver -detached

[root@linuxblind2 sbin]# ./rabbitmq-srver -detached

[root@linuxblind3 sbin]# ./rabbitmq-srver -detached

 

#加入集群
[root@linuxblind sbin]# ./cluster.sh
[root@linuxblind2 sbin]# ./cluster.sh

[root@linuxblind3 sbin]# ./cluster.sh

 

#查看状态,出现以下内容表示ok

[root@linuxblind sbin]#./rabbitmqctlcluster_status

Cluster status ofnode rabbit@linuxblind …

[{nodes,[{disc,[rabbit@linuxblind]},

{ram,[rabbit@linuxblind3,rabbit@linuxblind2]}]},

{running_nodes,[ rabbit@linuxblind2,rabbit@linuxblind3,rabbit@linuxblind]},

{partitions,[]}]

…done.

 

#cluster for iptables on centos 6.2

[root@linuxblind2 local]# vimrabbitmq/etc/rabbitmq/rabbitmq.config

[

{kernel, [{inet_dist_listen_min,9100},{inet_dist_listen_max, 9105}]}

].

[root@linuxblind2 local]# vim /etc/sysconfig/iptables

-A INPUT -m state –state NEW -m tcp -p tcp –dport 5672-j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 4369-j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 9100:9105-j ACCEPT

 

#4369 for epmd(Erlang Port Mapper Daemon)

#5672 for rabbitmq server

[root@linuxblind2 local]# /etc/init.d/iptablesrestart  or  service iptables restart

 

 

二.其他常用测试命令

#查看是否能ping通其他集群节点

[root@linuxblind sbin]# ./rabbitmqctl eval ‘net_adm:ping(rabbit@linuxblind2).’

pong       <—– 表示成功

…done.

 

pang       <—– 表示失败

…done.

 

命令介绍:http://www.rabbitmq.com/man/rabbitmqctl.1.man.html

三.问题集锦

问题1.

=WARNINGREPORT==== 24-Jun-2013::06:11:02 ===

global:rabbit@linuxblind3 failed to connect to rabbit@linuxblind2

解决办法:
[root@linuxblind2 sbin]#service iptables stop

 

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>