實現(xiàn)LVS-DR調(diào)度web模式

  • 拓?fù)洵h(huán)境


    image
    image

網(wǎng)絡(luò)環(huán)境

RS1   
    RIP 192.168.198.138/24
    VIP 192.168.198.100/32
    GW  192.168.198.130
RS2 
    RIP 192.168.198.132/24
    VIP 192.168.198.100/32
    GW  192.168.198.130
VS
    DIP 192.168.198.128/24
    VIP 192.168.198.100/32
    GW  192.168.198.130
    
route 
    192.168.198.130/24
    172.16.253.166/16
Client 
    172.16.254.150/16
    GW 172.16.253.166
RS1,RS2的網(wǎng)關(guān)指向192.168.198.130

RS1

[root@RS1 html]# route del default gw 192.168.198.128
[root@RS1 html]# route add default gw 192.168.198.130

[root@RS1 ~]# iptables -F
[root@RS1 ~]# yum -y install httpd
[root@RS1 ~]# vim /var/www/html/index.html 
    welcome to RS1
[root@RS1 ~]# service httpd start

RS2

[root@RS2 network-scripts]# route add -net 172.16.0.0/16 gw 192.168.198.130
[root@RS2 network-scripts]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.16.0.0      192.168.198.130 255.255.0.0     UG    0      0        0 ens34
192.168.198.0   0.0.0.0         255.255.255.0   U     100    0        0 ens34
[root@RS2 ~]# iptables -F
[root@RS2 ~]# yum -y install httpd
[root@RS2 ~]# vim /var/www/html/index.html 
    welcome to RS2
[root@RS2 ~]# systemctl start httpd 

VS

添加網(wǎng)關(guān)路由信息
[root@VS ~]# route add default gw 192.168.198.130
[root@VS ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.198.130 0.0.0.0         UG    0      0        0 ens34
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.198.0   0.0.0.0         255.255.255.0   U     100    0        0 ens34

[root@VS ~]# vim lvs_dr.sh
#! /bin/bash
vip=192.168.198.100
server=$vip:80
rip1=192.168.198.138
rip2=192.168.198.132
sch=wlc
dev=ens34:1   \\綁定網(wǎng)卡ens34
case $1 in
start)
    ifconfig $dev $vip/32 broadcast $vip  \\綁定vip到ens34網(wǎng)卡上
    iptables -F
    ipvsadm -A -t $server -s $sch
    ipvsadm -a -t $server -r $rip1 -g -w 3
    ipvsadm -a -t $server -r $rip2 -g -w 1
    ;;
stop)
    ipvsadm -C
    ipconfig $dev down
    ;;
*)
    echo "Usage:$(basename $0) start|stop"
    exit 1
    ;;
esac

[root@danran ~]# bash lvs_dr.sh start
[root@danran ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
  TCP  192.168.198.100:80 wlc
  -> 192.168.198.132:80           Route   1      0          0         
  -> 192.168.198.138:80           Route   3      0          0   

添加RS1和RS2的VIP

dr_vip_rs.sh 為添加RS服務(wù)端VIP地址的腳本
[root@RS1 ~]# vim dr_vip_rs.sh 
#!/bin/bash
#
vip=192.168.198.100
mask='255.255.255.255'
dev=lo:1
case $1 in
start)
   echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
   echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
   echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
   echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
   ifconfig $dev $vip netmask $mask broadcast $vip up
   route add -host $vip dev $dev
   echo "VS server is Ready "
   ;;
stop)
   ifconfig $dev down
   echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
   echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
   echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
   echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
   echo "VS server is Cancel"
   ;;
*)
   echo "Usage $(basename $0) start|stop"
   exit 1
   ;;
esac   
[root@RS1 ~]# bash dr_vip_rs.sh start
VS server is Ready 
[root@RS2 ~]# bash dr_vip_rs.sh start
VS server is Ready 

client

添加路由
[root@danran ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.16.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         172.16.0.1      0.0.0.0         UG    0      0        0 eth0

[root@danran ~]# route del default gw 172.16.0.1 
[root@danran ~]# route add default gw 172.16.253.166 \\添加默認(rèn)路由
[root@danran ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.16.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         172.16.253.166  0.0.0.0         UG    0      0        0 eth0

測試  
[root@danran ~]# for i in {1..10};do curl --connect-timeout 1 192.168.198.100 ;sleep 1;done      
welcome to RS2
welcome to RS1
welcome to RS1
welcome to RS1
welcome to RS2
welcome to RS1
welcome to RS1
welcome to RS1
welcome to RS2
welcome to RS1
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容