(2)在DIR上新建一个shell脚本文件,如下操作所示:
# vim /etc/init.d/lvs-nat
脚本内容如下
#!/bin/sh
#
# Startup script handle the initialisation of LVS
# chkconfig: - 28 72
# description: Initialise the Linux Virtual Server for NAT
#
### BEGIN INIT INFO
# Provides: ipvsadm
# Required-Start: $local_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Short-Description: Initialise the Linux Virtual Server
# Description: The Linux Virtual Server is a highly scalable and highly
# available server built on a cluster of real servers, with the load
# balancer running on Linux.
# description: start LVS of Nat
LOCK=/var/lock/ipvsadm.lock
VIP=192.168.10.10
RIP1=192.168.6.9
RIP2=192.168.6.11
. /etc/rc.d/init.d/functions
start() {
if [ -e $LOCK ];
then
echo "The LVS-NAT Server is already running !"
else
echo "1" >/proc/sys/net/ipv4/ip_forward
echo "0" >/proc/sys/net/ipv4/conf/all/send_redirects
echo "0" >/proc/sys/net/ipv4/conf/default/send_redirects
echo "0" >/proc/sys/net/ipv4/conf/eth0/send_redirects
echo "0" >/proc/sys/net/ipv4/conf/eth1/send_redirects
/bin/touch $LOCK
#Clear IPVS table
/sbin/ipvsadm -C
#set LVS
/sbin/ipvsadm -At $VIP:80 -s rr
/sbin/ipvsadm -at $VIP:80 -r $RIP1:80 -m -w 1
/sbin/ipvsadm -at $VIP:80 -r $RIP2:80 -m -w 1
echo "starting LVS-NAT Server is ok!"
fi
}