• keepalived 实现httpd的高可用


    安装keepalived的依赖

    yum install -y openssl ipvsadm.x86_64 popt* libnl*

    yum install openssl* -y

    yum -y install libnfnetlink.x86_64 libnfnetlink-devel.x86_64

    官网下载keepalived 解压安装

    tar zxvf keepalived-1.3.4.tar.gz

    ./configure 

    make && make install

     cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/

    cp /usr/local/sbin/keepalived /usr/sbin/

    vi /etc/keepalived/keepalived.conf

    global_defs {
    router_id haweb_1
    }
    vrrp_sync_group VGM {
    group {
    VI_HA
    }
    }

    vrrp_instance VI_HA {
    state MASTER #slave
    interface eth0
    lvs_sync_daemon_inteface eth0
    virtual_router_id 145
    priority 100 #90
    advert_int 5
    authentication {
    auth_type PASS
    auth_pass zhangbin
    }
    virtual_ipaddress {
    192.168.1.145/24 dev eth0
    }
    }

    在master和slave都同时配置以上步骤。。只是配置文件稍有不同

    测试在master死机后slave会马上衔接145继续工作。。

    如果不是keepalived死掉而是httpd死掉则需要把陪文写为

    vi /etc/keepalived/keepalived.conf

    global_defs {
    router_id haweb_1
    }
    vrrp_sync_group VGM {
    group {
    VI_HA
    }
    }
    vrrp_script chk_http_port {
    script "/etc/keepalived/httpd.sh"
    interval 1

    weight 1
    }

    vrrp_instance VI_HA {
    state MASTER
    interface eth0
    lvs_sync_daemon_inteface eth0
    virtual_router_id 51
    priority 100
    advert_int 5
    authentication {
    auth_type PASS
    auth_pass zhangbin
    }
    virtual_ipaddress {
    192.168.1.145/24 dev eth0
    }
    track_script {
    chk_http_port
    }
    }

     vi httpd.sh 

    #!/bin/bash
    counter=$(ps -C httpd --no-heading|wc -l)
    if [ "${counter}"="0" ]; then
    /usr/sbin/httpd
    sleep 2
    counter=$(ps -C httpd --no-heading|wc -l)
    if [ "${counter}"="0" ]; then
    /usr/bin/systemctl stop keepalived.service
    fi
    fi

  • 相关阅读:
    SQL SERVER 2008远程数据库移植到本地的方法
    TensorFlow 辨异 —— tf.placeholder 与 tf.Variable
    pycharm pip安装包
    TensorFlow深度学习,一篇文章就够了
    tf.reducemean()到底是什么意思?
    什么是Tensor
    IOS开发之自定义UITabBarController
    IOS中的网络编程详解
    高德地图JS-API (超简单Get新技能√)
    Ios开发之Category
  • 原文地址:https://www.cnblogs.com/han1094/p/6420592.html
Copyright © 2020-2023  润新知