lvs的nat模式httpd /httpds
[root@localhost network-scripts]# vim ifcfg-ens160
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR0=192.168.11.150
NETMASK0=255.255.255.0
GATEWAY0=192.168.11.2
IPADDR1=192.168.11.250
NETMASK1=255.255.255.0
//重启网卡
[root@localhost network-scripts]# systemctl restart NetworkManager
[root@localhost network-scripts]# ifdown ens160; ifup ens160
[root@localhost network-scripts]# vim ifcfg-ens160
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR0=192.168.11.148
NETMASK0=255.255.255.0
GATEWAY0=192.168.11.150
[root@localhost network-scripts]# ifdown ens160;ifup ens160
[root@localhost network-scripts]# yum -y install net-tools
//开启转发功能
[root@localhost network-scripts]# 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.11.250: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.11.250:80 rr
[root@localhost ~]# ipvsadm -a -t 192.168.11.250:80 -r 192.168.11.148:80 -m
[root@localhost ~]# ipvsadm -a -t 192.168.11.250:80 -r 192.168.11.146:8080 -m
保持
[root@localhost ~]# ipvsadm -Sn > /etc/sysconfig/ipvsadm
[root@localhost ~]# cat /etc/sysconfig/ipvsadm
-A -t 192.168.11.250:80 -s rr
-a -t 192.168.11.250:80 -r 192.168.11.146:8080 -m -w 1
-a -t 192.168.11.250:80 -r 192.168.11.148:80 -g -w 1
[root@localhost ~]#
[root@localhost html]# echo 'esl' > index.html
[root@localhost html]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost html]#
//关闭防火墙和seliunx
[root@localhost html]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost html]# setenforce 0
[root@localhost ~]# curl http://192.168.11.250
rs2
[root@localhost ~]# curl http://192.168.11.250
esl
[root@localhost ~]# curl http://192.168.11.250
rs2
[root@localhost ~]# curl http://192.168.11.250
esl
[root@localhost ~]# curl http://192.168.11.250
rs2
[root@localhost ~]# curl http://192.168.11.250
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens160
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR0=192.168.11.148
NETMASK0=255.255.255.0
GATEWAY0=192.168.11.2
~
[root@localhost ~]# vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@localhost ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@localhost ~]#
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens1
IPADDR1=192.168.11.250
NETMASK1=255.255.255.0
~
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens160
GATEWAY0=192.168.11.2
//修改内核
[root@localhost ~]# echo 'net.ipv4.conf.all.arp_ignore = 1'>> /etc/sysctl.conf
[root@localhost ~]# echo 'net.ipv4.conf.all.arp_announce = 2' >> /etc/sysctl.conf
[root@localhost ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@localhost ~]#
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens160
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR0=192.168.11.146
NETMASK0=255.255.255.0
GATEWAY0=192.168.11.2
IPADDR1=192.168.11.250
NETMASK1=255.255.255.0
~
[root@localhost ~]# ifdown ens160;ifup ens160
[root@localhost ~]# ipvsadm -A -t 192.168.11.250:80 -s rr
[root@localhost ~]# ipvsadm -a -t 192.168.11.250:80 -r 192.168.11.148:80 -g
[root@localhost ~]# ipvsadm -a -t 192.168.11.250:80 -r 192.168.11.146:8080 -g
[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.11.250:80 rr
-> 192.168.11.146:80 Route 1 0 0
-> 192.168.11.148:80 Route 1 0 0