LVS-DR模式多网段案例
RS 的配置脚本
#!/bin/bash
vip=10.0.0.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
ifconfigdev vip netmaskYou can't use 'macro parameter character #' in math modemask #broadcast vip up
#route add -hostvip dev dev
;;
stop)
ifconfigdev 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 "Usage: (basename0) start|stop"
exit 1
;;
esac
VS的配置脚本
#!/bin/bash
vip='10.0.0.100'
iface='lo:1'
mask='255.255.255.255'
port='80'
rs1='192.168.8.101'
rs2='192.168.8.102'
scheduler='wrr'
type='-g'
case 1 in
start)
ifconfigiface vip netmaskmask #broadcast vip up
iptables -F ipvsadm -A -t{vip}:{port} -sscheduler
ipvsadm -a -t {vip}:{port} -r {rs1}type -w 1
ipvsadm -a -t {vip}:{port} -r {rs2}type -w 1
;;
stop)
ipvsadm -C
ifconfig iface down
;;
*)
echo "Usage(basename $0) start|stop“
exit 1
esac
跨网段DR模型案例
配置
[root@rs1 ~]#cat lvs_dr_rs.sh
#!/bin/bash
#Author:wangxiaochun
#Date:2017-08-13
vip=192.168.0.100
mask='255.255.255.255'
dev=lo:1
#rpm -q httpd &> /dev/null || yum -y install httpd &>/dev/null
#service httpd start &> /dev/null && echo "The httpd Server is Ready!"
#echo "<h1>hostname
</h1>" > /var/www/html/index.html
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
ifconfigdev vip netmaskmask #broadcast vip up
#route add -hostvip dev dev
echo "The RS Server is Ready!"
;;
stop)
ifconfigdev 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 "The RS Server is Canceled!"
;;
*)
echo "Usage: (basename0) start|stop"
exit 1
;;
esac
[root@rs1 ~]#bash lvs_dr_rs.sh start
[root@rs2 ~]#bash lvs_dr_rs.sh start
[root@LVS ~]#cat lvs_dr_vs.sh
#!/bin/bash
#Author:wangxiaochun
#Date:2017-08-13
vip='192.168.0.100'
iface='lo:1'
mask='255.255.255.255'
port='80'
rs1='10.0.0.7'
rs2='10.0.0.17'
scheduler='wrr'
type='-g'
rpm -q ipvsadm &> /dev/null || yum -y install ipvsadm &> /dev/null
case 1 in
start)
ifconfigiface vip netmaskmask #broadcast vip up
iptables -F
ipvsadm -A -t{vip}:{port} -sscheduler
ipvsadm -a -t {vip}:{port} -r {rs1}type -w 1
ipvsadm -a -t {vip}:{port} -r {rs2}type -w 1
echo "The VS Server is Ready!"
;;
stop)
ipvsadm -C
ifconfig iface down
echo "The VS Server is Canceled!"
;;
*)
echo "Usage:(basename $0) start|stop"
exit 1
;;
esac
[root@LVS ~]#bash lvs_dr_vs.sh start
[root@Router ~]#nmcli connection modify eth0 +ipv4.addresses 192.168.0.200/24
[root@Router ~]#nmcli connection reload
[root@Router ~]#nmcli connection up eth0
[root@Router ~]#ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:4d:ef:3e brd ff:ff:ff:ff:ff:ff
inet 10.0.0.200/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet 192.168.0.200/24 brd 192.168.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe4d:ef3e/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:4d:ef:48 brd ff:ff:ff:ff:ff:ff
inet 172.20.200.200/16 brd 172.20.255.255 scope global noprefixroute eth1
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe4d:ef48/64 scope link
valid_lft forever preferred_lft forever
本文链接:http://www.yunweipai.com/35616.html
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/52767.html