1、下载RabbitMQ
vim /etc/hosts
10.10.21.197 rabbit1
10.10.21.198 rabbit2
#分别命名
hostname rabbit1
hostname rabbit2
vim /etc/yum.repos.d/rabbitmq.repo
[bintray-rabbitmq-server]
name=bintray-rabbitmq-rpm
baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.7.x/el/7/
gpgcheck=0
repo_gpgcheck=0
enabled=1
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq-erlang/rpm/erlang/22/el/7
gpgcheck=1
gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1
yum install rabbitmq-server
cp /usr/share/doc/rabbitmq-server-3.7.20/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config
systemctl start rabbitmq-server
2、配置rabbitMQ
rabbitmqctl add_user admin 123456
rabbitmqctl set_permissions admin ".*" ".*" ".*"
rabbitmqctl set_user_tags admin administrator
rabbitmq-plugins enable rabbitmq_management
rabbitmq-plugins list
scp /var/lib/rabbitmq/.erlang.cookie 192.168.10.202:/var/lib/rabbitmq/.erlang.cookie
#两台
chmod 400 /var/lib/rabbitmq/.erlang.cookie
systemctl stop rabbitmq-server
rabbitmq-server -detached
# 在要加入集群的节点操作
rabbitmqctl stop_app #停止应程序
rabbitmqctl reset #清空元数据
rabbitmqctl join_cluster rabbit@rabbit1 --ram #将rabbitmq-server1添加到集群当中,并成为内存节点,不加--ram默认是磁盘节点
rabbitmqctl start_app #不要忘记启动应用程序
# 移除节点
# 软删除
# 如果想要把节点从集群中移除,可使用如下命令实现:
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
rabbitmqctl cluster_status
# 硬删除
# 直接删掉集群中的某个节点
rabbitmqctl forget_cluster_node rabbit@Demo20
# 更改为镜像模式
rabbitmqctl set_policy ha-all "#" '{"ha-mode":"all"}'
3、haproxy集群设置
#####################我把RabbitMQ的管理界面也放在HAProxy后面了###############################
listen rabbitmq_admin
bind 0.0.0.0:15673
server rabbitmq1 10.10.21.197:15672
server rabbitmq2 10.10.21.198:15672
#####################RabbitMQ服务代理###########################################
listen rabbitmq_cluster 0.0.0.0:5673
mode tcp
stats enable
balance roundrobin
option tcpka
option tcplog
timeout client 3h
timeout server 3h
timeout connect 3h
#balance url_param userid
#balance url_param session_id check_post 64
#balance hdr(User-Agent)
#balance hdr(host)
#balance hdr(Host) use_domain_only
#balance rdp-cookie
#balance leastconn
#balance source //ip
server rabbitmq1 10.10.21.197:5672 check inter 5s rise 2 fall 3
#check inter 2000 是检测心跳频率,rise 2是2次正确认为服务器可用,fall 3是3次失败认为服务器不可用
server rabbitmq2 10.10.21.198:5672 check inter 5s rise 2 fall 3