• keepalived部署


    1.环境准备

    主机名 IP地址 CPU 内存 硬盘
    gztxy-prd-nginx01 192.168.1.11 2 2 100G
    gztxy-prd-nginx02 192.168.1.12 2 2 100G

    2.安装并配置

    安装:

    yum install keepalived -y
    

    主配置文件keepalived.conf:

    global_defs {
       router_id LVS_DEVEL
    }
    
    vrrp_script chk_nginx {
    script "/etc/keepalived/chk_nginx.sh" ## 检测 nginx 状态的脚本路径
    interval 2 ## 检测时间间隔
    weight -20 ## 如果条件成立,权重-20
    }
    vrrp_instance VI_1 {
       state MASTER
       interface ens192
       virtual_router_id 66
       priority 100 ## 节点优先级, 值范围 0-254, MASTER 要比 BACKUP 高
       nopreempt ## 优先级高的设置 nopreempt 解决异常恢复后再次抢占的问题
       advert_int 1 ## 组播信息发送间隔,两个节点设置必须一样, 默认 1s
    ## 设置验证信息,两个节点必须一致
    authentication {
       auth_type PASS
       auth_pass 66666 ## 真实生产,按需求对应该过来
    }
    ## 将 track_script 块加入 instance 配置块
    track_script {
       chk_nginx ## 执行 Nginx 监控的服务
    } #
    # 虚拟 IP 池, 两个节点设置必须一样
    virtual_ipaddress {
       192.168.1.3 ## 虚拟 ip,可以定义多个
    }
    }
    

    备配置文件keepalived.conf:

    global_defs {
      router_id LVS_DEVEL
    }
    vrrp_script chk_nginx {
      script "/etc/keepalived/chk_nginx.sh"
      interval 2
      weight -20
    }
    vrrp_instance VI_1 {
      state BACKUP
      interface ens192
      virtual_router_id 66
      priority 90
      advert_int 1
      authentication {
      auth_type PASS
      auth_pass 66666
    }
    track_script {
      chk_nginx
    }
    virtual_ipaddress {
      192.168.1.3
    }
    }
    

    检测脚本chk_nginx.sh:

    #!/bin/bash
    A=`ps -C nginx --no-header |wc -l`
    if [ $A -eq 0 ];then
            systemctl start nginx
            sleep 2
            if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
                    systemctl stop keepalived.service
            fi
    fi
    

      

  • 相关阅读:
    sysstat_iostat
    MSM_linux_x64_installer15.11.0013
    Error detected while processing /root/.vimrc: E492: Not an editor command: Plug 'scrooloose/nerdtree'
    ERROR 2006 (HY000): MySQL server has gone away
    内网时间服务器chrony
    lsof在脚本中无法被识别
    virbr0默认地址192.168.122.1冲突
    01 springcloud 版本的说明和各版本依赖如何引入工程
    关于vmodel绑定未定义的对象属性的几个细节验证
    DM8备份与还原实操
  • 原文地址:https://www.cnblogs.com/luchuangao/p/13645485.html
Copyright © 2020-2023  润新知