Lvs dr tunl real machine script

Source: Internet
Author: User

#! /Bin/bash
# Create lvs dr or tunl realservr scripts.
# Chenjian 2011-09-23
 
VIP_LIST = "192.168.116.20 192.168.116.21"
USAGE = "Usage: $0 {start | stop | status} {dr | tunl }"
NAME = tunl
NUM = 0
 
 
If [-z $1]
Then
Echo $ USAGE
Exit 2
Fi
 
ACTION = 'echo $1 | tr A-Z a-Z'
 
If! [$1 = status]
Then
If [-z $2]
Then
Echo $ USAGE
Exit 2
Fi
Fi
 
TYPE = 'echo $2 | tr A-Z a-Z'
 
Case "$1" in
Start)
 
If [$ TYPE = dr]
Then
If/sbin/ifconfig | grep lo:>/dev/null
Then
/Sbin/ifdown lo
/Sbin/ifup lo
Fi
For vip in 'echo $ VIP_LIST '; do
/Sbin/ifconfig lo: $ NUM $ vip netmask 255.255.255.255 broadcast $ vip
/Sbin/route add-host $ vip dev lo: $ NUM
NUM = 'echo $ [$ NUM + 1]'
Done
 
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
Sysctl-p>/dev/null 2> & 1
Echo "$ TYPE RealServer Start [OK]"
Elif [$ TYPE = tunl]
Then
For vip in 'echo $ VIP_LIST '; do
If [$ NAME = tunl]
Then
NAME = tunl0
/Sbin/ifconfig "$ NAME" $ vip netmask 255.255.255.255
/Sbin/route add-host $ vip dev $ NAME
Else
/Sbin/ifconfig "$ NAME": "$ NUM" $ vip netmask 255.255.255.255
/Sbin/route add-host $ vip dev $ NAME
Fi
NUM = 'echo $ [$ NUM + 1]'
Done
Echo 1>/proc/sys/net/ipv4/conf/tunl0/arp_ignore
Echo 2>/proc/sys/net/ipv4/conf/tunl0/arp_announce
Echo 0>/proc/sys/net/ipv4/conf/tunl0/arp_filter
Echo 1>/proc/sys/net/ipv4/conf/tunl0/forwarding
Echo 1>/proc/sys/net/ipv4/conf/all/arp_ignore
Echo 2>/proc/sys/net/ipv4/conf/all/arp_announce
 
Sysctl-p>/dev/null 2> & 1
Echo "$ TYPE RealServer Start [OK]"
Else
Echo $ USAGE
Exit 2
Fi
;;
Stop)
If [$ TYPE = dr]
Then
For vip in 'echo $ VIP_LIST '; do
/Sbin/ifconfig lo: $ NUM down
/Sbin/route del $ vip
NUM = 'echo $ [$ NUM + 1]'
Done
Echo "0">/proc/sys/net/ipv4/conf/lo/arp_ignore
Echo "0">/proc/sys/net/ipv4/conf/lo/arp_announce
Echo "0">/proc/sys/net/ipv4/conf/all/arp_ignore
Echo "0">/proc/sys/net/ipv4/conf/all/arp_announce
 
Sysctl-p>/dev/null 2> & 1
Echo "$ TYPE RealServer Stop [OK]"
Elif [$ TYPE = tunl]
Then
/Sbin/ifconfig tunl0 down
 
Echo 0>/proc/sys/net/ipv4/conf/tunl0/arp_ignore
Echo 0>/proc/sys/net/ipv4/conf/tunl0/arp_announce
Echo 1>/proc/sys/net/ipv4/conf/tunl0/arp_filter
Echo 0>/proc/sys/net/ipv4/conf/all/arp_ignore
Echo 0>/proc/sys/net/ipv4/conf/all/arp_announce
 
Else
Echo $ USAGE
Exit 2
Fi
;;
Status)
If/sbin/ifconfig | grep-q 'lo :'
Then
TYPE = dr
Elif/sbin/ifconfig | grep-q 'tunl'
Then
TYPE = tunl
Else
Exit 2
Fi

For vip in 'echo $ VIP_LIST '; do
 
If [! '/Sbin/ifconfig | grep-q $ vip'-o! 'Netstat-rn | grep $ vip '];
Then
Echo "LVS-$ TYPE real server stopped, vip = $ vip"
Else
Echo "LVS-$ TYPE Running, vip = $ vip"
Fi
Done
 
;;
*)
Echo "$ USAGE"
Exit 1
;;
Esac
 
Author "If one day"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.