标签:live col mysq code ipaddr family done 配置 backup
#下载keepalived ./configure --prefix=/usr/local Make && make install Atlas主安装keepalived Atlas备安装keepalived
Atlas1 Keepalived.conf文件如下: ! Configuration File for keepalived global_defs { } #自定义vrrp脚本 vrrp_script chk_port { script /etc/keepalived/atlas.sh #60秒检查一次 interval 60 } vrrp_instance VI_1 { #指定节点状态 state BACKUP #制定绑定的网卡 interface eth0 #vrrp 组ID,同一组内必须相同 virtual_router_id 51 #优先权,值大优先级大 priority 100 #组播信息发送间隔 advert_int 1 #禁止抢占 nopreempt #验证信息,两节点设置相同 authentication { auth_type PASS auth_pass 99989 } track_script { chk_port } #虚拟IP,两节点设置相同 virtual_ipaddress { #虚拟IP 申请 192.168.0.221/24 dev eth0 } ##扩展 #notify_master /etc/keepalived/m.sh #notify_backup /etc/keepalived/b.sh }
10秒检查一次,如果3次Atlas都是关闭,停止keepalived服务,vip切换 #!/bin/bash v_port=3100 v_j=0 for ((i=0; i<3; i++)); do #检测端口是否存在,用端口 或者 用进程 v_num=`netstat -npl | grep $v_port | grep mysql-proxy | wc -l` v_mysql_proxy_num=`ps -C mysql-proxy --no-header |wc -l` #端口不在,进程不在,关闭keepalived,切换VIP if [ "$v_num" == "0" -a "$v_mysql_proxy_num" == "0" ] then v_j=`expr $v_j + 1` fi sleep 10 done if [ "$v_j" == "3" ] then killall keepalived fi
! Configuration File for keepalived global_defs { } #自定义vrrp脚本 vrrp_script chk_port { script /etc/keepalived/atlas.sh interval 60 } vrrp_instance VI_1 { #指定节点状态 state BACKUP #制定绑定的网卡 interface eth0 #vrrp 组ID,同一组内必须相同 virtual_router_id 51 #优先权,值大优先级大 priority 100 #组播信息发送间隔 advert_int 1 #禁止抢占 nopreempt #验证信息,两节点设置相同 authentication { auth_type PASS auth_pass 99989 } track_script { chk_port } #虚拟IP,两节点设置相同 virtual_ipaddress { 192.168.0.221/24 dev eth0 } ##扩展 #notify_master /etc/keepalived/m.sh #notify_backup /etc/keepalived/b.sh }
10秒检查一次,如果3次Atlas都是关闭,停止keepalived服务,vip切换 #!/bin/bash v_port=3100 v_j=0 for ((i=0; i<3; i++)); do #检测端口是否存在,用端口 或者 用进程 v_num=`netstat -npl | grep $v_port | grep mysql-proxy | wc -l` v_mysql_proxy_num=`ps -C mysql-proxy --no-header |wc -l` #端口不在,进程不在,关闭keepalived,切换VIP if [ "$v_num" == "0" -a "$v_mysql_proxy_num" == "0" ] then v_j=`expr $v_j + 1` fi sleep 10 done if [ "$v_j" == "3" ] then killall keepalived fi
Atlas1,Atlas2 keepalived配置相同,BACKUP-BACKUP
三次扫描3100端口,如果不存在,关闭keepalived。VIP切换,注意目前Atlas主,从之间端口不一致。
主从端口最好一致,端口不一致,jdbc failover控制,不知道会不会出问题.
发生vip切换,需要查找原因,keepalived关闭后,需要手动启动,启动后不会占vip。
连接池暂不考虑haproxy,如果性能出问题,最先在数据库,而不是中间件
标签:live col mysq code ipaddr family done 配置 backup
原文地址:https://www.cnblogs.com/52shaidan/p/10271113.html