LVS-DR模式,

如果查看realserver服务器上的服务开放的端口netstat -tnlp是192.168.1.4:38381这种方式,则表示这台机器的38381端口只接受192.168.1.4 :38381 这样的一种连接方式

此时LVS前端在接受请求通过算法转发给后端realserver的时候,此时IP包的目的地址为依旧为VIP的地址,再加上请求的端口,则为(2.2.2.2:38381)这样一种形式,而此时如果realserver的端口开放不是0.0.0.0:38381而是本地IP192.168.1.1:38381,此时肯定就连不通了,

解决方法:

把服务的端口开放形式设置为0.0.0.0:38381 表示监听本机所有IP的38381端口


realserver 的VIP要配置在lo回环接口上,不能配置在其它比如eth0上,否则会响应从客户端发过来的请求

更改realserver arp_announce 和arp_ingore是为了防止从directer 转发过来apr请求被其它的realserver响应,因为其它realserver上也配有VIP!

安装keepalived时,编译时指定--sysconfigdir=/etc/,安装过程中则会自动拷贝keepalived到/etc/init.d/,以及/etc/sysconfig/keepalived,另外自动创建/etc/keepalived/keepalived.conf等等!省去这些手动操作麻烦!

./configure --prefix=/usr/local/keepalived-1.2.12 --sysconfdir=/etc




ipvsadm 命令

-l/L --list显示内核虚拟服务器列表

-n --numeric 输出IP 地址和端口的数字形式

-c --connection 显示LVS目前的连接

LVS-DR realserver中需修改的ARP内核参数,在RealServers上,VIP配置在本地回环接口lo上

net.ipv4.conf.all.arp_announce = 2

net.ipv4.conf.lo.arp_announce = 2

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.lo.arp_ignore = 1


realserver端配置脚本,各realserver相同

#!/bin/bash

#program:

#       the script is used to start or stop realserver of lvs

#history:

#2014/2/22

VIP=192.168.40.179

. /etc/rc.d/init.d/functions


case "$1" in

start)

echo " start lvs of realserver"

/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up

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/lo/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce

;;

stop)

/sbin/ifconfig lo:0 down

echo "stop lvs of realserver"

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce

;;

*)

echo "usage:$0 {start|stop}"

exit 1

esac