zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Java 如何有效地避免OOM:善于利用软引用和弱引用
    LRU缓存实现(Java)
    Java实现LRU(最近最少使用)缓存
    HashSet,TreeSet和LinkedHashSet的区别
    IIS-详解IIS中URL重写工具的规则条件(Rule conditions)
    IIS-代理
    IIS-新建网站
    IIS-反向代理配置&&插件安装
    IIS-C#项目环境搭建
    IIS-Windows10如何安装
  • 原文地址:https://www.cnblogs.com/han1094/p/6420592.html
Copyright © 2011-2022 走看看