lvs 的 NAT
LVS服务器(DR) | DIP:192.168.126.156 | VIP:192.168.126.250 |
---|
apache服务器(RS1) | IP:192.168.126.155 | VIP:192.168.126.250 |
apache服务器(RS2) | IP:192.168.126.154 | VIP:192.168.126.250 |
##配置DR的IP
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens160
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens160
UUID=4e00abb5-a536-48b9-a093-ce0b513ffbfb
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.126.156
IPADDR1=192.168.126.250
NETMASK=255.255.255.0
GATEWAY=192.168.126.2
DNS1=114.114.114.114
DNS2=8.8.8.8
[root@localhost ~]# ifup ens160
##开启转发功能
[root@localhost ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1 ##添加此行
[root@localhost ~]# sysctl -p
net.ipv4.ip_forward = 1
##添加规则调度器
[root@localhost ~]# ipvsadm -A -t 192.168.126.156:80 -s rr
[root@localhost ~]# 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.126.156:80 rr
[root@localhost ~]# ipvsadm -a -t 192.168.126.156:80 -r 192.168.126.155:80 -m
[root@localhost ~]# ipvsadm -a -t 192.168.126.156 -r 192.168.126.154:80 -m
[root@localhost ~]# ipvsadm -Sn > /etc/sysconfig/ipvsadm
[root@localhost ~]# vim /etc/sysconfig/ipvsadm
[root@localhost ~]# cat /etc/sysconfig/ipvsadm
-A -t 192.168.14.10:80 -s rr
-a -t 192.168.14.10:80 -r 192.168.126.156:80 -m -w 1
-a -t 192.168.14.10:80 -r 192.168.126.154:80 -m -w 1
[root@localhost ~]# echo '192.168.126.155' > /var/www/html/index.html
[root@localhost ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# echo '192.168.126.154' > /var/www/html/index.html
[root@localhost ~]# systemctl enable --now httpd
[root@localhost network-scripts]# curl http://192.168.126.250
yi
[root@localhost network-scripts]# curl http://192.168.126.250
er
lvs 的 DR
LVS服务器(DR) | DIP:192.168.126.155 | VIP:192.168.126.250 |
---|
apache服务器(RS1) | IP:192.168.126.154 | VIP:192.168.126.250 |
apache服务器(RS2) | IP:192.168.126.156 | VIP:192.168.126.250 |
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens160
UUID=4e00abb5-a536-48b9-a093-ce0b513ffbfb
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.126.155
IPADDR1=192.168.126.250
NETMASK=255.255.255.0
GATEWAY=192.168.126.2
DNS1=114.114.114.114
DNS2=8.8.8.8
[root@RS1 ~]# ifup ens160
##配置RS1与RS2的APR内核参数
[root@RS1 ~]# vim /etc/sysctl.conf
[root@RS1 ~]# cat /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@RS1 ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@RS2 ~]# vim /etc/sysctl.conf
[root@RS2 ~]# cat /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@RS2 ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@RS2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens160
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens160
UUID=4e00abb5-a536-48b9-a093-ce0b513ffbfb
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.126.154
IPADDR1=192.168.126.250
NETMASK=255.255.255.0
GATEWAY=192.168.126.2
DNS1=114.114.114.114
DNS2=8.8.8.8
[root@RS2 ~]# ifup ens160
##DR上安装ipvsadm
[root@RS1 ~]# yum -y install ipvsadm
[root@RS1 ~]# ipvsadm -a -t 192.168.126.250:80 -r 192.168.126.154:80 -g
[root@RS1 ~]# ipvsadm -a -t 192.168.126.250:80 -r 192.168.126.156:80 -g
[root@RS1 ~]# ipvsadm -Sn > /etc/sysconfig/ipvsadm
[root@RS1 ~]# echo "yi" > /usr/share/httpd/noindex/index.html
[root@RS2 ~]# echo "er" > /usr/share/httpd/noindex/index.html