zoukankan      html  css  js  c++  java
  • lvs配置之DR模式

    环境

    系统 IP
    redhat 8 DR  192.168.100.131 vip:192.168.100.100
    redhat 8 RS1  192.168.100.132 vip:192.168.100.100
    redhat 8 RS2  192.168.100.133 vip:192.168.100.100

    准备工作

    //安装ipvsadm
    [root@DR ~]# dnf -y install ipvsadm
    [root@RS1 ~]# dnf -y install ipvsadm
    [root@RS2 ~]# dnf -y install ipvsadm
    
    //RS1.RS2安装httpd
    #dnf -y install httpd
    
    //RS1.RS2.DR关闭防火墙和selinux
    #systemctl stop firewalld
    #setenforce 0
    
    //RS1.RS2设置开机自启并立即启动httpd
    #systemctl enable --now httpd
    
    //创建测试页(如果想直观查看测试结果可以做这一步,否则可以跳过)
    [root@RS1 ~]# echo "RS1" > /var/www/html/index.html
    [root@RS2 ~]# echo "RS2" > /var/www/html/index.html
    [root@DR ~]# ip addr add 192.168.100.100/32 dev ens160
    //这条两台RS机器都做
    yum -y install httpd net-tools

     

    RS服务器配置

    //RS1
    [root@RS1 ~]# vim /etc/sysctl.conf
    // 在最后面插入如下两行
    net.ipv4.conf.all.arp_ignore = 1     // 将对应网卡设置为只回应目标IP为自身接口地址的ARP请求
    net.ipv4.conf.all.arp_announce = 2    // 将ARP请求的源IP设置为eth0上的IP,也就是RIP
    
    [root@RS1 ~]# sysctl -p
    net.ipv4.conf.all.arp_ignore = 1
    net.ipv4.conf.all.arp_announce = 2
    
    //RS2
    [root@RS2 ~]# vim /etc/sysctl.conf
    // 在最后面插入如下两行
    net.ipv4.conf.all.arp_ignore = 1
    net.ipv4.conf.all.arp_announce = 2
    
    [root@RS2 ~]# sysctl -p
    net.ipv4.conf.all.arp_ignore = 1
    net.ipv4.conf.all.arp_announce = 2

    配置VIP

    一定要先设置好内核参数在配置VIP,如果先配置VIP,VIP配置好后会立即通告给所有人,而修改内核参数就是为了不通告

    //Rs1
    [root@RS1 ~]# ip addr add 192.168.100.100/32 dev lo
    //Rs2
    [root@RS1 ~]# ip addr add 192.168.100.100/32 dev lo

    配置路由信息

    //RS1
    [root@RS1 ~]#  route add -host 192.168.100.100/32 dev lo
    [root@RS1 ~]# echo "192.168.100.100/32 via 0.0.0.0 dev lo" > /etc/sysconfig/network-scripts/route-lo
    [root@RS1 ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         192.168.100.254 0.0.0.0         UG    100    0        0 ens160
    192.168.100.0   0.0.0.0         255.255.255.0   U     100    0        0 ens160
    192.168.100.100 0.0.0.0         255.255.255.255 UH    0      0        0 lo
    
    //RS2
    [root@RS2 ~]# route add -host 192.168.100.100/32 dev lo
    [root@RS2 ~]# echo '192.168.100.100/32 via 0.0.0.0 dev lo' > /etc/sysconfig/network-scripts/route-lo
    [root@RS2 ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         192.168.100.254 0.0.0.0         UG    100    0        0 ens160
    192.168.100.0   0.0.0.0         255.255.255.0   U     100    0        0 ens160
    192.168.100.100 0.0.0.0         255.255.255.255 UH    0      0        0 lo

    添加并保存规则

    //DR
    [root@DR network-scripts]# ipvsadm -A -t 192.168.100.100:80 -s wrr
    [root@DR network-scripts]#  ipvsadm -a -t 192.168.100.100:80 -r 192.168.100.132 -g
    [root@DR network-scripts]#  ipvsadm -a -t 192.168.100.100:80 -r 192.168.100.133 -g
    
    [root@DR network-scripts]# ipvsadm -Ln
    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
      -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
    TCP  192.168.100.100:80 wrr
      -> 192.168.100.132:80           Route   1      0          0         
      -> 192.168.100.133:80           Route   1      0          0 
    
    [root@DR network-scripts]# ipvsadm -S > /etc/sysconfig/ipvsadm
    [root@DR network-scripts]# systemctl enable --now ipvsadm

    访问测试

    [root@DR network-scripts]# ipvsadm -Ln
    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
      -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
    TCP  192.168.100.100:80 wrr
      -> 192.168.100.132:80           Route   1      4          1         
      -> 192.168.100.133:80           Route   1      1          1  
  • 相关阅读:
    XMEGA IO口外部中断操作
    博客开通了
    cocos2d-x CCParticleSystem粒子系统
    获得web api 返回的Dataset 绑定到网格控件上
    DbHelperSQL—— 动软生成DbHelperSQL类
    Silverlight 调用 web api
    await运算符只能用于异步方法中。请考虑用async修饰符标记此方法,并将其返回类型更改为Task
    js如何获取url的参数
    cvbfbd
    【转】selenium及webdriver的原理
  • 原文地址:https://www.cnblogs.com/lichouluoyu/p/14742534.html
Copyright © 2011-2022 走看看