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