lvs是一种负载均衡技术.注意区分负载均衡和高可用的区别.
keepalive是lvs的管理工具
ipvsadm也是lvs的管理工具
keepalive借助ipvsadm管理lvs.所以通常说lvs+keepalive
lvs支持多种负载方式.
理论及配置说明:
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:1route add -host 192.168.14.100 dev lo抑制ARP:echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignoreecho "2" >/proc/sys/net/ipv4/conf/lo/arp_announceecho "1" >/proc/sys/net/ipv4/conf/all/arp_ignoreecho "2" >/proc/sys/net/ipv4/conf/all/arp_announce
前期准备:
KA的配置文件:主KA
/etc/keepalived/keepalived.conf
! Configuration File for keepalivedglobal_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 300virtual_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 keepalivedglobal_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 300virtual_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种模式:NATDR(direct route)TUN(ip tunnel)fullnatDR
RIP1,绑定VIP2,抑制arp回应主要:LB通过修改目的mac,因此无法改写端口2000W pv请求10000一下都可以用haproxy/nginxNAT模式:
LB要打开转发:net.ipv4_forward=1