• Nginx-自动漂移VIP


    自动漂移VIP-1

    #!/bin/bash
    #2020-03-16 14:24
    #auto change nginx vip.sh
    #By Precious
    ################################
    NGX_PRE="24"
    ETH_ENS="ens33:0"
    NGX_VIP="192.168.1.188"
    ETH_DIR="/etc/sysconfig/network-scripts/"
    while true
    do
    NGX_NUM="$(ps -ef|grep nginx |grep -v grep|grep -v change|wc -l)"
    if [ $NGX_NUM -ne 0 ];then
        ping -c 2 $NGX_VIP
        if [ $? -ne 0 ];then
        cd $ETH_DIR
        cp ifcfg-ens33 ifcfg-$ETH_ENS
    cat >>ifcfg-$ETH_ENS<<EOF
    BOOTPROTO=none
    DEFROUTE=yes
    DEVICE=$ETH_ENS
    IPADDR=$NGX_VIP
    PREFIX=$NGX_PRE
    EOF
        cat ifcfg-$ETH_ENS
        ifup ifcfg-$ETH_ENS
        fi
    else
        ifdown ifcfg-$ETH_ENS
        rm -rf $ETH_DIR/ifcfg-$ETH_ENS
    fi
    sleep 2 
    done

    自动漂移VIP-2

    #!/bin/bash
    #2020年1月7日20:42:50
    #auto change service VIP
    #by author www.jfedu.net
    ########################
    ETH_NAME="ens33:1"
    NGX_VIP="192.168.1.188"
    NGX_MASK="255.255.255.0"
    ETH_DIR="/etc/sysconfig/network-scripts"
    NGX_NUM=`ps -ef|grep nginx|grep -v grep|grep -v check|wc -l`
    
    start(){
    while sleep 4 
    do
    if [ $NGX_NUM -eq 0 ];then
        ifdown $ETH_NAME
        exit 0    
    else
        ping -c 2 $NGX_VIP >/dev/null 2>&1
        if [ $? -ne 0 ];then
    cat>$ETH_DIR/ifcfg-$ETH_NAME<<EOF
    TYPE="Ethernet"
    BOOTPROTO="static"
    DEVICE="$ETH_NAME"
    IPADDR=$NGX_VIP
    NETMASK=$NGX_MASK
    ONBOOT="yes"
    EOF
        ifup $ETH_NAME
        fi
    fi
    date
    done
    }
    
    stop(){
        ifdown $ETH_NAME
        rm -rf $ETH_DIR/ifcfg-$ETH_NAME
    }
    
    case $1 in
        start)
        start
        ;;
        stop)
        stop
        ;;
        *)
        echo -e "33[32m------------------33[0m"
        echo -e "33[32mUsage: /bin/sh $0 {start|stop|help}33[0m"
            exit 1 
    esac
  • 相关阅读:
    selenium中webDriver模块的常用方法
    java web Project Explorer误删解决方法
    java web开发前后端中文配置
    常见Filed Types
    类的展现
    面向对象:类与运算符
    面向对象定义类,属性
    筛选元素
    try : finally语句
    捕获异常try:except
  • 原文地址:https://www.cnblogs.com/fengyuanfei/p/13797680.html
Copyright © 2020-2023  润新知