Lvs Dr 模式配置

1Dr 安裝 ipvsadmvim

# yum -y install ipvsadmbash

 

# lsmod | grep ip_vs    #檢查ipvs模塊是否加載進系統ipvs模塊加載進系統,須要咱們執行ipvsadm命令纔會加載進去或者modprobe ip_vsspa

 

# modprobe ip_vs      #加載ipvs模塊rest

# lsmod | grep ip_vsserver

ip_vs                 125220  0ip

 

# echo 1 > /proc/sys/net/ipv4/ip_forward  #開啓路由轉發路由

 

二、Dr 配置VIP地址class

# ifconfig  eth0:0  VIP/24配置

# route add -host  VIP  dev  eth0route

 

三、配置LVS、添加Real server節點

# ipvsadm -C            #清空原有配置

# ipvsadm -A -t VIP:80 -s rr -p 20        #指定VIP

# ipvsadm -a -t VIP:80 -r RS1:80 -g -w 1   #rs1節點

# ipvsadm -a -t VIP:80 -r RS2:80 -g -w 1   #rs2節點

# ipvsadm -L -n                      #查看lvs 配置

 

腳本

# vim /usr/local/sbin/ipvs

#!/bin/bash

PORT=80

VIP=192.168.119.150

RIP=(192.168.119.134

192.168.119.135

)

start(){

ifconfig eth0:0 $VIP/24 up

route add -host $VIP dev eth0

ipvsadm -C

ipvsadm -A -t $VIP:$PORT -s rr -p 20for ((i=0;i<${#RIP[*]};i++))do

ipvsadm -a -t $VIP:$PORT -r ${RIP[$i]}:$PORT -g -w 1

done

}

stop(){

  ipvsadm -C

  ifconfig eth0:0 down

  route del -host $VIP dev eth0

}case "$1" in

        start)

          start

        echo "ipvs is start"

        ;;

        stop)

        stop

        echo "ipvs is stop"

        ;;

        restart)

        stop

        echo "ipvs is stop"

        start

        echo "ipvs is start"

        ;;

        *)

        echo "usage:$0 {start|stop|restart}"

esac

 

四、Rs 配置

 

添加lo端口的VIP

# ifconfig lo:0  192.168.119.150/32 up

# route add -host 192.168.119.150 dev lo

 

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_announce

# echo "2">/proc/sys/net/ipv4/conf/all/arp_announce

 

腳本

#!/bin/bash

VIP=192.168.119.150

PORT=80

case "$1" in

  start)

        ifconfig eth0:0 $VIP/32 up

        route add -host $VIP dev eth0

        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_announce

        echo "2">/proc/sys/net/ipv4/conf/all/arp_announce

        echo "start LVS of REALServer IP"

        ;;

  stop)

        ifconfig eth0:0 $VIP/32 down

        route del -host $VIP dev eth0

        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_announce

        echo "0">/proc/sys/net/ipv4/conf/all/arp_announce

        echo "stop LVS OF REALServer"

        ;;*)

        echo "Usage: $0 {start|stop}"

esac

相關文章
相關標籤/搜索