rabbitmq部署在机房,添加镜像集群后,需要做高可用,当单机故障时可以切换到另外一台

1.修改rabbitmq的配置,引入修改相关配置的文件

# vim /usr/local/rabbitmq/sbin/rabbitmq-defaults
# 添加这行
CONFIG_FILE=${SYS_PREFIX}/etc/rabbitmq/rabbitmq.conf

# 添加修改端口的配置
vim /usr/local/rabbitmq/etc/rabbitmq/rabbitmq.conf
#数据管理端口(默认端口为5672)
listeners.tcp.default=5673
#界面管理端口(默认端口为15672)
management.tcp.port=15672
management.tcp.ip=0.0.0.0

chown -R rabbitmq.rabbitmq /etc/rabbitmq/

2.配置负载均衡程序haproxy

添加haproxy的相关配置
useradd haproxy -s /sbin/nologin

# 编写 haproxy 的启动脚本

vim /etc/init.d/haproxy

#!/bin/sh
#
# chkconfig: - 85 15
# description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \
#              for high availability environments.
# processname: haproxy
# config: /etc/haproxy/haproxy.cfg
# pidfile: /var/run/haproxy.pid# Script Author: Simon Matter <simon.matter@invoca.ch>
# Version: 2004060600# Source function library.
if [ -f /etc/init.d/functions ]; then. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then. /etc/rc.d/init.d/functions
elseexit 0
fi# Source networking configuration.
. /etc/sysconfig/network# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0# This is our service name
BASENAME=`basename $0`
if [ -L $0 ]; thenBASENAME=`find $0 -name $BASENAME -printf %l`BASENAME=`basename $BASENAME`
fiBIN=/usr/sbin/$BASENAMECFG=/etc/$BASENAME/$BASENAME.cfg
[ -f $CFG ] || exit 1PIDFILE=/var/run/$BASENAME.pid
LOCKFILE=/var/lock/subsys/$BASENAMERETVAL=0start() {quiet_checkif [ $? -ne 0 ]; thenecho "Errors found in configuration file, check it with '$BASENAME check'."return 1fiecho -n "Starting $BASENAME: "daemon $BIN -D -f $CFG -p $PIDFILERETVAL=$?echo[ $RETVAL -eq 0 ] && touch $LOCKFILEreturn $RETVAL
}stop() {echo -n "Shutting down $BASENAME: "killproc $BASENAME -USR1RETVAL=$?echo[ $RETVAL -eq 0 ] && rm -f $LOCKFILE[ $RETVAL -eq 0 ] && rm -f $PIDFILEreturn $RETVAL
}restart() {quiet_checkif [ $? -ne 0 ]; thenecho "Errors found in configuration file, check it with '$BASENAME check'."return 1fistopstart
}reload() {if ! [ -s $PIDFILE ]; thenreturn 0fiquiet_checkif [ $? -ne 0 ]; thenecho "Errors found in configuration file, check it with '$BASENAME check'."return 1fi$BIN -D -f $CFG -p $PIDFILE -sf $(cat $PIDFILE)
}check() {$BIN -c -q -V -f $CFG
}quiet_check() {$BIN -c -q -f $CFG
}rhstatus() {status $BASENAME
}condrestart() {[ -e $LOCKFILE ] && restart || :
}# See how we were called.
case "$1" instart)start;;stop)stop;;restart)restart;;reload)reload;;condrestart)condrestart;;status)rhstatus;;check)check;;*)echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status|check}"exit 1
esacexit $?

3.添加haproxy的配置

