把这个搞定之后,直接在ipvsadm源码目录里make即可。(没测试)
3、集群配置
在实施环境中,肯定要用脚本来跑,快准狠。 (1)NAT配置脚本
LB配置:
#!/bin/sh
#------mini-HOWTO-setup-LVS-NAT-director----------
#set ip_forwardON for vs-nat director (1 on, 0 off).
cat /proc/sys/net/ipv4/ip_forward
echo "1" >/proc/sys/net/ipv4/ip_forward
echo "0" >/proc/sys/net/ipv4/conf/all/send_redirects
cat /proc/sys/net/ipv4/conf/all/send_redirects
echo "0" >/proc/sys/net/ipv4/conf/default/send_redirects
cat /proc/sys/net/ipv4/conf/default/send_redirects
echo "0" >/proc/sys/net/ipv4/conf/eth0/send_redirects
cat /proc/sys/net/ipv4/conf/eth0/send_redirects
/sbin/sysctl -p &> /dev/null
#setup VIP
/sbin/ifconfig eth0:0 42.202.144.15 netmask 255.255.255.255 up
#clear ipvsadmtables
/sbin/ipvsadm -C
#install LVS services with ipvsadm
#add telnet to VIP with rr sheduling
/sbin/ipvsadm -A -t 192.168.2.110:telnet -s rr
#first realserver
#forward telnet to realserver 42.202.144.11 using LVS-NAT (-m), with weight=1
/sbin/ipvsadm-a -t 42.202.144.15:telnet -r 42.202.144.11:telnet -m -w 1
#check that realserver is reachable from director
ping -c 1 192.168.1.11
#second realserver
#forward telnet to realserver 192.168.1.12 using LVS-NAT (-m), with weight=1
/sbin/ipvsadm -a -t 42.202.144.15:telnet -r 42.202.144.12:telnet -m -w 1
#checking if realserver is reachable from director
ping -c 1 192.168.1.12
/sbin/ipvsadm
(2)DR模式配置脚本
LB配置
#!/bin/bash
#---------------mini-rc.lvs_dr-director------------------------
#set ip_forward OFF forlvs-dr director (1 on, 0 off)
#add ethernet device androuting for VIP 192.168.1.110
/sbin/ifconfig eth0:0 42.202.144.15netmask 255.255.255.255 up
/sbin/route add -host 42.202.144.15dev eth0:0
#setup_ipvsadm_table
#clear ipvsadm table
/sbin/ipvsadm -C
#installing LVS serviceswith ipvsadm
#add telnet to VIP withround robin scheduling
/sbin/ipvsadm -A -t 42.202.144.15:telnet-s rr
#forward telnet torealserver using direct routing with weight 1
/sbin/ipvsadm -a -t 42.202.144.15:telnet-r 42.202.144.11 -g -w 1
#check realserverreachable from director
ping -c 1 42.202.144.11
#forward telnet torealserver using direct routing with weight 1
/sbin/ipvsadm -a -t 42.202.144.15:telnet-r 42.202.144.12 -g -w 1
#check realserverreachable from director
ping -c 1 42.202.144.12
#displaying ipvsadmsettings
/sbin/ipvsadm
(3)TUN模式配置脚本
LB配置
#!/bin/bash
#---------------mini-rc.lvs_dr-director------------------------
#set ip_forward OFF forlvs-dr director (1 on, 0 off)
#add ethernet device androuting for VIP 192.168.1.110
/sbin/ifconfig eth0:0 42.202.144.15netmask 255.255.255.255 up
/sbin/route add -host 42.202.144.15dev eth0:0
#setup_ipvsadm_table
#clear ipvsadm table
/sbin/ipvsadm -C
#installing LVS serviceswith ipvsadm
#add telnet to VIP withround robin scheduling
/sbin/ipvsadm -A -t 42.202.144.15:telnet-s rr
#forward telnet torealserver using direct routing with weight 1
/sbin/ipvsadm -a -t 42.202.144.15:telnet-r 42.202.144.11 -g -w 1
#check realserverreachable from director
ping -c 1 42.202.144.11
#forward telnet torealserver using direct routing with weight 1
/sbin/ipvsadm -a -t 42.202.144.15:telnet-r 42.202.144.12 -g -w 1
#check realserverreachable from director
ping -c 1 42.202.144.12
#displaying ipvsadmsettings
/sbin/ipvsadm