keepalived + Hadproxy + MySQL配置文件 (已验证)

该配置,本人在keepalived v1.3.5和Keepalived v2.0.19 均验证可用。

HA-Proxy version 1.5.18

keepalived 配置:

#主keeplived的配置

! Configuration File for keepalived

global_defs {
   router_id ha_vip1
}

vrrp_script chk_haproxy
{
     script "/etc/keepalived/scripts/h_check.sh"
     interval 2
     timeout 2
     fall 3
}

vrrp_instance haproxy {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 51
    }
    virtual_ipaddress {
        192.168.44.120
    }
    track_script {
         chk_haproxy
    }
    notify_master "/etc/keepalived/scripts/haproxy_master.sh"
}

#从keeplived的配置

! Configuration File for keepalived

global_defs {
   router_id ha_vip2
}

vrrp_script chk_haproxy
{
     script "/etc/keepalived/scripts/h_check.sh"
     interval 2
     timeout 2
     fall 3
}

vrrp_instance haproxy {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 51
    }
    virtual_ipaddress {
        192.168.44.120
    }
    track_script {
         chk_haproxy
    }
    notify_master "/etc/keepalived/scripts/haproxy_master.sh"
}

 

检测脚本

[root@node-1 scripts]# cat check.sh

#!/bin/bash
LOGFILE="/etc/keepalived/log/keepalived-haproxy-state.log"
date >> $LOGFILE
A=`ps -C nginx --no-header |wc -l`
echo "[infor]: Check haproxy health status is OK ?" >> $LOGFILE
if [ $A -eq 0 ];then
   echo "[ERROR]: haproxy status is down. try restart haproxy service!" >> $LOGFILE
   systemctl start nginx  #haproxy.service
   sleep 2
   if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
      echo "[ERROR]: check_haproxy restart is fail! Stop the local keepalived service. And change the vip to another host!" >> $LOGFILE
      systemctl stop keepalived.service
   else
      echo "[infor]: check_haproxy restart is sucess!" >> $LOGFILE
   fi
else
  echo "[infor]: Haproxy health status is OK! " >> $LOGFILE
fi
echo "-- -- -- -- -- -- -- -- -- -- -- -- -- --- -- -- --- --- -- -- " >> $LOGFILE

脚本2;

[root@node-1 scripts]# cat haproxy_master.sh

#!/bin/bash
LOGFILE="/etc/keepalived/log/keepalived-haproxy-state.log"
date >> $LOGFILE
echo "MongoDB Being Master ..." >> $LOGFILE
echo "-- -- -- -- -- -- -- -- -- -- -- -- -- --- -- -- --- --- -- -- " >> $LOGFILE

 

已验证可用:

haproxy(负载均衡)

HA-Proxy version 1.5.18

##########haproxy的配置文件

global
        daemon
        nbproc 1
        pidfile /var/run/haproxy.pid

defaults
        mode tcp               #默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OK

        retries 3               #两次连接失败就认为是服务器不可用,也可以通过后面设置
        option redispatch       #当serverId对应的服务器挂掉后,强制定向到其他健康的服务器
        option abortonclose     #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接
        maxconn 4096            #默认的最大连接数
        timeout connect 5000ms  #连接超时
        timeout client 30000ms  #客户端超时
        timeout server 30000ms  #服务器超时
        timeout check 2000      #=心跳检测超时
        log 127.0.0.1 local0 err #[err warning info debug]



listen configMysql
        bind 0.0.0.0:4444     #对外提供服务的端口
        mode tcp
        maxconn 4086
        server s1 172.17.3.130:4000    #因为的数据库是TiDB,故这里端口为:4000
        server s2 172.17.3.131:4000
        server s3 172.17.3.132:4000

 

 

你可能感兴趣的:(数据库工具)