服务器主机:
10.200.3.100 DirectServer
10.200.3.99 RealServer1
10.200.3.101 RealServer2
10.200.3.200 VIP
安装配置:
DirectServer端操作:
yum install ipvsadm
配置DirectServer,创建文件 /etc/init.d/lvs_vsadm.sh, 并赋予执行权限
#!/bin/sh VIP=10.200.3.200
RIP1=10.200.3.99
RIP2=10.200.3.101
/etc/rc.d/init.d/functions case "$1" in
start)
echo "start LVS of DirectorServer"
#set the Virtual IP Address
ifconfig ens160: $VIP/
#/sbin/route add -host $VIP dev ens160:
#Clear IPVS table
/sbin/ipvsadm -C
#set LVS
/sbin/ipvsadm -A -t $VIP: -s rr
/sbin/ipvsadm -a -t $VIP: -r $RIP1: -g
/sbin/ipvsadm -a -t $VIP: -r $RIP2: -g
#Run LVS
/sbin/ipvsadm
#end
;;
stop)
echo "close LVS Directorserver"
/sbin/ipvsadm -C
;;
*)
echo "Usage: $0 {start|stop}"
exit
esac
启动lvsadm服务:
#/etc/init.d/lvs_vsadm.sh start
start LVS of DirectorServer
IP Virtual Server version 1.2. (size=)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP Pt-gitlab:http rr
-> 10.200.3.99:http Route
-> 10.200.3.101:http Route
配置RealServer,两台配置一样,新建文件 /etc/init.d/realserver.sh 并赋予执行权限
#!/bin/sh
VIP=10.200.3.200
/etc/rc.d/init.d/functions
case "$1" in
start)
echo "Start LVS of RealServer"
/sbin/ifconfig lo: $VIP broadcast $VIP netmask 255.255.255.255 up
echo "" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
/sbin/ifconfig lo: down
echo "Stop LVS of RealServer"
echo "" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage:$0{start|stop}"
exit
esac
启动执行脚本:
# /etc/init.d/lvs_dr.sh start
至此,单节点lvsadm部署完成.