我是靠谱客的博主 危机西牛,最近开发中收集的这篇文章主要介绍Rabbitmq镜像模式集群+Haproxy+KeepalivedRabbitmq镜像模式集群+Haproxy+Keepalived,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Rabbitmq镜像模式集群+Haproxy+Keepalived

在这里插入图片描述

1、部署 RabbitMQ Cluster(HA)

1)、3台centos7操作系统,ip分别为:
10.11.59.113 10.11.59.114 10.11.59.115

域名解析:

#### vim /etc/hosts

 10.11.59.113  rabbitmq1

 10.11.59.114  rabbitmq2

 10.11.59.115  rabbitmq3

###scp /etc/hosts 10.11.59.114:/etc/hosts

###scp /etc/hosts 10.11.59.115:/etc/hosts

确定三台rabbitmq可以ping通

ping rabbitmq1 

ping rabbitmq2

ping rabbitmq3

安装依赖的erlang环境(3台)

yum -y install erlang  socat  rabbitmq-server

rabbitmq常用命令

systemctl start rabbitmq-server.service 
systemctl stop rabbitmq-server.service 
systemctl enable rabbitmq-server.service  --now
systemctl enable rabbitmq-server.service  --now

启动rabbitmq

systemctl start rabbitmq-server.service

账号配置(安装启动后其实还不能在其它机器访问,rabbitmq 默认的 guest 账号只能在本地机器访问, 如果想在其它机器访问必须配置其它账号)

配置管理员账户:
#可以创建管理员用户,负责整个 MQ 的运维
rabbitmqctl add_user admin admin
#赋予其 administrator 角色
rabbitmqctl set_user_tags admin administrator
# 创建 RabbitMQ 监控用户,负责整个 MQ 的监控
rabbitmqctl add_user  user_monitoring  passwd_monitor
rabbitmqctl set_user_tags user_monitoring monitoring
# 创建某个项目的专用用户,只能访问项目自己的 virtual hosts
rabbitmqctl set_user_tags user_monitoring management
#创建和赋角色完成后查看并确认
rabbitmqctl list_users  
#启动 rabbitmq 内置 web 插件, 管理 rabbitmq 账号等信息 (3 台)
rabbitmq-plugins enable rabbitmq_management 

统一 erlang.cookie 文件中 cookie 值

​ (必须使集群中也就是rabbitmq2,rabbitmq3这两台机器的.erlang.cookie 文件中 cookie 值一致,且权限为 owner 只读。)

scp /var/lib/rabbitmq/.erlang.cookie 10.11.59.114:/var/lib/rabbitmq/.erlang.cookie

scp /var/lib/rabbitmq/.erlang.cookie 10.11.59.115:/var/lib/rabbitmq/.erlang.cookie
#rabbitmq2  rabbitmq3
chmod 600 /var/lib/rabbitmq/.erlang.cookie

Rabbitmq 集群添加节点

( 在 rabbitmq2,rabbitmq3 分别执行(–ram 基于内存),重启 rabbitmq1机器中 rabbitmq 的服务)

rabbitmqctl stop_app
rabbitmqctl join_cluster --ram rabbit@rabbitmq1
rabbitmqctl start_app
rabbitmq-plugins enable rabbitmq_management
systemctl restart rabbitmq-server.service 

访问http://rabbitmq1:15672

在这里插入图片描述

镜像模式要依赖 policy 模块:设置那些Exchanges或者queue的数据需要如何复制,同步

rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'

在这里插入图片描述

在这里插入图片描述

2、配置haproxy

两台ip:

10.11.59.142 10.11.59.143

yum -y install haproxy
cp -rf /etc/haproxy/haproxy.cfg{,.bak}
cat >>/etc/haproxy/haproxy.cfg <<eof
global
    log 127.0.0.1 local0
    user haproxy
    group haproxy
    daemon
    maxconn 4096

defaults
    log global
    mode tcp
    option tcplog
    option dontlognull
    retries 3
    maxconn 2000
    timeout connect 5s
    timeout client 120s
    timeout server 120s

listen rabbitmq_cluster 
        bind 0.0.0.0:5671
        mode tcp
        balance roundrobin
        server rabbitmq1 10.11.59.113:5672 check inter 5000 rise 2 fall 3 weight 1
        server rabbitmq2 10.11.59.114:5672 check inter 5000 rise 2 fall 3 weight 1
        server rabbitmq3 10.11.59.115:5672 check inter 5000 rise 2 fall 3 weight 1
listen monitor 
        bind 0.0.0.0:8100
        mode http
        option httplog
        stats enable
        stats uri /haproxy
        stats refresh 5s
eof

在这里插入图片描述
在这里插入图片描述

3、给haproxy配置HA:(两台haproxy做)

yum -y install keepalived
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak

​ keepalived的master配置:

cat >> /etc/keepalived/keepalived.conf <<eof
! Configuration File for keepalived

global_defs {
router_id haproxy-master
}
vrrp_script check_run {
script "/etc/keepalived/keepalived_check_haproxy.sh"
interval 5
}

vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 89
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.11.59.110/24
}
track_script {
check_run
}
}
eof

keepalived的slave配置:

cat >> /etc/keepalived/keepalived.conf <<eof

! Configuration File for keepalived

global_defs {
router_id haproxy-slave
}
vrrp_script check_run {
script "/etc/keepalived/keepalived_check_haproxy.sh"
interval 5
}

vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 89
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.11.59.110/24
}
track_script {
check_run
}
}
eof

haproxy 健康检测脚本(两台都要做):

cat >>/etc/keepalived/keepalived_check_haproxy.sh <<eof
#!/bin/bash
systemctl status haproxy &>/dev/null
if [ $? -ne 0 ] ;then 
#   service keepalived stop
    systemctl stop keepalived
fi
eof

haproxy 健康检测脚本(两台都要做):

cat >>/etc/keepalived/keepalived_check_haproxy.sh <<eof
#!/bin/bash
systemctl status haproxy &>/dev/null
if [ $? -ne 0 ] ;then 
#   service keepalived stop
    systemctl stop keepalived
fi
eof

在这里插入图片描述

最后

以上就是危机西牛为你收集整理的Rabbitmq镜像模式集群+Haproxy+KeepalivedRabbitmq镜像模式集群+Haproxy+Keepalived的全部内容,希望文章能够帮你解决Rabbitmq镜像模式集群+Haproxy+KeepalivedRabbitmq镜像模式集群+Haproxy+Keepalived所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(35)

评论列表共有 0 条评论

立即
投稿
返回
顶部