#!/bin/sh # # Read in the LVS configuration file. . /etc/lvs.conf reset_lvs() { # Reset the LVS virtual server tables. $IPVSADM --clear } configure_networking() { # Turn off all relevant ICMP redirects. $LVS_IF is the network # interface used for LVS traffic on the director. 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/$LVS_IF/send_redirects # Turn on the IP forwarding flag echo "1" >/proc/sys/net/ipv4/ip_forward # Add interface and routing for the VIP interface. /sbin/ifconfig $VIP_IF $VIP netmask 255.255.248.0 broadcast 156.141.63.255 /sbin/route add -host $VIP dev $VIP_IF } remove_interface() { # Remove the VIP network interface. [ -n "$(ifconfig | grep ^$VIP_IF)" ] && /sbin/ifconfig $VIP_IF down } add_services() { # For each TCP service listed in the configuration, add the service # and add the Real-servers that provide the service. for TPORT in $TPORTS; do # -A = Add service; -t = Service uses TCP # $VIP:$TPORTS = Virtual IP Address of new service, and the port # number of the service being presented on this interface. # -s = scheduling method (rr = Round Robin) $IPVSADM -A -t $VIP:$TPORT -s rr # Add real-servers into the LVS cluster for the above service. # # -a = Add real-server; -t = Service uses TCP # 156.141.59.63:telnet = Virtual IP Address of new service, # and the port number of the service being presented on this interface. # -r : = hostname/IP Address of the real-server and port # number of the service on the real-server. # -m = use Masquerading (aka Network Address Translation) # -w = Weight of the real-server in the pool. Can be used to direct traffic # to more powerful servers in the pool. for RIP in $RIPS; do $IPVSADM -a -t $VIP:$TPORT -r $RIP:$TPORT -m -w 1 done done # For each UDP service listed in the configuration, add the service # and add the Real-servers that provide the service. for UPORT in $UPORTS; do # -A = Add service; -u = Service uses UDP # $VIP:$UPORTS = Virtual IP Address of new service, and the port # number of the service being presented on this interface. # -s = scheduling method (rr = Round Robin) $IPVSADM -A -u $VIP:$UPORT -s rr # Add real-servers into the LVS cluster for the above service. # # -a = Add real-server; -t = Service uses TCP # 156.141.59.63:telnet = Virtual IP Address of new service, # and the port number of the service being presented on this interface. # -r : = hostname/IP Address of the real-server and port # number of the service on the real-server. # -m = use Masquerading (aka Network Address Translation) # -w = Weight of the real-server in the pool. Can be used to direct traffic # to more powerful servers in the pool. for RIP in $RIPS; do $IPVSADM -a -u $VIP:$UPORT -r $RIP:$UPORT -m -w 1 done done } poll_servers() { # Ping each host in the cluster to verify whether or not they are # alive. Systems which do not respond should be removed from the # ipvs table. for RIP in $RIPS; do # In order to be reduce dependencies, assume that fping is # unavailable, and use the less efficient system ping command. In # order to accommodate network latency, systems that do not # respond will be polled again, up to a maximum of $SEEK # iterations. SEEK=4 while [ $SEEK -gt 0 ]; do [ -z "`ping -c 1 $RIP | grep 100%`" ] && SEEK=-1 || SEEK=$(($SEEK-1)) done # If SEEK is "-1" then a positive result was obtained and the host # is available to the network. Now check to see if the host is in # the LVS table -- if it is not, then add the host to the # configuration. if [ "$SEEK" = "-1" ]; then # Check to see if the host is already in the configuration. If # it is not, then add it. if [ -z "$($IPVSADM -l | grep $RIP)" ]; then for TPORT in $TPORTS; do $IPVSADM -a -t $VIP:$TPORT -r $RIP:$TPORT -m -w 1 done for UPORT in $UPORTS; do $IPVSADM -a -u $VIP:$UPORT -r $RIP:$UPORT -m -w 1 done mail -s "[LVS WARNING] Login Node Added" malcolm_cowe@xxxxxxxxxxx <