zoukankan      html  css  js  c++  java
  • keepalived部署+nginx高可用

    nginx+keepalived搞性能web网络架构实战配置:
    环境准备:
    keepalived+nginx-1:     192.168.1.23
    keepalived+nginx-2:     192.168.1.25

    keepalived环境部署:(需要关闭防火墙与selinux)

    yum方式部署:
    yum install keepalived* -y
    #配置文件:
        /etc/keepalived/keepalived.conf

    源码方式部署:

    #下载版本keepalived-1.4.5版本/安装配置:
    wget https://www.keepalived.org/software/keepalived-1.4.5.tar.gz
    tar xf keepalived-1.4.5.tar.gz
    cd keepalived-1.4.5
    ./configure --prefix=/usr/local/keepalived/
    make 
    make install
    
     mkdir /etc/keepalived/
    cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
    cp /usr/local/keepalived/etc/sysconfig/keepalived  /etc/sysconfig/
    cp keepalived-1.4.5/keepalived/keepalived.service /etc/systemd/system/
    ln -s /usr/local/keepalived/sbin/keepalived  /usr/sbin/
    cp keepalived-1.4.5/keepalived/etc/init.d/keepalived /etc/init.d/
    chmod 755 /etc/init.d/keepalived 
    systemctl enable keepalived
    systemctl start keepalived
    ps -ef|gre keepalived

    keepalived结合nginx实现高可用:(nginx安装步骤省略)两台keepalived+nginx服务的keepalived配置文件/nginx进程脚本 差不多一样:需要注意的是空格不能多写 nopreempt不抢占参数 只对BACKUP生效,对MASTER无效。
    keepalived配置文件内容如下:

    ! Configuration File for keepalived
    global_defs {
      notification_email {
          support@jfedu.net
     }
        notification_email_from wgkgood@163.com
        smtp_server 127.0.0.1
        smtp_connect_timeout 30
    }
    
    vrrp_script chk_nginx {
        script  "/data/sh/auto_check_nginx.vip.sh"
        interval 2
        weight 2
    }
    
    #VIP1
    vrrp_instance VI_1 {
         state  BACKUP
         interface ens33
         virtual_router_id 151
         priority 100
         nopreempt
         advert_int 5
         authentication {
             auth_type  PASS
             auth_pass  1111
    
         }
         virtual_ipaddress {
             192.168.1.198
         }
         track_script {
            chk_nginx
         }
    }

    监控nginx服务进程脚本:
    vim /data/sh/auto_check_nginx.vip.sh

    NGX_MUX="$(ps -ef|grep nginx|grep -v "grep"|grep -v "check"|wc -l)"
    if [ $NGX_MUX -eq 0 ];then
            systemctl stop keepalived
    fi

    配置keepalived主主模式:

    ! Configuration File for keepalived
    global_defs {
      notification_email {
          support@jfedu.net
     }
        notification_email_from wgkgood@163.com
        smtp_server 127.0.0.1
        smtp_connect_timeout 30
    }
    
    vrrp_script chk_nginx {
        script  "/data/sh/auto_check_nginx.vip.sh"
        interval 2
        weight 2
    }
    
    #VIP1
    vrrp_instance VI_1 {
         state  BACKUP
         interface ens33
         virtual_router_id 151
         priority 90
         nopreempt
         advert_int 5
         authentication {
             auth_type  PASS
             auth_pass  1111
    
         }
         virtual_ipaddress {
             192.168.1.198
         }
         track_script {
            chk_nginx
         }
    }
    
    #VIP2
    vrrp_instance VI_2 {
         state  MASTER
         interface ens33
         virtual_router_id 152
         priority 100
         nopreempt
         advert_int 5
         authentication {
             auth_type  PASS
             auth_pass  2222
    
         }
         virtual_ipaddress {
             192.168.1.199
         }
         track_script {
            chk_nginx
         }
    }
  • 相关阅读:
    设计模式之原型模式
    【转载】 吵翻了!这张图里到底是人还是狗?心理学家这样说
    【转载】 DeepMind 提出元梯度强化学习算法,显著提高大规模深度强化学习应用的性能
    ubuntu18.04 安装wine64出现错误: X 64-bit development files not found.
    ubuntu18.04 源码方式安装wine , 警告,libxrender 64-bit development files not found, XRender won't be supported.
    【转载】 信息如何像零食、金钱一样掌控你的大脑
    图像处理算法 之 滤波 模糊(基于OpenCV)
    图像处理之FPN校正
    ISP-黑电平校正(BLC)
    ISP基础(0y):图像传感器
  • 原文地址:https://www.cnblogs.com/fengyuanfei/p/13816329.html
Copyright © 2011-2022 走看看