標籤:src var forward rem 瀏覽器 https server images 緩衝
伺服器IP地址規劃(10.x類比公網地址,192.x私網地址,172.x私網地址)
NFS:192.168.30.33WEB1:192.168.30.17WEB2:192.168.30.27LVS:192.168.30.7 VIP:10.0.0.100DNS:172.20.42.27Mysql:192.168.30.30Route:192.168.30.208, 10.0.0.200,172.20.42.200Client: Windows IP 172.20.42.222
各伺服器配置WEB1
1. 網路 ifcfg-eth0 DEVICE=eth0 IPADDR=192.168.30.17 PREFIX=24 GATEWAY=192.168.30.208 ifcfg-eth0:1 DEVICE=eth0:1 IPADDR=10.0.0.100 PREFIX=82. 安裝相應的包 yum install httpd php-fpm php-mysql -y3. 在RS上修改核心參數以限制arp通告及應答級 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
WEB2
參考WEB1,只是將IP更改為192.168.30.27
DNS
1. 安裝 yum install bind -y2. 配置
vim /etc/named.rfc1912.zones
zone "blog.com" IN {
type master;
file "blog.com.zone";
};
vim /var/named/blog.com.zone
$TTL D
@ IN SOA master.blog.com admin.blog.com. (
0 ; serial
D ; refresh
H ; retry
W ; expire
H ) ; minimum
NS master
master A 172.20.42.27
www A 10.0.0.100
3. 啟動systemctl restart named
Route路由配置
1. 網路 ifcfg-eth0 DEVICE=eth0 BOOTPROTO=none IPADDR=192.168.30.208 PREFIX=24 ifcfg-eth0:1 DEVICE=eth0:1 BOOTPROTO=none IPADDR=10.0.0.200 PREFIX=8 ifcfg-eth1 DEVICE=eth1 BOOTPROTO=none IPADDR=172.20.42.200 PREFIX=162. 啟用ip_forward echo 1 > /prov/sys/net/ipv4/ip_forward sysctl -a |grep ip_forward: net.ipv4.ip_forward = 1
LVS配置
1. 網路ifcfg-eth0DEVICE=eth0BOOTPROTO=noneIPADDR=192.168.30.7PREFIX=24GATEWAY=192.168.30.208ifcfg-eth0:1DEVICE=eth0:1BOOTPROTO=noneIPADDR=10.0.0.100PREFIX=82. 運行如下的指令碼(適當變更) [[email protected] ~]#cat lvs_dr_vs.sh #!/bin/bash #Author:wangxiaochun #Date:2017-08-13 vip=‘10.0.0.100‘ iface=‘eth0:1‘ mask=‘255.255.255.255‘ port=‘80‘ rs1=‘192.168.30.17‘ rs2=‘192.168.30.27‘ scheduler=‘wrr‘ type=‘-g‘ rpm -q ipvsadm &> /dev/null || yum -y install ipvsadm &> /dev/null case $1 instart) ifconfig $iface $vip netmask $mask #broadcast $vip up iptables -F ipvsadm -A -t ${vip}:${port} -s $scheduler 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 3. 查看ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.0.0.100:80 wrr -> 192.168.30.17:80 Route 1 0 0 -> 192.168.30.27:80 Route 1 0 0 4. 更改lvs-dr的調度策略 ipvsadm -C ipvsadm -A -t 10.0.0.100:80 -s rr ipvsadm -a -t 10.0.0.100:80 -r 192.168.30.17 ipvsadm -a -t 10.0.0.100:80 -r 192.168.30.27 5. 測試新的策略 在Linux客戶機上,配置網路 DEVICE=eth2 BOOTPROTO=none IPADDR=172.20.0.7![](https://images2018.cnblogs.com/blog/1386066/201807/1386066-20180703114658714-1685106874.png) PREFIX=16 GATEWAY=172.20.42.200 DNS1=172.20.42.27 [[email protected] ~]# curl www.blog.com web1 [[email protected] ~]# curl www.blog.com web2 [[email protected] ~]# curl www.blog.com web1 [[email protected] ~]# curl www.blog.com web2 測試結論:達到了roundrobin輪詢的效果 6. 在windows PC上測試
在瀏覽器中訪問www.blog.com,可以看出,不是每次重新整理網站都會切換網站,是因為瀏覽器的緩衝導致。
實驗lvs+dns+nfs+mysql+web