LVS配置--下

tunip脚本配置

[root@localhost ~]# vi /etc/ha.d/resource.d/tunip

#/bin/sh

#/sbin/ifconfig tunl0 192.168.2.253 broadcast 192.168.2.253 netmask 255.255.255.255 up

#

# description: Start DirectorServer of LVS

# chkconfig: - 08 92

#

# Start LVS DR in Directorserver

VIP=192.168.2.253

 

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

 

case "$1" in

start)

echo " Start LVS of DirectorServer"

# set the Virtual IP Address

/sbin/modprobe ipip

/sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up

;;

stop)

echo "Close LVS Directorserver"

/sbin/modprobe -r ipip

/sbin/ifconfig tunl0 down

;;

*)

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

exit 1

esac

 

slave机器配置

把主调度器121上的配置文件及脚本拷贝至从127机器上,并开放694端口

更改ha.cf配置文件

ucast eth0 192.168.2.127 #eth0IP,此处从为从的IP

auto_failback off

 

 

 

四、ldirectordVIP结合至heartbeat

[root@LVS-master ~]# vi /etc/ha.d/haresources

LVS-master \

        ldirectord::ldirectord.cf \

        tunip

 

开启关闭LVS

[root@LVS-master ~]# service heartbeat start

 

[root@LVS-master ~]# service heartbeat stop 

 

 

五、Windows realserver配置

此连接需要使用DR连接方式win2000只支持loop win2003支持looptun

win2K配置环回地址

1)添加硬件

控制面板->添加/删除硬件->添加/排除设备故障->添加新设备->否,我想从列表选择硬件->网卡->左边|microsoft右边|microsoft loopback adapter

2)环回网卡配置IP

192.168.2.253

255.255.255.0

3)修改环回地址子网掩码

找到注册表下面键值

LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces

修改右边subnetmask255.255.255.255

4)重启网卡

修改好后

重新启动环回网卡即可(如未重启连接会有问题)

 

 

 

六、LVS fwm功能即LVS结合iptables做转发

 

1调度器上配置

打开转发功能

echo "1" > /proc/sys/net/ipv4/ip_forward     

开启防火墙,把80008080开启转发设置mark组为2 

iptables -t mangle -A PREROUTING -p tcp  -d 192.168.2.253/32 --dport 8000 -j MARK --set-mark 2

iptables -t mangle -A PREROUTING -p tcp  -d 192.168.2.253/32 --dport 8001 -j MARK --set-mark 2

iptables -t mangle -A PREROUTING -p tcp  -d 192.168.2.253/32 --dport 8003 -j MARK --set-mark 2

iptables -t mangle -A PREROUTING -p tcp  -d 192.168.2.253/32 --dport 8080 -j MARK --set-mark 2

 

查看上述规则是否加入到mangle表的PREROUTING

iptables -t mangle -L PREROUTING        

 

2LVS配置

LVS添加设置为DR模式,可能是因为调度器为linux,realserverwin使用NAT方式用不了

ipvsadm -A -f 2 -s wlc

ipvsadm -a -f 2 -r 192.168.2.26 -g -w 1

ipvsadm -a -f 2 -r 192.168.2.43 -g -w 1

 

移除相关配置

ipvsadm -D -f 2

ipvsadm -d -f 2 -r 192.168.2.43

 

3realserver配置 

realserver配置见上-->Windows   realserver配置此连接需要使用DR连接方式

 

4ldirectord的最终配置

 

[root@LVS-master ~]# vi /etc/ha.d/ldirectord.cf

#SH_level2

virtual=192.168.2.253:8601

#       real=192.168.2.120:8601 gate

        real=192.168.2.125:8601 gate

        real=192.168.2.126:8601 gate

        real=192.168.2.27:8601 gate

        real=192.168.2.77:8601 gate

        scheduler=wlc

        checktype=connect

        protocol=tcp

        checkport=8601

#SHZ_level2

virtual=192.168.2.252:8601

        real=192.168.2.74:8601 ipip

        real=192.168.2.75:8601 ipip

        scheduler=wlc

        checktype=connect

        protocol=tcp

        checkport=8601

 

#wt-gateway

virtual=2

        real=192.168.2.26 gate 3

        real=192.168.2.28 gate 3

        real=192.168.2.29 gate 3

        real=192.168.2.42 gate

        real=192.168.2.43 gate 3

        scheduler=wlc

        protocol=fwm

 

权重越大连接越多

启动后结果如下

[root@LVS-master ~]# ipvsadm

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  192.168.2.252:8601 wlc

  -> 192.168.2.74:8601            Tunnel  1      1515       0        

  -> 192.168.2.75:8601            Tunnel  1      1515       0        