# cat /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global# to have these messages end up in /var/log/haproxy.log you will# need to:## 1) configure syslog to accept network log events.  This is done#    by adding the '-r' option to the SYSLOGD_OPTIONS in#    /etc/sysconfig/syslog## 2) configure local2 events to go to the /var/log/haproxy.log#   file. A line like the following can be added to#   /etc/sysconfig/syslog##    local2.*                       /var/log/haproxy.log#log         127.0.0.1 local2chroot      /usr/local/haproxypidfile     /usr/local/haproxy/haproxy.pidmaxconn     50000user        haproxygroup       haproxydaemonnbproc      1# turn on stats unix socketstats socket /usr/local/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------defaultsmode                    tcplog                     global
#   option                  httplogoption                  tcplogoption                  dontlognulloption             http-server-close
#   option forwardfor  except 127.0.0.0/8
#   option     redispathretries                 3timeout queue           1mtimeout connect         10stimeout client          2mtimeout server          2mtimeout http-keep-alive 10stimeout check           10smaxconn                 3000#---------------------------------------------------------------------
# HAProxy statistics backend
#---------------------------------------------------------------------
listen haproxy-monitoring bind *:4321mode  httpstats enablestats refresh           30sstats uri               /statsstats realm             HAProxy\ Statisticsstats auth              admin:adminstats hide-version#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
listen rabbitmq_cluster bind 0.0.0.0:5672mode tcpbalance roundrobinserver rabbitmq_01 192.168.254.187:5673 check inter 2000 rise 2 fall 3server rabbitmq_02 192.168.254.196:5673 check inter 2000 rise 2 fall 3#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
listen rabbitmq_webbind 0.0.0.0:27651mode tcpbalance roundrobinserver rabbitmq_01 192.168.254.187:15672 check inter 2000 rise 2 fall 3server rabbitmq_02 192.168.254.196:15672 check inter 2000 rise 2 fall 3#---------------------------------------------------------------------
# round robin balancing between the various backends

# 配置开机自动启动

chkconfig --add haproxy
chkconfig haproxy on
chkconfig --list haproxy

4.配置keepvid
# 自动启动haproxy的监控脚本
mkdir /etc/keepalived/
vim /etc/keepalived/check_haproxy.sh

#!/bin/bash
A=`ps -C haproxy --no-header | wc -l`
if [ $A -eq 0 ];then
#/usr/local/haproxy/sbin/haproxy -f /etc/haproxy/haproxy.cfg &
killall haproxy
/etc/init.d/haproxy start
echo "haproxy start done" >>/etc/haproxy/haproxy_start.log
sleep 3
if [ `ps -C haproxy --no-header | wc -l` -eq 0 ];then
/etc/init.d/keepalived stop
echo "keepalived stop"
fi
fi

chmod +x /etc/keepalived/check_haproxy.sh
# keepalived的启动文件

vim /etc/init.d/keepalived

#!/bin/sh
#
# Startup script for the Keepalived daemon
#
# processname: keepalived
# pidfile: /var/run/keepalived.pid
# config: /etc/keepalived/keepalived.conf
# chkconfig: - 21 79
# description: Start and stop Keepalived# Source function library
. /etc/rc.d/init.d/functions# Source configuration file (we set KEEPALIVED_OPTIONS there)
. /etc/sysconfig/keepalivedRETVAL=0prog="keepalived"start() {echo -n $"Starting $prog: "daemon keepalived ${KEEPALIVED_OPTIONS}RETVAL=$?echo[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
}stop() {echo -n $"Stopping $prog: "killproc keepalivedRETVAL=$?echo[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
}reload() {echo -n $"Reloading $prog: "killproc keepalived -1RETVAL=$?echo
}# See how we were called.
case "$1" instart)start;;stop)stop;;reload)reload;;restart)stopstart;;condrestart)if [ -f /var/lock/subsys/$prog ]; thenstopstartfi;;status)status keepalivedRETVAL=$?;;*)echo "Usage: $0 {start|stop|reload|restart|condrestart|status}"RETVAL=1
esacexit $RETVAL

# 配置 keepvid.conf

# master
vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived
global_defs {notification_email {pengll@chinasoft.com}notification_email_from wsadmin@chinasoft.comsmtp_server 1.1.1.2smtp_connect_timeout 30router_id LVS_MQ_DEVEL
}vrrp_script chk_haproxy_status {script "/bin/bash /etc/keepalived/check_haproxy.sh"interval 3weight 2
}vrrp_instance VI_1 {state MASTER  ##备份服务器上将MASTER改为BACKUP   interface eth0virtual_router_id 71garp_master_delay 2 #主从切换时间,单位为秒。priority 100advert_int 1authentication {auth_type PASSauth_pass rabbitmqpass}track_script {chk_haproxy_status}virtual_ipaddress {192.168.254.86}
}vrrp_instance VI_2 {state MASTERinterface eth1virtual_router_id 71garp_master_delay 2 #主从切换时间,单位为秒。priority 88advert_int 1authentication {auth_type PASSauth_pass rabbitmqpass}track_script {chk_haproxy_status}virtual_ipaddress {1.1.1.1}
}

