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

  • 相关阅读:
    156. Binary Tree Upside Down
    155. Min Stack
    154. Find Minimum in Rotated Sorted Array II
    153. Find Minimum in Rotated Sorted Array
    汉诺塔问题
    算法——二分搜索
    linux内核编程helloworld(中级)
    linux内核入门(1)——基本简介和编译
    linux网络编程概念(一)
    linux配置防火墙
  • 原文地址:https://www.cnblogs.com/han1094/p/6420592.html
Copyright © 2011-2022 走看看