一、系统架构
二、部署过程
1、配置internet服务器
修改网卡eth0配置,使用仅主机模式
[10:58:30 root@internet ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 NAME=eth0 BOOTPROTO=none ONBOOT=yes IPADDR=192.168.10.101 PREFIX=24 GATEWAY=192.168.10.200
重启服务器,验证:
[10:56:42 root@internet ~]#route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.10.200 0.0.0.0 UG 100 0 0 eth0 192.168.10.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0 [10:56:46 root@internet ~]#ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:0c:29:24:4c:c1 brd ff:ff:ff:ff:ff:ff inet 192.168.10.101/24 brd 192.168.10.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe24:4cc1/64 scope link valid_lft forever preferred_lft forever
2、配置router服务器
2.1、配置eth0和eth1网卡
[11:20:53 root@router ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 NAME=eth0 BOOTPROTO=none ONBOOT=yes IPADDR=10.0.0.200 PREFIX=24 [11:21:07 root@router ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth1 DEVICE=eth1 NAME=eth1 BOOTPROTO=none ONBOOT=yes IPADDR=192.168.10.200 PREFIX=24 [11:21:08 root@router ~]#ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:0c:29:fc:02:d2 brd ff:ff:ff:ff:ff:ff inet 10.0.0.200/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fefc:2d2/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:0c:29:fc:02:dc brd ff:ff:ff:ff:ff:ff inet 192.168.10.200/24 brd 192.168.10.255 scope global noprefixroute eth1 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fefc:2dc/64 scope link valid_lft forever preferred_lft forever
2.2、开启ip_forward功能
[11:28:17 root@router ~]#echo net.ipv4.ip_forward = 1 >> /etc/sysctl.conf #使其生效 [11:28:17 root@router ~]#sysctl -p
3、配置lvs服务器
3.1、修改eth0网卡
[11:36:00 root@lvs ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 NAME=eth0 BOOTPROTO=none ONBOOT=yes IPADDR=10.0.0.8 PREFIX=24 GATEWAY=10.0.0.200
3.2、配置VIP
[11:36:13 root@lvs ~]#ifconfig lo:1 10.0.0.100/32 [16:13:54 root@lvs ~]#ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet 10.0.0.100/0 scope global lo:1 valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:0c:29:64:6d:66 brd ff:ff:ff:ff:ff:ff inet 10.0.0.8/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe64:6d66/64 scope link valid_lft forever preferred_lft forever
3.3、创建集群,使用轮询的调度算法
[16:13:56 root@lvs ~]#ipvsadm -A -t 10.0.0.100:80 -s rr [16:16:57 root@lvs ~]#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 rr
3.4、添加RS服务到集群中
[16:17:02 root@lvs ~]#ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.7 -g [16:18:12 root@lvs ~]#ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.17 -g [16:18:15 root@lvs ~]#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 rr -> 10.0.0.7:80 Route 1 0 0 -> 10.0.0.17:80 Route 1 0 0
4、配置RS服务器
4.1、安装apache、mysql、mod_ssl服务(验证功能作用)
[root@rs1 ~]# yum -y install httpd mysql-server mod_ssl
4.2、启动httpd服务(两台RS服务器都需要安装)
[root@rs1 ~]# systemctl enable --now httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
4.3、配置展示页面(特意配置不同)
#RS1 [root@rs1 ~]# cat /var/www/html/index.html rs1 10.0.0.7 #RS2 [root@rs2 ~]# cat /var/www/html/index.html rs2 10.0.0.17
效果如下:
[root@rs1 ~]# curl 10.0.0.7 rs1 10.0.0.7 [root@rs1 ~]# curl 10.0.0.17 rs2 10.0.0.17
4.4、配置eth0网卡
#RS1 [root@rs1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 NAME=eth0 BOOTPROTO=none ONBOOT=yes IPADDR=10.0.0.7 PREFIX=24 GATEWAY=10.0.0.200 #RS2 [root@rs2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 NAME=eth0 BOOTPROTO=none ONBOOT=yes IPADDR=10.0.0.17 PREFIX=24 GATEWAY=10.0.0.200
4.5、IPVS配置
4.5.1、关闭内核参数,防止IP冲突(两台RS服务器都需要配置)
[root@rs1 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore [root@rs1 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce [root@rs1 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore [root@rs1 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
4.5.2、添加VIP,绑定在lo网卡上(两台RS服务器都需要配置)
[root@rs1 ~]# ifconfig lo:1 10.0.0.100/32 [root@rs1 ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet 10.0.0.100/0 scope global lo:1 valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:bd:9e:c1 brd ff:ff:ff:ff:ff:ff inet 10.0.0.7/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:febd:9ec1/64 scope link valid_lft forever preferred_lft forever
5、验证
[16:58:33 root@internet ~]#curl 10.0.0.100 rs1 10.0.0.7 [16:58:33 root@internet ~]#curl 10.0.0.100 rs2 10.0.0.17
三、思考
1、
2、