美文网首页
LVS的跨网络DR实现

LVS的跨网络DR实现

作者: 沐熙一叶_Leaf | 来源:发表于2021-07-12 20:49 被阅读0次

    1、LVS的跨网络DR实现


    # 准备环境
    环境:五台主机
    一台:客户端 eth0:仅主机 192.168.0.6/24 GW:192.168.0.200
    一台:ROUTER
    eth0 :NAT 10.0.0.200/24
    eth1: 仅主机 192.168.0.200/24
    启用 IP_FORWARD
    一台:LVS
    eth0:NAT:DIP:10.0.0.8/24 GW:10.0.0.200
    两台RS:
    RS1:eth0:NAT:10.0.0.7/24 GW:10.0.0.200          lo:VIP  10.0.0.100/32
    RS2:eth0:NAT:10.0.0.17/24 GW:10.0.0.200         lo:VIP  10.0.0.100/32
    

    1.1 LVS的网络配置

    #所有主机禁用iptables和SELinux
    
    #internet主机环境
    [root@internet ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
    DEVICE=eth0
    NAME=eth0
    BOOTPROTO=static
    IPADDR=192.168.0.6
    PREFIX=24
    GATEWAY=192.168.0.200
    ONBOOT=yes
    DNS1=202.101.172.35
    
    [root@internet ~]# hostname 
    internet
    [root@internet ~]# hostname -I
    10.0.0.6 
    [root@internet ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
    0.0.0.0         192.168.0.200   0.0.0.0         UG    0      0        0 eth0
    
    [root@internet ~]# ping 10.0.0.7 -c1
    PING 10.0.0.7 (10.0.0.7) 56(84) bytes of data.
    64 bytes from 10.0.0.7: icmp_seq=1 ttl=63 time=2.10 ms
    
    [root@internet ~]# ping 10.0.0.17 -c1
    PING 10.0.0.17 (10.0.0.17) 56(84) bytes of data.
    64 bytes from 10.0.0.17: icmp_seq=1 ttl=63 time=0.559 ms
    
    
    #路由器的网络配置,添加双网卡
    [root@router ~]# echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf 
    [root@router ~]# sysctl -p
    net.ipv4.ip_forward = 1
    
    [root@router network-scripts]#pwd
    /etc/sysconfig/network-scripts
    [root@router network-scripts]#cat ifcfg-ens37
    DEVICE=ens33
    NAME=ens33
    BOOTPROTO=static
    IPADDR=10.0.0.200
    GATEWAY=10.0.0.1
    PREFIX=24
    ONBOOT=yes
    DNS1=202.101.172.35
    [root@router network-scripts]#cat ifcfg-ens37
    DEVICE=ens37
    NAME=ens37
    BOOTPROTO=static
    IPADDR=192.168.0.200
    GATEWAY=192.168.0.1
    PREFIX=24
    ONBOOT=yes
    DNS1=202.101.172.35
    
    #RS1的网络配置
    [root@rs1 ~]# hostname
    rs1.yezeng.org
    [root@rs1 ~]# hostname -I
    10.0.0.7 
    [root@rs1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 
    DEVICE=ens33
    NAME=ens33
    BOOTPROTO=static
    IPADDR=10.0.0.7
    PREFIX=24
    GATEWAY=10.0.0.200
    ONBOOT=yes
    DNS1=202.101.172.35
    [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 ens33
    10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 ens33
    [root@rs1 ~]# yum -y install httpd
    [root@rs1 ~]# systemctl enable --now httpd.service 
    Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
    
    [root@rs1 ~]# ping 192.168.0.6 -c1
    PING 192.168.0.6 (192.168.0.6) 56(84) bytes of data.
    64 bytes from 192.168.0.6: icmp_seq=1 ttl=63 time=0.828 ms
    
    [root@rs1 ~]# curl 10.0.0.7
    10.0.0.7 
    
    
    #RS2 的网络配置
    [root@rs2 ~]# hostname
    rs2.yezeng.org
    [root@rs2 ~]# hostname -I
    10.0.0.17 
    [root@rs2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 
    DEVICE=ens33
    NAME=ens33
    BOOTPROTO=static
    IPADDR=10.0.0.17
    PREFIX=24
    GATEWAY=10.0.0.200
    ONBOOT=yes
    DNS1=202.101.172.35
    [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 ens33
    10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 ens33
    
    [root@rs2 ~]# yum -y install httpd
    [root@rs2 ~]# systemctl enable --now httpd
    Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
    [root@rs2 ~]# hostname -I > /var/www/html/index.html
    [root@rs2 ~]# curl 10.0.0.17
    10.0.0.17 
    
    [root@rs2 ~]# ping 192.168.0.6 -c1
    PING 192.168.0.6 (192.168.0.6) 56(84) bytes of data.
    64 bytes from 192.168.0.6: icmp_seq=1 ttl=63 time=1.10 ms
    
    #LVS 的网络配置
    [root@lvs ~]# hostname
    lvs.yezeng.org
    [root@lvs ~]# hostname -I
    10.0.0.8 
    
    [root@lvs ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 
    DEVICE=ens33
    NAME=ens33
    BOOTPROTO=static
    IPADDR=10.0.0.8
    PREFIX=24
    GATEWAY=10.0.0.200
    ONBOOT=yesi
    DNS1=202.101.172.35
    [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 ens33
    10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 ens33
    [root@lvs ~]# ping 192.168.0.6 -c1
    PING 192.168.0.6 (192.168.0.6) 56(84) bytes of data.
    64 bytes from 192.168.0.6: icmp_seq=1 ttl=63 time=0.511 ms
    
    

    1.2 后端RS的IPVS配置

    #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
    [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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:0c:29:7f:49:eb brd ff:ff:ff:ff:ff:ff
        inet 10.0.0.7/24 brd 10.0.0.255 scope global noprefixroute ens33
           valid_lft forever preferred_lft forever
        inet6 fe80::20c:29ff:fe7f:49eb/64 scope link 
           valid_lft forever preferred_lft forever
    
    #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
    [root@rs2 ~]# 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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:0c:29:15:d6:29 brd ff:ff:ff:ff:ff:ff
        inet 10.0.0.17/24 brd 10.0.0.255 scope global noprefixroute ens33
           valid_lft forever preferred_lft forever
        inet6 fe80::20c:29ff:fe15:d629/64 scope link 
           valid_lft forever preferred_lft forever
    
    

    1.3 LVS 主机的配置

    #在LVS上添加VIP
    [root@lvs ~]# ifconfig lo:1 10.0.0.100/32
    [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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:0c:29:6c:c2:ce brd ff:ff:ff:ff:ff:ff
        inet 10.0.0.8/24 brd 10.0.0.255 scope global noprefixroute ens33
           valid_lft forever preferred_lft forever
        inet6 fe80::20c:29ff:fe6c:c2ce/64 scope link 
           valid_lft forever preferred_lft forever
    
    
    [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 -g
    [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
    
    

    1.4 测试访问

    [root@internet ~]# curl 10.0.0.100
    10.0.0.17 
    [root@internet ~]# curl 10.0.0.100
    10.0.0.7 
    
    [root@rs1 ~]# tail -f /var/log/httpd/access_log -n0
    192.168.0.6 - - [10/Jul/2021:07:46:19 +0800] "GET / HTTP/1.1" 200 10 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
    

    相关文章

      网友评论

          本文标题:LVS的跨网络DR实现

          本文链接:https://www.haomeiwen.com/subject/ttydpltx.html