343ff 发表于 2014-4-10 17:16:39

LVS DR 实验环境部署脚本

LVS DR 实验环境部署脚本


#!/bin/bash

# Lvs_dr
#
# Client    CIP: 172.16.20.101/24   eth0:br0
#
# Server_GW IP1: 172.16.20.102eth0:br0
#       IP2: 192.168.0.254eth1:br1
#
# DirectorVIP: 192.168.0.1/24 eth0:br1
#       DIP: 10.0.0.254/24eth1:br1
#
# RealServerA   RIP: 10.0.0.1/24    eth0:br1
#               RIP: 192.168.0.10       eth0:1:br1
#
# RealServerB   RIP: 10.0.0.2/24    eth0:br1
#               RIP: 192.168.0.20       eth0:1:br1
#

client(){
    #配置网络地址
    ifconfig eth0 172.16.20.101 netmask 255.255.255.0
      route del default
      route add default gw 172.16.20.102
    return
}<br>
server_gw(){
    #配置网络地址
    ifconfig eth0 172.16.20.102 netmask 255.255.255.0
    ifconfig eth1 192.168.0.254 netmask 255.255.255.0

    #开启转发
    echo 1 > /proc/sys/net/ipv4/ip_forward

}

director(){
    #配置网络地址
    ifconfig eth0 192.168.0.1 netmask 255.255.255.0
    ifconfig eth1 10.0.0.254 netmask 255.255.255.0

    route del default
      route add default gw 192.168.0.254

    #开启Debug
    ipvsadm -L -n
    echo 12 > /proc/sys/net/ipv4/vs/debug_level

    #关闭转发
    echo 0 > /proc/sys/net/ipv4/ip_forward

    #配置策略
    ipvsadm -C
    ipvsadm -A -t 192.168.0.1:80 -s wrr
    ipvsadm -a -t 192.168.0.1:80 -r 10.0.0.1:80 -g -w 1
    ipvsadm -a -t 192.168.0.1:80 -r 10.0.0.2:80 -g -w 2

    return
}

realservera(){
    #配置网络地址
    ifconfig eth0 10.0.0.1 netmask 255.255.255.0
    ifconfig eth0:1 192.168.0.10 netmask 255.255.255.0

    #添加VIP
    ifconfig lo:1 192.168.0.1 netmask 255.255.255.255

    #关闭内部ARP转发
    echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
    echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce<br>      echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore<br>      echo 2 > /proc/sys/net/ipv4/conf/all/arp_ignore

    route del default
      route add default gw 192.168.0.254
    echo "serverA" > /var/www/html/index.html
    /etc/init.d/httpd restart

    return
}
realserverb(){
    #配置网络地址
    ifconfig eth0 10.0.0.2 netmask 255.255.255.0
    ifconfig eth0:1 192.168.0.20 netmask 255.255.255.0

    #添加VIP
    ifconfig lo:1 192.168.0.1 netmask 255.255.255.255

    #关闭内部ARP转发
    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<br>      echo 2 > /proc/sys/net/ipv4/conf/all/arp_ignore

      route del default
      route add default gw 192.168.0.254
    echo "serverB" > /var/www/html/index.html
    /etc/init.d/httpd restart

    return
}


页: [1]
查看完整版本: LVS DR 实验环境部署脚本