亲宝软件园·资讯

展开

Centos7.3 RabbitMQ分布式集群 Centos7.3 RabbitMQ分布式集群搭建示例

zhdya 人气:0

本文介绍了Centos7.3 RabbitMQ分布式集群搭建示例,分享给大家,具体如下:

注意事项

centos 7.x 关闭firewall

三台机器:

172.17.250.97   rabbiMQ01
172.17.250.98   rabbiMQ03
172.17.250.99   rabbiMQ02

配置 hosts

172.17.250.97 fz-rabbitMQ01
172.17.250.99 fz-rabbitMQ02
172.17.250.98 fz-rabbitMQ03

$ systemctl stop firewalld.service # 停止firewall

不想关闭防火墙,就开放15672端口,设置之后可以通过网页方式管理MQ

安装安装iptables防火墙

yum install iptables-services

添加配置

iptables -I INPUT -p tcp --dport 5672 -j ACCEPT
iptables -I INPUT -p tcp --dport 15672 -j ACCEPT

保存配置

service iptables save

重启

systemctl restart iptables.service

设置开机自启动

systemctl enable iptables.service

安装

安装 Erlang

RabbitMQ 安装需要依赖 Erlang 环境

$ cd /usr/local/src
$ wget http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.centos.x86_64.rpm

$ yum install erlang-19.0.4-1.el7.centos.x86_64.rpm -y

安装 RabbitMQ

$ cd /usr/local/src
$ wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.10/rabbitmq-server-3.6.10-1.el7.noarch.rpm
$ yum install rabbitmq-server-3.6.10-1.el7.noarch.rpm -y

仅仅rabbitMQ01运行:

rabbitmq-server -detached

之后运行

rabbitmqctl status

查看rabbitmq是否正常启动。

创建集群:

首先搞个密钥认证:

[root@fz-rabbitMQ01 src]# ssh-keygen

[root@fz-rabbitMQ01 src]# ssh-copy-id -pXXXXX -i ~/.ssh/id_rsa.pub [email protected]

[root@fz-rabbitMQ01 src]# ssh-copy-id -pXXXXX -i ~/.ssh/id_rsa.pub [email protected]

读取rabbitMQ01节点的cookie, 并复制到其他节点(节点之间通过cookie确定相互是否可通信)。 cookie存放在/var/lib/rabbitmq/.erlang.cookie或者$HOME/.erlang.cookie中。

[root@fz-rabbitMQ01 src]# scp -PXXXXX /var/lib/rabbitmq/.erlang.cookie 172.17.250.99:/var/lib/rabbitmq
/etc/bashrc:行94: soruce: 未找到命令
.erlang.cookie                                100% 20  0.0KB/s 00:00 
[root@fz-rabbitMQ01 src]# scp -PXXXXX /var/lib/rabbitmq/.erlang.cookie 172.17.250.98:/var/lib/rabbitmq
/etc/bashrc:行94: soruce: 未找到命令
.erlang.cookie

逐个启动节点

rabbitmq-server -detached

建立集群

分别在rabbitMQ02和rabbitMQ03上面执行即可

rabbitmqctl stop_app 

rabbitmqctl reset 

rabbitmqctl join_cluster rabbit@fz-rabbitMQ01 

rabbitmqctl start_app

最后通过rabbitmqctl cluster_status查看集群的状态信息:

[root@fz-rabbitMQ01 src]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@fz-rabbitMQ01'
[{nodes,[{disc,['rabbit@fz-rabbitMQ01','rabbit@fz-rabbitMQ02',
    'rabbit@fz-rabbitMQ03']}]},
 {running_nodes,['rabbit@fz-rabbitMQ03','rabbit@fz-rabbitMQ02',
     'rabbit@fz-rabbitMQ01']},
 {cluster_name,<<"[email protected]">>},
 {partitions,[]},
 {alarms,[{'rabbit@fz-rabbitMQ03',[]},
   {'rabbit@fz-rabbitMQ02',[]},
   {'rabbit@fz-rabbitMQ01',[]}]}]

在访问web(http://xxx.xxx.xxx.xxx:15672)时, 如果在Overview中的Nodes部分看到“Node statistics not available”的信息,说明在该节点上web管理插件还未启用。

3个节点都需要运行:

[root@fz-rabbitMQ01 src]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
 amqp_client
 cowlib
 cowboy
 rabbitmq_web_dispatch
 rabbitmq_management_agent
 rabbitmq_management

Applying plugin configuration to rabbit@fz-rabbitMQ01... started 6 plugins.

遇到的问题

Error: unable to connect to node '[email protected]': nodedown

解决方案:执行如下两条命令:

# /sbin/service rabbitmq-server stop
# /sbin/service rabbitmq-server start

然后再次执行:即可

rabbitmqctl stop_app 
rabbitmqctl reset 
rabbitmqctl join_cluster rabbit@fz-rabbitMQ01 
rabbitmqctl start_app

加载全部内容

相关教程
猜你喜欢
用户评论