zoukankan      html  css  js  c++  java
  • lvs+keepalived+nginx (httpd)部署

    1:

      192.168.22.109      lvs1

      192.168.22.110      lvs2

      192.168.22.240      VIP

    4:lvs的三种模式图

      lvs-net  http://www.linuxvirtualserver.org/VS-NAT.html

      

      LVS-TUN http://www.linuxvirtualserver.org/VS-IPTunneling.html

      

      LVS-DR http://www.linuxvirtualserver.org/VS-DRouting.html

      

      lvs的三种模式比较参考:http://www.uml.org.cn/zjjs/201211124.asp,此文章说的很详细

    注:LVS部署方式:http://www.cnblogs.com/liangsky/p/4585747.html

    5)安装keepalived(两台)

      wget http://www.keepalived.org/software/keepalived-1.2.17.tar.gz

      ./configure 

      make && make install

      cp /root/keepalived-1.2.17/keepalived/etc/init.d/keepalived.rh.init /etc/init.d/keepalived

      cp /root/keepalived-1.2.17/keepalived/etc/init.d/keepalived.sysconfig /etc/sysconfig/keepalived

      mkdir /etc/keepalived/

      cp /root/keepalived-1.2.17/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

      cp /usr/local/sbin/keepalived /usr/sbin/

     

       

      [root@master init.d]# service keepalived start

      Starting Keepalived for LVS: [确定]


    6)配置keepalived

      先master

      

    global_defs {
    notification_email {
    11@163.net    
    71@qq.com              #需要发送的告警的邮箱地址
    }
    notification_email_from yw_xunjian@test.com  #从哪个邮箱发送过来
    smtp_server mail.test.com  #发送邮箱服务端地址
    smtp_connect_timeout 30
    router_id LVS_master
    }

    vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    virtual_ipaddress {
    #192.168.200.16
    #192.168.200.17
    192.168.22.240
    }
    }


    virtual_server 192.168.22.240 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    #sorry_server 192.168.200.200 1358

    real_server 192.168.22.109 80 {
    weight 1

    TCP_CHECK{
    connect_timeout 3
    nb_get_retry 3
    delay_before_retry 3

    connect_port 80
    }

    }

    real_server 192.168.22.110 80 {
    weight 1

    TCP_CHECK{
    connect_timeout 3
    nb_get_retry 3
    delay_before_retry 3

     connect_port 80

    }

    }

    备机配置:

    global_defs {
    notification_email {
    zhaoliang@zdsoft.net
    79790562@qq.com
    }
    notification_email_from ywb_xunjian@winupon.com
    smtp_server mail.winupon.com
    smtp_connect_timeout 30
    router_id LVS_master
    }

    vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    virtual_ipaddress {
    #192.168.200.16
    #192.168.200.17
    192.168.22.240
    }
    }


    virtual_server 192.168.22.240 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    #sorry_server 192.168.200.200 1358

    real_server 192.168.22.109 80 {
    weight 1

    TCP_CHECK{
    connect_timeout 3
    nb_get_retry 3
    delay_before_retry 3

    connect_port 80
    }

    }

    real_server 192.168.22.110 80 {
    weight 1

    TCP_CHECK{
    connect_timeout 3
    nb_get_retry 3
    delay_before_retry 3

     connect_port 80

    }

    }

    在两机上执行service keepalived start

    查看IP地址:ip a

    可以看到VIP地址在主机上

    在主机上执行service keepalived stop

    可以看到VIP已经到了备机   

    # PS:这里说的LVS.并不是用ipvsadm软件配置.而是直接用keepalived的virtual_server配置项控制的.
    #  安装ipvsadm只是可以看到负载状况.其实只需要keepalived也可以实现负载均衡集群.

    yum -y install httpd 

    主机上执行ipvsadm

    [root@master html]# service ipvsadm status
    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
    -> RemoteAddress:Port Forward Weight ActiveConn InActConn
    TCP 192.168.22.240:80 rr persistent 50
    -> 192.168.22.109:80 Local 1 0 0
    -> 192.168.22.110:80 Route 1 0 0

    备机上执行

    [root@slave ~]# ipvsadm
    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
    -> RemoteAddress:Port Forward Weight ActiveConn InActConn

     sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g' /etc/sysctl.conf

  • 相关阅读:
    又过了一周
    本周学习情况
    5.12
    一周回顾
    npm修改全局包安装路径
    热力图之heatmap
    前端的发展历程
    idea打开maven项目没有别识别是maven项目
    nginx下部署vue项目
    WEB前端开发NodeJS
  • 原文地址:https://www.cnblogs.com/liangsky/p/4566389.html
Copyright © 2011-2022 走看看