# slave
vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived
global_defs {notification_email {pengll@chinasoft.com}notification_email_from wsadmin@chinasoft.comsmtp_server 1.1.1.2smtp_connect_timeout 30router_id LVS_MQ_DEVEL
}vrrp_script chk_haproxy_status {script "/bin/sh /etc/keepalived/check_haproxy.sh"interval 5    #运行间隔weight 2
}vrrp_instance VI_1 {state BACKUP  ##备份服务器上将MASTER改为BACKUP   interface eth0virtual_router_id 71garp_master_delay 2 #主从切换时间,单位为秒。priority 99 ##此处需要比master值小advert_int 1   ###MASTER与BACKUP节点间同步检查的时间间隔,单位为秒,两个节点设置必须一样authentication {auth_type PASSauth_pass rabbitmqpass}track_script {chk_haproxy_status}virtual_ipaddress {192.168.254.86}
}vrrp_instance VI_2 {state BACKUPinterface eth1virtual_router_id 71garp_master_delay 2 #主从切换时间,单位为秒。priority 87 ##此处需要比master值小advert_int 1 #MASTER与BACKUP节点间同步检查的时间间隔,单位为秒,两个节点设置必须一样authentication {auth_type PASSauth_pass rabbitmqpass}track_script {chk_haproxy_status}virtual_ipaddress {1.1.1.1}
}

# 系统配置
vim /etc/sysconfig/keepalived

# Options for keepalived. See `keepalived --help' output and keepalived(8) and
# keepalived.conf(5) man pages for a list of all options. Here are the most
# common ones :
#
# --vrrp               -P    Only run with VRRP subsystem.
# --check              -C    Only run with Health-checker subsystem.
# --dont-release-vrrp  -V    Dont remove VRRP VIPs & VROUTEs on daemon stop.
# --dont-release-ipvs  -I    Dont remove IPVS topology on daemon stop.
# --dump-conf          -d    Dump the configuration data.
# --log-detail         -D    Detailed log messages.
# --log-facility       -S    0-7 Set local syslog facility (default=LOG_DAEMON)
#KEEPALIVED_OPTIONS="-D -d -S 0"

cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

# 添加开机自动启动keepalived
chkconfig --add keepalived
chkconfig keepalived on
chkconfig --list keepalived

# Options for keepalived. See `keepalived --help' output and keepalived(8) and
# keepalived.conf(5) man pages for a list of all options. Here are the most
# common ones :
#
# --vrrp               -P    Only run with VRRP subsystem.
# --check              -C    Only run with Health-checker subsystem.
# --dont-release-vrrp  -V    Dont remove VRRP VIPs & VROUTEs on daemon stop.
# --dont-release-ipvs  -I    Dont remove IPVS topology on daemon stop.
# --dump-conf          -d    Dump the configuration data.
# --log-detail         -D    Detailed log messages.
# --log-facility       -S    0-7 Set local syslog facility (default=LOG_DAEMON)
#

KEEPALIVED_OPTIONS="-D -d -S 0"

