■負載均衡群集工作模式–直接路由(Direct Routing)
注意:如果跨網段,那麼報文通過路由器經由 terne返回給使用者
■在區域網中具有相同的IP地址,勢必會造成各伺服器ARP通訊的紊亂
■對節點伺服器進行處理,使其不響應針對VIP的ARP請求
■RealServe返回報文(源IP是VIP)經路由器轉發,在重新封裝報文時需要先獲取路由器的MAC地址
■修改/etc/sysctl.conf檔案
排程器 | VM1: 192.168.100.21 | ens3:0:192.168.100.10 |
---|---|---|
WEB1伺服器叢集池 | VM1: 192.168.100.22 | lo:0:192.168.100.10 |
WEB2伺服器叢集池 | VM1: 192.168.100.23 | lo:0:192.168.100.10 |
NFS共用伺服器 | VM1: 192.168.100.24 |
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vi ifcfg-ens33:0
NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.100.10
NETMASK=255.255.255.255
[root@localhost network-scripts]# ifup ifcfg-ens33:0
[root@localhost network-scripts]# ifconfig ## 如果-bash: ifconfig: command not found報錯,安裝 sudo yum install net-tools,按提示輸入y,就可以了
[root@localhost network-scripts]# vi /etc/sysctl.conf
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
[root@localhost network-scripts]# sysctl -p ###生效
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
[root@localhost /]# ipvsadm -v
[root@localhost ~]# modprobe ip_vs
[root@localhost ~]# cat /proc/net/ip_vs
[root@localhost ~]#yum -y install ipvsadm
[root@localhost ~]#ipvsadm -A -t 192.168.100.10:80 -s rr
[root@localhost ~]#ipvsadm -a -t 192.168.100.10:80 -r 192.168.100.22:80 -g -w 1
[root@localhost ~]#ipvsadm -a -t 192.168.100.10:80 -r 192.168.100.23:80 -g -w 1
[root@localhost network-scripts]# ipvsadm-save
[root@localhost network-scripts]# systemctl enable ipvsadm
rpm -q nfs-utils ###如果沒裝,yum -y install nfs-utils
rpm -q rpcbind ###如果沒裝,yum -y install rpcbind
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# vi /etc/exports
/opt/51xit 192.168.100.0/24 (rw,sync)
/opt/52xit 192.168.100.0/24 (rw,sync)
[root@localhost ~]# systemctl restart nfs
[root@localhost ~]# systemctl restart rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# mkdir /opt/51xit /opt/52xit
[root@localhost ~]# echo "this is 51xit" >/opt/51xit/index.html
[root@localhost ~]# echo "this is 52xit" >/opt/52xit/index.html
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vi ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.255
ONBOOT=yes
[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ifconfig ## 如果-bash: ifconfig: command not found報錯,安裝 sudo yum install net-tools,按提示輸入y,就可以了
[root@localhost network-scripts]# vi /etc/rc.local
/sbin/route add -host 192.168.100.10 dev lo:0
[root@localhost network-scripts]# route add -host 192.168.100.10 dev lo:0
[root@localhost network-scripts]# vi /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
[root@localhost network-scripts]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
[root@localhost ~]# yum -y install nfs-utils
[root@localhost ~]# showmount -e 192.168.100.24 ####如果還沒釋出,請到儲存伺服器釋出下,exportfs -rv
Export list for 192.168.100.24:
/opt/51xit (everyone)
/opt/52xit (everyone)
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# mount 192.168.100.24:/opt/51xit /var/www/html/
[root@localhost ~]# vi /etc/fstab
192.168.100.44:/opt/51xit/ /var/www/html/ nfs rw,tcp,intr 0 1 ###開機自動掛載,注意格式對齊
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vi ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.255
ONBOOT=yes
[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ifconfig ## 如果-bash: ifconfig: command not found報錯,安裝 sudo yum install net-tools,按提示輸入y,就可以了
[root@localhost network-scripts]# vi /etc/rc.local
/sbin/route add -host 192.168.100.10 dev lo:0
[root@localhost network-scripts]# route add -host 192.168.100.10 dev lo:0
[root@localhost network-scripts]# vi /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
[root@localhost network-scripts]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
[root@localhost ~]# yum -y install nfs-utils
[root@localhost ~]# showmount -e 192.168.100.24 ####如果還沒釋出,請到儲存伺服器釋出下,exportfs -rv
Export list for 192.168.100.24:
/opt/accp (everyone)
/opt/bdqn (everyone)
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# mount 192.168.100.24:/opt/52xit /var/www/html/
[root@localhost ~]# vi /etc/fstab
192.168.100.24:/opt/52xit/ /var/www/html/ nfs rw,tcp,intr 0 1 ###開機自動掛載,注意格式對齊
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd