浅析RabbitMQ 集群
角色 | IP地址 | 主机名 | MQ版本 |
Master | 192.168.103.83 | rabbit-jxs-10383 | 3.5.2-1 |
slave | 192.168.103.84 | rabbit-jxs-10384 | 3.5.2-1 |
1) 配置yum 源 (Master/slave 同时配置)
yum -y install epel-release
1) 安装erlang (Master/slave 同时配置)
Yum –y install erlang
http://www.rabbitmq.com/releases/rabbitmq-server/v3.5.2/rabbitmq-server-3.5.2-1.noarch.rpm
2) 安装RabbitMQ (Master/slave 同时配置)
rpm –vih rababitmq-server-3.5.2-1.noarch.rpm
3) 修改主机名
a) Hostname rabbit-jxs-10383 #slave
b) Vim /etc/sysconfig/network
Hostname= rabbit-jxs-10383
c) Vim /etc/hosts (Master/slave 同时配置)
192.168.103.83 rabbit-jxs-10383
192.168.103.84 rabbit-jxs-10384
d) MQ WEB 配置
[rabbitmq_management,rabbitmq_management_agent].
e) MQ 服务配置
[root@rabbit-jxs-10383 rabbitmq]# cat rabbitmq.conf
% This file managed by Puppet
% Template Path: rabbitmq/templates/rabbitmq.config
[
{rabbit, [
{default_user, <<"autohome">>},
{default_pass, <<"S7!CUy3lZ5;_[K">>},
{tcp_listeners,[5672]},
{cluster_partition_handling, ignore}
]},
{kernel, [
]}
].
% EOF
f) MQ 环境变量配置
[root@rabbit-jxs-10383 rabbitmq]# cat rabbitmq-env.conf
RABBITMQ_NODE_PORT=5672
MNESIA_BASE=/data/rabbitmq/data
LOG_BASE=/data/rabbitmq/log
g) MQ 创建目录
Mkdir /data/rabitmq/data –p
Mkdir /data/rabbitmq/log –p
Chown rabbitmq:rabbitmq /data/rabbitmq –R
h) MQ启动服务
Service rabbitmq-serve restart
Chkconfig rabbitmq-server on
i) MQ 端口监听
[root@rabbit-jxs-10383 rabbitmq]# netstat -tnpl |grep 567
tcp 0 0 0.0.0.0:5672 0.0.0.0:* LISTEN 10020/beam.smp
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 10020/beam.smp
tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 10020/beam.smp
[root@rabbit-jxs-10383 rabbitmq]#
4) MQ slave 服务配置
a) 同步Master RabbitMQ 文件配置
Scp –p 30000 192.168.103.83:/etc/rabbitmq/* /etc/rabbitmq/
Chown rabbitmq:rabbitmq –R /etc/rabbitmq/
b) MQ 创建工作目录
Mkdir /data/rabbitmq/data –p
Mkdir /data/rabbitmq/log –p
Chown rabbitmq:rabbitmq –R /data/rabbitmq
c) 同步Master Rabbitmq .erlang.cookie
Scp –p 30000 192.168.103.83:/var/lib/rabbitmq/.erlang.cookie ./var/lib/rabbitmq/
Chown rabbitmq:rabbitmq /var/lib/rabbitmq
d) 启动MQ slave 服务
Service rabbitmq-server restart
chkconfig rabbitmq on
e) 停止Master MQ
rabbitmqctl stop_app
f) 清空Master MQ信息
rabbitmqctl reset
g) 加入10384 到MQ集群中
rabbitmqctl join_cluster rabbit@rabbit-jxs-10384
h) 启动MQmaster 服务
rabbitmqctl start_app
i) 查看状态
[root@rabbit-jxs-10383 ~]# rabbitmqctl cluster_status
Cluster status of node ‘rabbit@rabbit-jxs-10383‘ ...
[{nodes,[{disc,[‘rabbit@rabbit-jxs-10383‘,‘rabbit@rabbit-jxs-10384‘]}]},
{running_nodes,[‘rabbit@rabbit-jxs-10384‘,‘rabbit@rabbit-jxs-10383‘]},
{cluster_name,<<"rabbit@rabbit-jxs-10383">>},
{partitions,[]}]
1) 创建Rabbit 管理用户
a) rabbitmqctl add_user admin admin
2) 赋予用户权限
a) rabbitmqctl set_user_tags admin administrator
3) MQ 镜像实现
a) rabbitmqctl set_policy ha-all "^" ‘{"ha-mode":"all"}‘
4) 完成MQ配置
a) http://192.168.103.84:15672
本文出自 “欢迎评论,欢迎点赞” 博客,转载请与作者联系!
原文地址:http://swq499809608.blog.51cto.com/797714/1665970