首页 > 其他分享 >使用keepalived绑定虚拟vip实现主备切换

使用keepalived绑定虚拟vip实现主备切换

时间:2023-01-11 17:56:50浏览次数:45  
标签:grep script keepalived vrrp nginx vip 主备 check

! Configuration File for keepalived
global_defs {
    notification_email {
        root@localhost
    }
    notification_email_from root@localhost
    smtp_server 127.0.0.1
    smtp_connect_timeout 30
    router_id localhost001    # 主机名
    #vrrp_skip_check_adv_addr
    #vrrp_garp_interval 0
    #vrrp_gna_interval 0
}

vrrp_sync_group VG_1 {
    group {
        VI_1
    }
}

vrrp_script check_process {
    script /etc/keepalived/script/check_nginx.sh
    interval 5
    fall 2
}

vrrp_instance VI_1 {
    state BACKUP
    interface enp3s0          # 监控网络配置,注意是'enp3s0',使用ifconfig查看
    virtual_router_id 15
    priority 222
    advert_int 1
    track_interface {
        enp3s0                # 监控网络配置,注意是'enp3s0',使用ifconfig查看
    }
    track_script {
        check_process
    }
    authentication {
        auth_type PASS
        auth_pass 105901
    }
    virtual_ipaddress {
        28.105.90.15          # 虚拟vip
    }
    nopreempt
#        notify /etc/keepalived/script/sms_notify.sh
}

 vi /etc/keepalived/script/check_nginx.sh

#!/bin/bash
count=`ps -ef|grep "nginx: master process" | grep -v grep | wc -l`
if [ $count -eq 0 ];then
    service nginx start
    sleep 3
    if [ `ps -ef|grep "nginx: master process" | grep -v grep | wc -l` -eq 0 ];then
        killall keepalived
    fi
fi

 

标签:grep,script,keepalived,vrrp,nginx,vip,主备,check
From: https://www.cnblogs.com/tgttttttttt/p/17044527.html

相关文章

  • Centos7.6部署k8s v1.16.4高可用集群(主备模式)
    原文:https://zhuanlan.zhihu.com/p/465647563一、部署环境主机列表:共有7台服务器,3台controlplane,3台work,1台client。k8s版本:二、高可用架构本文采用kub......
  • keepalived+nginx
    yuminstall-ykeepalived主从都需要check_nginx.shcheck_nginx.sh内容如下:cat>/etc/keepalived/check_nginx.sh<<EOF#!/bin/bashcounter=$(ps-Cnginx--no-heading|......
  • nginx + keepalived 高可用配置
    ip 192.168.153.14主 192.168.153.15备 1、安装nginxyum-yinstallgccpcre-develzlib-developensslopenssl-devel#安装nginxwgethttps://n......
  • mysql+nginx+keepalived的高可用玩法
     AB 做负载均衡, CD做负载均衡,ABCD 四个服务器虚拟一个IPkeepalived强制分流到主中心的AB两台机器当主中心停电后,keepalived分流到备中心CD两台机器可以找我帮忙搞哈......
  • 【跨屏建站网】kpvip模板2023.1.6发布更新
    跨屏建站网kpvip模板2023.1.6发布更新,修复了已知bug,优化了代码,调整了新闻版块,之前的新闻缩略图有图的时候会显示图片,没有图片则显示一张占位图,而调整以后,我们去掉了缩略图......
  • keepalived+nginx二进制安装
    keepalived二进制安装1、下载keepalived安装包:keepalived下载地址:https://www.keepalived.org/download.htmlwgethttp://www.keepalived.org/software/keepalived-2.0......
  • 最完美WIN11_Pro_22H2.22623.1095软件选装纯净版VIP38.4
    【系统简介】=============================================================1.本次更新母盘来UUP_WIN11_Pro_22H2.22623.1095。进一步优化调整。2.不支持更新,更新后精简版......
  • Spring Security认证授权练手小项目 腾讯视频VIP权限管理功能
    腾讯视频VIP权限管理​​1、项目功能视频演示​​​​2、需求与设计​​​​1、需求​​​​2、功能概要​​​​3、接口设计​​​​3、项目源码结构​​​​4、项目源码下......
  • MySQL 高可用性之Keepalived+Mysql(双主热备)
    MySQL高可用性之Keepalived+Mysql(双主热备)环境描述:OS:CentOS6.5_X64MASTER:192.168.0.202BACKUP:192.168.0.203VIP:192.168.0.2041.配置两台MySQL主主同步1.1安装......
  • 客户端指定不同的vip/域名/F5地址来实现按规则请求不同的集群
    假设后端分为了多个集群,比如A集群它处理用户id是求模100等于0的所有用户,并且它连的分库分表的数据也是用户id求模100等于0的所有用户;那么这个A集群的对外地址aaa就可以打......