• Linux下搭建keepalive+nginx


    一、 安装nginx(略)

    二、 安装keepalive

    1. 下载http://www.keepalived.org/download.html
    2. 安装依赖包 yum install –y popt* gcc* openssl* nmap
    3. tar fvxz keepalived-1.2.15.tar.gz
    4. cd keepalived-1.2.15
    5. ./configure –prefix=/usr/local/keepalived
    6. make && make installmkdir /etc/keepalived  ##为keepalived创建配置文件目录,默认配置文件从/etc/keepalived下读取
    7. cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ ##复制keepalived的二进制命令  
    8. cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/  ##提供启动脚本
    9. cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ ##keepalived的主
    10. cp /usr/local/keepalived/ety/sysconfig/keepalived /usr/sysconfig/

    三、 配置keepalive

    1.  打开配置文件vim /etc/keepalived/keepalived.conf

    ! Configuration File for keepalived

    global_defs {

       notification_email {

         liumingtao@zhanghetianxia.com

         lmt122900@sina.com

       }

       notification_email_from pub@easymobi.cn

       smtp_server 127.0.0.1

       smtp_connect_timeout 30

       router_id LVS_DEVEL

    }

    vrrp_script chk_http_port {

        script "/opt/nginx.sh"  #检测nginx是否存活脚本位置(下面会有定义脚本名)

        interval 2

        weight 2

    }

    vrrp_instance VI_1 {

        state MASTER # 主   (备用 BACKUP)

        interface eth0       #本机ip网卡名称

        virtual_router_id 10  # 每组keepalive routeid相同,不同组不能一样

        mcast_src_ip 192.168.102.79  #本机ip 备机用备机ip

        priority 100  #权重 备机数值要比主的数值小

        advert_int 1  # 检查间隔

        authentication {

            auth_type PASS

            auth_pass 1111222

        }

    track_script {

        chk_http_port  #定义nginx检测脚本名称

    }

        virtual_ipaddress {

            192.168.102.89  #虚拟ip

        }

    }

    启动主备的keepalived验证

    nginx.sh 脚本 备机可以不用定义脚本相关选项

    #!/bin/sh

    # check nginx server status

    NGINX=/usr/local/nginx/sbin/nginx

    PORT=80

    nmap localhost -p $PORT | grep "$PORT/tcp open"

    #echo $?

    if [ $? -ne 0 ];then

        $NGINX -s stop

        $NGINX

        sleep 3

        nmap localhost -p $PORT | grep "$PORT/tcp open"

        [ $? -ne 0 ] && /etc/init.d/keepalived stop

    fi

    把脚本加上执行权限后放到/opt/目录下

  • 相关阅读:
    Ubuntu 18.04.2 LTS美化方案
    Ubuntu 16.04升级18.04
    Spark性能优化指南——高级篇
    Spark性能优化指南——基础篇
    遗传算法(Genetic Algorithm)——基于Java实现
    Linux sar命令参数详解
    Gdb调试多进程程序
    P8.打印整数
    Algorithm Book Index
    Debugging with GDB (8) 4.10 Debugging Programs with Multiple Threads
  • 原文地址:https://www.cnblogs.com/liumt-blog/p/11792205.html
Copyright © 2020-2023  润新知