一、网络配置

1.1 客户端

#客户端配置
[root@client ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=192.168.50.6
GATEWAY=10.0.0.200
PREFIX=24
ONBOOT=yes
[root@client ~]#route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.200 0.0.0.0 UG 100 0 0 eth0
10.0.0.200 0.0.0.0 255.255.255.255 UH 100 0 0 eth0
192.168.50.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0

1.2 路由器配置

#启用ip_forward
[root@router ~]#echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
[root@router ~]#sysctl -p [root@router ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=10.0.0.200
PREFIX=24
ONBOOT=yes
[root@router ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
NAME=eth1
BOOTPROTO=static
IPADDR=192.168.50.200
PREFIX=24
ONBOOT=yes

1.3后端服务器RS

#RS1
[root@rs1 ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=10.0.0.7
PREFIX=24
GATEWAY=10.0.0.200
ONBOOT=yes
[root@rs1 ~]#route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.200 0.0.0.0 UG 100 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@rs1 ~]#yum -y install httpd
[root@rs1 ~]#systemctl enable --now httpd
[root@rs1 ~]#hostname -I > /var/www/html/index.html
[root@rs1 ~]#curl 10.0.0.7
10.0.0.7 #RS2
[root@rs2 ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
NAME=eth0
BOOTPROTO=static
IPADDR=10.0.0.17
PREFIX=24
GATEWAY=10.0.0.200
ONBOOT=yes
[root@rs2 ~]#route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.200 0.0.0.0 UG 100 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@rs2 ~]#yum -y install httpd
[root@rs2 ~]#systemctl enable --now httpd
[root@rs2 ~]#hostname -I > /var/www/html/index.html
[root@rs2 ~]#curl 10.0.0.17
10.0.0.17

1.4LVS

[root@lvs ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=10.0.0.8
PREFIX=24
GATEWAY=10.0.0.200
ONBOOT=yes
[root@lvs ~]#route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.200 0.0.0.0 UG 100 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0

1.5 网络测试

#确保能够ping通
[root@client ~]#ping 10.0.0.7
[root@client ~]#ping 10.0.0.17
[root@client ~]#ping 10.0.0.8

二、配置LVS

2.1 后端RS的IPVS配置

# LVS的IPVS配置
[root@lvs ~]#ifconfig lo:1 170.16.0.100/32 #RS1的IPVS配置
[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
[root@rs1 ~]#ifconfig lo:1 10.0.0.100/32 #RS2的IPVS配置
[root@rs2 ~]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@rs2 ~]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@rs2 ~]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@rs2 ~]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@rs2 ~]#ifconfig lo:1 10.0.0.100/32

2.2 实现LVS 规则

[root@lvs ~]#yum -y install ipvsadm
[root@lvs ~]#ipvsadm -A -t 10.0.0.100:80 -s rr
[root@lvs ~]#ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.7:80 -g
[root@lvs ~]#ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.17:80 -
[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

2.3 测试访问

[root@client ~]#while :;do curl 10.0.0.100;sleep 1;done
10.0.0.7
10.0.0.17
10.0.0.7
10.0.0.17
10.0.0.7
....

最新文章

  1. bzoj1202--带权并查集+前缀和
  2. WCF框架处理流程初探
  3. TF-IDF算法
  4. Yii2修改默认布局
  5. PL/SQL Developer自动补全SQL技巧
  6. Exam 70-462 Administering Microsoft SQL Server 2012 Databases 复习帖
  7. hadoop错误java.io.IOException Failed to replace a bad datanode on the existing pipeline due to no more good datanodes being available to try
  8. Android 打造自己的个性化应用(一):应用程序换肤主流方式的分析与概述
  9. C++STL笔记
  10. Dora.Interception, 一个为.NET Core度身打造的AOP框架[3]:Interceptor的注册
  11. jupyter notebook安装、登录
  12. Hadoop多租户架构配置
  13. SpringBoot入门笔记(四)、通常Mybatis项目目录结构
  14. 多线程出现 java.lang.NumberFormatException: multiple points
  15. Spring Boot Controller相应JSP页面 错误whitelabel error page
  16. Pc端css初始化
  17. Qt QML referenceexamples attached Demo hacking
  18. 剑指offer 08跳台阶
  19. Alpha阶段贡献分配规则
  20. 美团实习Java岗面经,已拿offer

热门文章

  1. Laravel Redis分布式锁实现源码分析
  2. elasticsearch之警惕inner hits的性能问题
  3. python @property用法(转载)
  4. Python_类型转换
  5. Linux weblogic
  6. 在CentOS7 安装 jq
  7. Oracle - 以 INSERT SQL语句形式导出结果集
  8. next中layout
  9. rockchip-rk3399 RGA的使用
  10. 使用.NET 6开发TodoList应用(25)——实现RefreshToken