fdfe 发表于 2015-9-4 08:59:26

lvs+keepalived+nginx (httpd)部署

  1:
  192.168.22.109      lvs1
  192.168.22.110      lvs2
  192.168.22.240      VIP
  
  
  
  4:lvs的三种模式图
  lvs-nethttp://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/
  
  
  # 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
  
  # service ipvsadm status
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port         Forward Weight ActiveConn InActConn
TCP192.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   
  
  备机上执行
  # 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
页: [1]
查看完整版本: lvs+keepalived+nginx (httpd)部署