环境
IP | 服务 |
---|---|
192.168.1.100 | lvs调度器(DS)外网地址 |
192.168.2.110 | lvs调度器(DS)内网地址 |
192.168.2.111 | web服务器(RS1) |
192.168.2.112 | web服务器(RS2) |
拓扑
一、lvs 调度器安装
1、设置双网卡-内网:192.168.2.110,NAT模式 网段 192.168.2.0/24
2、 设置双网卡-外网:192.168.1.100,桥接模式跟我物理宿主机网卡同一个网段
3、查看IP
- [root@kvm110 ~]# ifconfig
- ens33: flags=4163
mtu 1500 - inet 192.168.2.110 netmask 255.255.255.0 broadcast 192.168.2.255
- inet6 fe80::6963:2857:478c:ecd4 prefixlen 64 scopeid 0x20<link>
- ether 00:0c:29:fb:5a:a1 txqueuelen 1000 (Ethernet)
- RX packets 1691 bytes 162793 (158.9 KiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 1252 bytes 228085 (222.7 KiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
- ens37: flags=4163
mtu 1500 - inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
- inet6 fe80::ae1c:36e0:2072:3c3c prefixlen 64 scopeid 0x20<link>
- ether 00:0c:29:fb:5a:ab txqueuelen 1000 (Ethernet)
- RX packets 2463 bytes 241054 (235.4 KiB)
- RX errors 0 dropped 5 overruns 0 frame 0
- TX packets 678 bytes 76564 (74.7 KiB)
- 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 1000 (Local Loopback)
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
4、配置转发
- cat <<EOF > /etc/sysctl.d/lvs-nat.conf
- net.ipv4.ip_forward = 1
- EOF
-
- # 生效
- sysctl -p /etc/sysctl.d/lvs-nat.conf
-
- # 动态加载ip_vs模块
- modprobe ip_vs
5、配置策略
- ipvsadm -C
- ipvsadm -A -t 192.168.1.100:80 -s rr
- ipvsadm -a -t 192.168.1.100:80 -r 192.168.2.111 -m
- ipvsadm -a -t 192.168.1.100:80 -r 192.168.2.112 -m
-
- # 保存
- ipvsadm-save > /etc/sysconfig/ipvsadm
-
- # 查看策略
- ipvsadm -ln
二、Web 服务器安装(2台都要安装)
1、安装并启动 httpd
- yum install httpd -y
- systemctl start httpd
2、修改主页内容
- # 修改 web 服务器 1
- vim /var/www/html/index.html
- this is 192.168.2.111
-
- # 修改 web 服务器 2
- vim /var/www/html/index.html
- this is 192.168.2.112
3、配置网关
- vim /etc/sysconfig/network-scripts/ifcfg-ens33
-
- 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=ens33
- UUID=e92e4fb7-96ed-4623-90cb-f5f9461f7b67
- DEVICE=ens33
- ONBOOT=yes
- IPADDR=192.168.2.111
- NETMASK=255.255.255.0
- GATEWAY=192.168.2.110 # 指向 IVS
- DNS1=8.8.8.8
-
- # 重启生效
- systemctl start network
三、宿主机访问