TCP  192.168.2.253:8601 wlc

  -> 192.168.2.77:8601            Route   1      2949       0        

  -> 192.168.2.126:8601           Route   1      2949       0        

  -> 192.168.2.27:8601            Route   1      2949       0        

  -> 192.168.2.125:8601           Route   1      2949       0        

FWM  2 wlc

  -> 192.168.2.43:0               Route   1      1          0        

  -> 192.168.2.42:0               Route   3      1          0        

  -> 192.168.2.29:0               Route   1      1          0        

  -> 192.168.2.26:0               Route   1      1          0        

  -> 192.168.2.28:0               Route   1      1          0  

 

七、其它

 #UltraMonkey-L7是用于7层转发的,由于公司产品是使用socket实现的即使用的是传输层协议(TCPUDP)用不不到UltraMonkey-L7

 

http://sourceforge.jp/projects/ultramonkey-l7/downloads/47898/ultramonkey-l7-2.1.3-1.tar.gz/

卸载ipip模块:

[root@LVS-master ~]# rmmod ipip

modprobe -r ipip

算法

•轮叫调度(Round-Robin Scheduling

•加权轮叫调度(Weighted Round-Robin Scheduling

•最小连接调度(Least-Connection Scheduling

•加权最小连接调度(Weighted Least-Connection Scheduling

•基于局部性的最少链接(Locality-Based Least Connections Scheduling

•带复制的基于局部性最少链接(Locality-Based Least Connections with Replication Scheduling

•目标地址散列调度(Destination Hashing Scheduling

•源地址散列调度(Source Hashing Scheduling

•最短预期延时调度(Shortest Expected Delay Scheduling

•不排队调度(Never Queue Scheduling

模式比较  

特性模式 VS-NAT VS-TUN VS-DR

服务器操作系统 任何操作系统 须支持隧道技术 大多数系统

服务器模式  隧道、 ARP Lo ARP

端口映射   

服务器网络 私有网 LAN/WAN LAN

服务器数量 (10-20) 多(100 (100)

用户访问IP LVS虚拟IP LVS虚拟IP LVS虚拟IP

服务器网关 负载均衡器 原有的路由器 原有的路由器

 

源文档 <http://www.mailer.cn/Solution/ny37a.htm>

 

查看超时时间设置,下面是默认值

#ipvsadm -L --timeout

900 120 300

单位秒

#ipvsadm -L --timeout

900 120 300

单位秒

调整TCPUDP的超时

ipvsadm --set tcp tcpfin udp

查看实时连接

Ipvsadm -lnc

 

NAT 方式设置realserver时,只需要把default gateway设置为调度器的VIP地址即可

ipip如上配置去掉realserverarp响应

DR设置realserverlo:0配置为VIP地址去掉realserverarp响应

 

 

modprobe -r ipip

modprobe ipip

#ifconfig tunl0 192.168.2.253 netmask 255.255.255.255 broadcast 192.168.2.253 up

ifconfig lo:0 192.168.2.253 netmask 255.255.255.255 broadcast 192.168.2.253 up

route add -host 192.168.2.253 dev lo:0

#echo "1" > /proc/sys/net/ipv4/conf/tunl0/arp_ignore

#echo "2" > /proc/sys/net/ipv4/conf/tunl0/arp_announce

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

 

 

 

 

Heatbeat重启导致机器重启问题

由于/etc/ha.d/ha.cf开启了watchdog功能

#If our own heart doesn't beat for  a minute, then our machine will reboot.

watchdog /dev/watchdog

 

 

参考文章

http://wenku.baidu.com/view/859c4960ddccda38376bafc5.html

http://support.microsoft.com/kb/839013

http://blog.chinaunix.net/u3/93425/showart_1864588.html

http://zh.linuxvirtualserver.org/node/94

http://www.cnblogs.com/eugenewu0808/archive/2010/08/20/1804624.html

http://www.ibm.com/developerworks/search/searchResults.jsp?searchType=1&searchSite=dWChina&pageLang=zh&langEncoding=UTF8&searchScope=dW&query=lvs

http://linux-ha.org/wiki/Heartbeat

http://www.austintek.com/LVS/LVS-HOWTO/HOWTO/LVS-HOWTO.install.html

http://itboba.com/taxonomy/term/279

http://www.91linux.com/html/article/network/20081102/13726.html

 



本文转自 qwjhq 51CTO博客,原文链接:http://blog.51cto.com/bingdian/410535

上一篇:图像处理之距离变换


下一篇:Spring Boot 2.3.0正式发布:优雅停机、配置文件位置通配符新特性一览