• KeepAlived+Nginx 安装


    yum install -y gcc gcc-c++ openssl openssl-devel

    目前keepalived最新版本下载:
    [root@rhel ~]#wget -c http://www.keepalived.org/software/keepalived-1.2.12.tar.gz
    [root@rhel ~]# tar zxvf keepalived-1.2.12.tar.gz
    [root@rhel ~]# cd keepalived-1.2.12
    安装编译环境:
    [root@rhel ~]# yum install -y gcc gcc-c++ openssl openssl-devel
    1

    //指定安装路径
    [root@rhel keepalived-1.2.12]# ./configure --prefix=/usr/local/keepalived --sysconf=/etc 

    [root@rhel keepalived-1.2.12]# make && make install //安装
    将keepalived命令软连接到/usr/bin下
    [root@rhel keepalived-1.2.12]# ln -s /usr/local/keepalived/sbin/keepalived /usr/bin/keepalived

    添加启动脚本且方便用service keepalived start/stop/restart管理(如果没有init.d/keepalived则从源码目录拷贝)
    [root@rhel keepalived-1.2.12]# cp /keepalived/keepalived-2.0.8/keepalived/etc/init.d/keepalived /etc/init.d/keepalived
    [root@rhel keepalived-1.2.12]# chmod 755 /etc/init.d/keepalived //添加执行权限
    [root@rhel keepalived-1.2.12]# chkconfig keepalived on //开机启动

    修改/etc/init.d/keepalived中的程序路径
    # Source configuration file (we set KEEPALIVED_OPTIONS there)
    . /etc/sysconfig/keepalived

    改为:
    # Source configuration file (we set KEEPALIVED_OPTIONS there)
    . /keepalived/keepalived-2.0.8/keepalived/etc/sysconfig/keepalived

    默认情况下,keepalived 会读取 /etc/keepalived 下keepalived.conf 文件
    如果没有建立这个文件,keepalived也不会报错,但是会发现,所创建的关于keepalived的相关参数根本就没有生效。
    [root@rhel keepalived-1.2.12]# mkdir /etc/keepalived
    [root@rhel keepalived-1.2.12]# ln -s /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf

    keepalived.conf

    ! Configuration File for keepalived

    global_defs {
    notification_email {
    root@localhost
    }
    notification_email_from keepalived@localhost
    smtp_server 127.0.0.1
    smtp_connect_timeout 30
    router_id LVS_DEVEL
    }

    vrrp_script Monitor_Nginx {
    script "/monitor_nginx.sh"
    interval 2
    weight 2
    }

    vrrp_instance VI_1 {
    state MASTER
    interface ens192
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 123456
    }

    track_script {
    Monitor_Nginx #(调用nginx进程检测脚本)
    }

    virtual_ipaddress {
    172.16.9.30
    }

    }

    monitor_nginx.sh

    #!/bin/bash
    if [ "$(ps -ef | grep "nginx: master process"| grep -v grep )" == "" ]
    then
    killall keepalived
    fi
     
    chmod 777 /monitor_nginx.sh
    sed -i 's/ $//' /monitor_nginx.sh

    启动测试:
    [root@rhel keepalived-1.2.12]# service keepalived restart
    停止 keepalived: [确定]
    启动 keepalived: [确定]

    安装完成

    service keepalived restart
    service keepalived stop
    service keepalived start

    systemctl start keepalived
    systemctl restart keepalived
    systemctl stop keepalived

  • 相关阅读:
    Ubuntu下官方QQ崩溃的解决
    [转]PHP函数的实现原理及性能分析
    [收藏的资料]301重定向的实现方法
    手动配置Ubuntu 指定DNS服务器地址
    C# FTP操作类
    vs2010 快捷键大全
    分享一个不错的VS插件——CodeMap
    C# 快速的批量修改重命名.net程序的命名空间(一)转 tianyaxiang
    jquery 的 ajax 程序 简单的
    winform窗体间传值
  • 原文地址:https://www.cnblogs.com/littlewrong/p/9977532.html
Copyright © 2020-2023  润新知