1. rmp安装rabbitmq
#erlang
wget https://github.com/rabbitmq/erlang-rpm/releases/download/v20.3.8.9/erlang-20.3.8.9-1.el7.centos.x86_64.rpm
# socat
wget http://repo.iotti.biz/CentOS/7/x86_64/socat-1.7.3.2-5.el7.lux.x86_64.rpm
# rabbitmq, el7和el6针对的是linux版本,centos7或者6
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.6/rabbitmq-server-3.7.6-1.el7.noarch.rpm
# 安装
rpm -ivh erlang-20.3.8.9-1.el7.centos.x86_64.rpm
rpm socat-1.7.3.2-5.el7.lux.x86_64.rpm
rpm rabbitmq-server-3.7.6-1.el7.noarch.rpm
# 配置文件的位置
vim /usr/lib/rabbitmq/lib/rabbitmq_server-3.6.5/ebin/rabbit.app
# 用户添加
rabbitmqctl add_user admin admin
#添加用户,后面两个参数分别是用户名和密码,我这都用superrd了。
# set_permissions [-p <vhost>] <username> <conf> <write> <read>
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
#添加权限
rabbitmqctl set_user_tags admin administrator #修改用户角色
# web插件
rabbitmq-plugins enable rabbitmq_management
2. 搭建集群
前提:安装三个节点的rabbitmq,分别在s130,s131,s132
# 1. 停止三个节点
rabbitmqctl stop
# 2. 集群启动,三个节点都启动
rabbitmq-server -detached
# 假如s130为主节点,复制s130中的.erlang.cookie到s131,s132
scp /var/lib/rabbitmq/.erlang.cookie root@s131:/var/lib/rabbitmq/
scp /var/lib/rabbitmq/.erlang.cookie root@s132:/var/lib/rabbitmq/
# 3. s131操作,s132亦是如此
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@s130
rabbitmqctl start_app
# 5.集群收缩
rabbitmqctl forget_cluster_node rabbit@s131
# 6. 集群名称修改
rabbitmqctl set_cluster_name rabbitmq_itcloud
如图所示集群节点加入成功
集群状态查看
[root@s130 rabbitmq]# rabbitmqctl cluster_status
Cluster status of node rabbit@s130 ...
[{nodes,[{disc,[rabbit@s130,rabbit@s131,rabbit@s132]}]},
{running_nodes,[rabbit@s132,rabbit@s131,rabbit@s130]},
{cluster_name,<<"rabbitmq_itcloud">>},
{partitions,[]},
{alarms,[{rabbit@s132,[]},{rabbit@s131,[]},{rabbit@s130s
总结:
有很多资料要做RabbitMQ的负载均衡,我觉得没有必要,我们提前建好队列,将队列分布在不同的节点上面,依然可以达到HaProxy负载均衡的效果,最主要可以省去很多运维的繁琐。