Lvs DR模型
环境:
VIP:192.168.11.17
DIP:192.168.11.26
RIP1:192.168.11.21
RVIP1:192.168.11.17
RIP2:192.168.11.30
RVIP2:192.168.11.17
一、Director配置
[root@web2 ~]# ifconfig #查看网络接口信息 eth0 Link encap:Ethernet HWaddr 00:0C:29:AD:98:5C inet addr:192.168.11.26 Bcast:192.168.11.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fead:985c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1066497 errors:0 dropped:0 overruns:0 frame:0 TX packets:1008429 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:94370565 (89.9 MiB) TX bytes:124526653 (118.7 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) [root@web2 ~]# ifconfig eth0:0 192.168.11.17 netmask 255.255.255.255 broadcast 192.168.11.17 #配置eth0:0的VIP地址,并且只广播192.168.11.17这个IP [root@web2 ~]# ifconfig #查看网络接口信息 eth0 Link encap:Ethernet HWaddr 00:0C:29:AD:98:5C inet addr:192.168.11.26 Bcast:192.168.11.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fead:985c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1066497 errors:0 dropped:0 overruns:0 frame:0 TX packets:1008429 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:94370565 (89.9 MiB) TX bytes:124526653 (118.7 MiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:AD:98:5C #查看配置的信息 inet addr:192.168.11.17 Bcast:192.168.11.17 Mask:255.255.255.255 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) [root@web2 ~]# ipvsadm -A -t 192.168.11.17:80 -s rr #配置ipvsadm VIP:PORT,调度为rr [root@web2 ~]# ipvsadm -a -t 192.168.11.17:80 -r 192.168.11.21 -g -w 1 #加入ipvsadm VIP:PROT,权重为1,rr算法忽略权重,使用wrr即可有用 [root@web2 ~]# ipvsadm -a -t 192.168.11.17:80 -r 192.168.11.30 -g -w 2 #加入ipvsadm VIP:PROT,权重为2,rr算法忽略权重,使用wrr即可有用 [root@web2 ~]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.11.17:80 rr -> 192.168.11.21:80 Route 1 0 0 -> 192.168.11.30:80 Route 2 0 0
二、RS1配置
1、安装httpd服务,并设定页面信息为===21===
[root@jroa ~]# vim /var/www/html/index.html [root@jroa ~]# cat /var/www/html/index.html===21===
2、配置环境,可以直接写一个脚本运行下就好了
[root@jroa ~]# cat skp.sh #!/bin/bash # vip=192.168.11.17 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 lo:0 $vip netmask 255.255.255.255 broadcast $vip route add -host $vip dev lo:0 ;; stop) 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 ifconfig lo:0 del $vip ;; esac [root@jroa ~]# ./skp.sh start [root@jroa ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:4E:CE:B9 inet addr:192.168.11.21 Bcast:192.168.11.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe4e:ceb9/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:650171 errors:0 dropped:0 overruns:0 frame:0 TX packets:573969 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:110093761 (104.9 MiB) TX bytes:70375622 (67.1 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:1608 errors:0 dropped:0 overruns:0 frame:0 TX packets:1608 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:150747 (147.2 KiB) TX bytes:150747 (147.2 KiB) lo:0 Link encap:Local Loopback inet addr:192.168.11.17 Mask:255.255.255.255 UP LOOPBACK RUNNING MTU:65536 Metric:1 [root@jroa ~]# cat /proc/sys/net/ipv4/conf/all/arp_ignore 1 [root@jroa ~]# cat /proc/sys/net/ipv4/conf/all/arp_announce 三、RS2配置 1、安装httpd服务,并设定页面信息为===30=== [root@CentOS7_30 ~]# vim /var/www/html/index.html [root@CentOS7_30 ~]# cat /var/www/html/index.html===30===
2、配置环境,可以直接写一个脚本运行下就好了 [root@CentOS7_30 ~]# cat skp.sh #!/bin/bash # vip=192.168.11.17 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 lo:0 $vip netmask 255.255.255.255 broadcast $vip route add -host $vip dev lo:0 ;; stop) 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 ifconfig lo:0 del $vip ;; esac [root@CentOS7_30 ~]# ./skp.sh start [root@CentOS7_30 ~]# ifconfig eno16780032: flags=4163mtu 1500 inet 192.168.11.30 netmask 255.255.255.0 broadcast 192.168.11.255 inet6 fe80::20c:29ff:fec8:1bd5 prefixlen 64 scopeid 0x20 ether 00:0c:29:c8:1b:d5 txqueuelen 1000 (Ethernet) RX packets 467264 bytes 39421187 (37.5 MiB) RX errors 0 dropped 40 overruns 0 frame 0 TX packets 411092 bytes 50696991 (48.3 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 0 (Local Loopback) RX packets 989 bytes 97596 (95.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 989 bytes 97596 (95.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo:0: flags=73 mtu 65536 inet 192.168.11.17 netmask 255.255.255.255 loop txqueuelen 0 (Local Loopback)
四、在Director查看下VIP的MAC地址
[root@web2 ~]# ifconfig #我们发下VIP的MAC地址为:00:0C:29:AD:98:5C 与上面的一致 eth0 Link encap:Ethernet HWaddr 00:0C:29:AD:98:5C inet addr:192.168.11.26 Bcast:192.168.11.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fead:985c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1068566 errors:0 dropped:0 overruns:0 frame:0 TX packets:1008825 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:94521078 (90.1 MiB) TX bytes:124573363 (118.8 MiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:AD:98:5C inet addr:192.168.11.17 Bcast:192.168.11.17 Mask:255.255.255.255 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
五、在其他机子ping测试并arp看下MAC地址对不对,并且curl访问测试
[root@redis_master ~]# ping 192.168.11.17 #ping VIP地址 PING 192.168.11.17 (192.168.11.17) 56(84) bytes of data. 64 bytes from 192.168.11.17: icmp_seq=1 ttl=64 time=1.26 ms ^C --- 192.168.11.17 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 608ms rtt min/avg/max/mdev = 1.265/1.265/1.265/0.000 ms [root@redis_master ~]# arp #查看下VIP的MAC地址为:00:0c:29:ad:98:5c Address HWtype HWaddress Flags Mask Iface 192.168.11.9 ether 00:0c:29:49:94:30 C eth0 192.168.11.17 ether 00:0c:29:ad:98:5c C eth0 [root@redis_master ~]# curl http://192.168.11.17 #访问测试OK,是rr调度方式,wrr或其它请执行测试===21===
[root@redis_master ~]# curl http://192.168.11.17===30===
[root@redis_master ~]# curl http://192.168.11.17===21===
[root@redis_master ~]# curl http://192.168.11.17===30===