haproxy+keepalived+rabbitmq3.8实现集群的高可用相关推荐

  1. nginx两台文件服务器集群,keepalived结合nginx状态检测脚本实现对web服务器集群的高可用...

    实验环境 两台CentOS-7.5虚拟机 web1:10.0.11.203 web2:10.0.11.204 VIP :10.0.11.210 web类型:nginx 客户端:自用笔记本(win10) ...

  2. K8S集群Master高可用实践

    本文将在前文基础上介绍k8s集群的高可用实践,一般来讲,k8s集群高可用主要包含以下几个内容: 1.etcd集群高可用 2.集群dns服务高可用 3.kube-apiserver.kube-contr ...

  3. 【带你重拾Redis】Redis 哨兵集群实现高可用

    Redis 哨兵集群实现高可用 哨兵的介绍 sentinel,中文名是哨兵.哨兵是 Redis 集群架构中非常重要的一个组件,主要有以下功能: 集群监控:负责监控 Redis master 和 sla ...

  4. 数据库集群和高可用解决方案

    数据库集群和高可用解决方案 参考文章: (1)数据库集群和高可用解决方案 (2)https://www.cnblogs.com/Newd/p/9049873.html 备忘一下.

  5. web应用的负载均衡、集群、高可用(HA)解决方案

    web应用的负载均衡.集群.高可用(HA)解决方案 参考文章: (1)web应用的负载均衡.集群.高可用(HA)解决方案 (2)https://www.cnblogs.com/huojg-21442/ ...

  6. ActiveMQ的集群与高可用

    ActiveMQ的集群与高可用 针对大量的消息吞吐量.对MQ可用性要求非常严格的场景.或者非常复杂的消息处理关系情况下,单个MQ实例通常已经无法满足我们的需要,这时候ActiveMQ的集群和高可用方案 ...

  7. 蚂蚁集团万级规模 k8s 集群 etcd 高可用建设之路

    蚂蚁集团运维着可能是全球最大的 k8s 集群:k8s 官方以 5k node 作为 k8s 规模化的顶峰,而蚂蚁集团事实上运维着规模达到 10k node 规模的 k8s 集群.一个形象的比喻就是,如 ...

  8. 浅谈web应用的负载均衡、集群、高可用(HA)解决方案

    浅谈web应用的负载均衡.集群.高可用(HA)解决方案 转载于:https://www.cnblogs.com/hfultrastrong/p/7887420.html

  9. Redis面试 - 哨兵集群实现高可用

    Redis 哨兵集群实现高可用 哨兵的介绍 sentinel,中文名是哨兵.哨兵是 redis 集群机构中非常重要的一个组件,主要有以下功能: 集群监控:负责监控 redis master 和 sla ...

最新文章

  1. 7篇Nature,2篇Science!这所985高校迎来顶刊大丰收
  2. Spring学习笔记(二)——Spring相关配置属性注入Junit整合
  3. mysql数据类型默认长度_mysql数据类型长度
  4. 【机器学习】异常检测算法(I)
  5. MFC中进度条控件的使用方法
  6. 定义DO/DTO/VO等POJO类时,不要设定任何属性默认值
  7. 33:计算分数加减表达式的值
  8. CRITIC法之python
  9. 小米手环4 NFC版将全渠道开售:垃圾分类超智能
  10. CAS 单点登录模块学习
  11. Android获取Java类名/文件名/方法名/行号
  12. 如何将所有音乐从 iPhone传输到Mac?
  13. paddle2.0实现DNN(minst数据集)
  14. centos:清理磁盘空间
  15. PayPal全力助推中国商家开拓海外市场
  16. NuPlayer源码分析三:解码模块
  17. mysql存小程序获取到的带有表情的昵称_拉取用户信息,带表情的昵称,存储到数据库是???要怎么处理...
  18. 机器学习 (六): Sigmoid 公式推导和理解
  19. 工行网银 火狐浏览器
  20. 基于海思平台与QT框架的高效视频显示

热门文章

  1. 计算机毕业设计之php的网上汽车销售系统
  2. EXCEL带汉字如何求和
  3. CoreOS有状态应用管理的框架--Operator详解
  4. 怎样在服务器上绑定域名解析,服务器怎么绑定域名 服务器绑定域名方法【详细步骤】...
  5. centos备份mysql数据库
  6. Mybatis resultMap 嵌套集合
  7. transformjs 玩转星球
  8. 计算机鼠标怎么设置在哪里,技巧:如何在计算机上调整鼠标移动速度?如何设置鼠标点击?...
  9. mybatis 列索无效的问题:
  10. 以太网与WiFi网速叠加,实现高速下载