码迷,mamicode.com
首页 > 其他好文 > 详细

LVS+keepalived

时间:2016-05-16 00:03:21      阅读:480      评论:0      收藏:0      [点我收藏+]

标签:

理论及配置说明:

http://www.cnblogs.com/edisonchou/p/4281978.html

 

lvs:DR模式wrr负载:

拓扑

    KA1    LAMP-1

pc------|

    KA2  LAMP-2

VIP:192.168.14.100

KA1:192.168.14.134

KA1:192.168.14.135

LAMP-1:192.168.141

LAMP-2:192.168.142

 

安装软件:

lvs:

yum install ipvsadm -y
rpm -qa ipvsadm

KA:

yum install keepalived -y

 

lamp:配置

RS绑定VIP:
ip addr add 192.168.14.100/32 dev lo label lo:1
route add -host 192.168.14.100 dev lo
抑制ARP:
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

 

前期准备:

KA的配置文件:主KA

/etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   router_id LVS_19
   vrrp_mcast_group4 224.0.1.18
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 199
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1098
    }
    virtual_ipaddress {
      192.168.14.100/24 dev eth0 label eth0:1
    }
}

#ipvsadm -A -t 192.168.14.100:80 -s rr -p 300
virtual_server 192.168.14.100 80 {
    delay_loop 6              
    lb_algo wrr                
    lb_kind DR                
    nat_mask 255.255.255.0
    persistence_timeout 50     
    protocol TCP
               
#ipvsadm -a -t 192.168.14.100:80 -r 10.0.1.6:80 -g 
    real_server 192.168.14.141 80 {
        weight 1              
        TCP_CHECK {
        connect_timeout 8       
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }

    real_server 192.168.14.142 80 {
        weight 1              
        TCP_CHECK {
        connect_timeout 8       
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
}

备:KA:

! Configuration File for keepalived

global_defs {
   router_id LVS_19
   vrrp_mcast_group4 224.0.1.18
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 199
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1098
    }
    virtual_ipaddress {
      192.168.14.100/24 dev eth0 label eth0:1
    }
}

#ipvsadm -A -t 192.168.14.100:80 -s rr -p 300
virtual_server 192.168.14.100 80 {
    delay_loop 6              
    lb_algo wrr                
    lb_kind DR                
    nat_mask 255.255.255.0
    persistence_timeout 50     
    protocol TCP
               
#ipvsadm -a -t 192.168.14.100:80 -r 10.0.1.6:80 -g 
    real_server 192.168.14.141 80 {
        weight 1              
        TCP_CHECK {
        connect_timeout 8       
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }

    real_server 192.168.14.142 80 {
        weight 1              
        TCP_CHECK {
        connect_timeout 8       
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
}

检查:如果一台down了,另一台通过ifconfig就会出现绑定的VIP了

ip add |egrep  "134|135"

 

理论笔记:

集群--一组服务器
lvs harproxy nginx,keepalive heartbeat
负载均衡 高可用


负载模型:
nginx 7层负载
lvs 4层负载
lvs---nginx---webserver

负载:
1,7*24h服务
2,一台机器扛不住

lvs底层原理底层原理:
ipvs
ipvsadm自带
keepalive

名词介绍:
CIP(Client ip address)
DIP(Director IP address)
VIP(virtual ip address)
RIP(Real Server Ip address)=RS


负载的3种模式:
NAT
DR(direct route)
TUN(ip tunnel)
fullnat

DR
RIP
1,绑定VIP
2,抑制arp回应
主要:
LB通过修改目的mac,因此无法改写端口
2000W pv
请求10000一下都可以用haproxy/nginx

NAT模式:
LB要打开转发:
net.ipv4_forward=1

 

LVS+keepalived

标签:

原文地址:http://www.cnblogs.com/iiiiher/p/5496641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!