Created
September 24, 2015 08:00
-
-
Save edisonlz/29e2cbc7d40799a70138 to your computer and use it in GitHub Desktop.
LVS配置
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
一、基本介绍 | |
LVS是工作在内核内间的TCP/IP协议栈上,且监控在INPUT链上,所以一般情况下LVS 和iptables 最好不要同时使用. | |
Keepalived是一个基于ARRP协议来实现高可用的服务,keepalived能够自己调用ipvsadm命令生成规则,能够自动实现,将主节点的VIP以及ipvs规则“拿过来”,应用在从节点上,继续为用户服务。还可以实现对后端realserver的健康状况做检测。 | |
LVS三种工作模式(NAT、DR、TUN), 通常用的最多的是DR模式 | |
DR模式下,LVS服务器必需有个网卡和realserver在同个物理网段上,目的是为了学习真实服务器的MAC地址,用于做转发.且Realserver必需将VIP绑定在机器的回环上,通常LVS机器上有很多个IP,都是用来做接口地址. | |
二、 ipvsadm keepalived的配置与安装 | |
2.1、安装 | |
rpm -ivh http://10.100.28.128/download/ipvsadm-1.25-10.el6.x86_64.rpm | |
keepalived实现高可用 | |
rpm -ivh http://10.100.28.128/download/keepalived-1.2.7-3.el6.x86_64.rpm | |
2.2、ipvsadm是操作lvs的命令行工具 | |
基本命令 | |
ipvsadm -L --timeout Timeout(tcp tcpfin udp):30560 //查看超时时间1、tcp session时间 2、连接断开后保持时间 3、udp超时时间 | |
ipvsadm -L -n //查看 | |
ipvsadm -C //清空 | |
ipvsadm -L -n -t 10.103.55.20:3306 // 查看某一个VIP的链接数(注:一定要加端口) | |
ipvsadm -L -n -t 10.103.55.20:3306--stats //查看某一个VIP连接数与流量 | |
ipvsadm -L -n -t 10.103.55.20:3305--stats --exact //查看某一个VIP的连接数(--exact参数作用是显示更为精准) | |
例2:DR方式 | |
LVS机器配置: | |
echo "1">/proc/sys/net/ipv4/ip_forward // 打开转发, | |
VIP=10.103.55.20 PORT=3306 RS1=10.103.7.115 RS2=10.103.7.116 | |
ipvsadm --set30560 ipvsadm -A -t $VIP:$PORT -s rr // 添加VIP 10.103.55.20 并使用轮循算法 | |
ipvsadm -a -t $VIP:$PORT -r $RS1:$PORT -g -w 100// 添加Realserver -g 表示DR模式 -w 权重 | |
ipvsadm -a -t $VIP:$PORT -r $RS2:$PORT -g -w 100 | |
2.3、RealServer配置: | |
/sbin/ifconfig lo:2010.103.55.20 broadcast 10.103.55.20 netmask 0xffffffff up /sbin/route add -host 10.103.55.20 dev lo:20 | |
keepalived配置文件详解 | |
!ConfigurationFilefor keepalived | |
global_defs { notification_email { [email protected] #rs有问题时,发送邮件} | |
notification_email_from [email protected] #邮箱服务器 | |
smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS1_ZHAOWEI #LVS名称} | |
include /etc/keepalived/conf/*.conf #包含所有以.conf结尾的文件 | |
------------------fddb_10.103.55.20_101_master.conf------------------------- 命名规则:服务名称+VIP+VRID+主/从.conf | |
vrrp_instance fd_db_1 { | |
state MASTER #MASTER 为热备中的主服务器interface bond0.55#VIP工作的网卡 | |
virtual_router_id 101#VRID 不可重复,1-255 | |
priority 100#权重,要比BACKUP小 | |
advert_int 1#检测时间 | |
authentication {#认证方式及认证密码 | |
auth_type PASS | |
auth_pass fd_db_1 | |
} | |
virtual_ipaddress {#VIP10.103.55.20} | |
track_interface {#当eth0 down掉时,权重减50 | |
eth0 weight -50}} | |
virtual_server 10.103.55.203306{#VIP+ $PORT | |
delay_loop 3#检测realserver间隔时间(秒) | |
lb_algo rr #使用的算法(轮循) | |
lb_kind DR #工作模式(DR)# persistence_timeout 50 #保持链接(同一时间内落到同一个realserver上面) | |
protocol TCP #使用协议 | |
real_server 10.103.7.1153306{ | |
weight 100#权重 | |
TCP_CHECK {#检测方式TCP/HTTP | |
connect_timeout 10#连接超时时间 | |
nb_get_retry 3#失败次数 | |
delay_before_retry 3#重试连接次数 | |
connect_port 3306#检测端口}} | |
real_server 10.103.7.1163306{ | |
weight 100 | |
TCP_CHECK { | |
connect_timeout 10 | |
nb_get_retry 3 | |
delay_before_retry 3 | |
connect_port 3306}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
当客户端发起访问VIP 对应的域名的请求时,根据网络通信原理会产生ARP 广播,因为负载均衡器和真实的服务器在同一网络并且VIP设置在集群中的每个节点上,此时集群内的真实服务器会尝试回答来自客户端计算机的查找VIP的ARP广播,这就会产生问题,大家都说我是"VIP"。
方法一:在真实服务器上设置lo 忽略ARP 广播
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2