• LVS-DR模式配置搭建


    1.Director配置 
    操作IP 192.168.0.108,配置VIP(创建eno:1并配置)

    cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0

    vi /etc/sysconfig/network-scripts/ifcfg-eth0:0

    TYPE=Ethernet
    PROXY_METHOD=none
    BROWSER_ONLY=no
    BOOTPROTO=static
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_FAILURE_FATAL=no
    IPV6_ADDR_GEN_MODE=stable-privacy
    NAME=eth0:0
    UUID=b6790a67-bcb1-4b5f-87f8-8355ef4ebea0
    DEVICE=eth0:0
    ONBOOT=yes
    IPADDR=192.168.0.108
    NETMASK=255.255.255.0
    

    systemctl restart network

    2.安装ipvsadm并配置

    yum install -y ipvsadm

    ipvsadm -A -t 192.168.0.108 -s rr
    ipvsadm -a -t 192.168.0.108:80 -r 192.168.0.133 -g
    ipvsadm -a -t 192.168.0.108:80 -r 192.168.0.134 -g

    [root@localhost ~]# 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.0.108:80 rr
      -> 192.168.0.133:80             Route   1      0          0
      -> 192.168.0.134:80             Route   1      0          0
    #防火墙设置

    firewall-cmd --permanent --add-port=80/tcp

    forewall-cmd --reload

    3、两台apache配置

    yum install -y httpd
    systemctl enable httpd
    systemctl start httpd
    cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:1

    vi /etc/sysconfig/network-scripts/ifcfg-lo:1

    DEVICE=lo:1
    IPADDR=192.168.0.108
    NETMASK=255.255.255.255
    # If you're having problems with gated making 127.0.0.0/8 a martian,
    # you can change this to something else (255.255.255.255, for example)
    ONBOOT=yes
    NAME=loopback
    ~
    

    systemctl restart network

    firewall-cmd --permanent --add-port=80/tcp

    #关闭VIP ARP响应

    echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
    echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
    echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore

    echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

    服务器添加首页

    echo abctest192.168.0.134 >/var/www/html/index.html

    echo edf is test192.168.0.133 >/var/www/html/index.html

    4.测试
    [root@lvs ~]# curl http://192.168.0.108
    edf is test192.168.0.133
    [root@lvs ~]# curl http://192.168.0.108
    abctest192.168.0.134
    [root@lvs ~]# curl http://192.168.0.108
    edf is test192.168.0.133
    [root@lvs ~]# curl http://192.168.0.108
    edf is test192.168.0.133

    5.脚本实现

    lvs管理器上的脚本

    #!/bin/bash
    #lvs管理器配置,lvs之DR模式
    # vim /usr/local/sbin/lvs_nat.sh
    echo 1 > /proc/sys/net/ipv4/ip_forward
    ipv=/sbin/ipvsadm
    vip=192.168.0.108
    rs1=192.168.0.133
    rs2=192.168.0.34
    #添加vip网卡之eth0:0
    ifconfig eth0:0 down
    ifconfig eth0:0 $vip broadcast $vip netmask 255.255.255.255 up
    route add -host $vip dev eth0:0
    ipvsadm -C
    ipvsadm -A -t 192.168.0.108 -s rr
    ipvsadm -a -t 192.168.0.108:80 -r 192.168.0.133 -g
    ipvsadm -a -t 192.168.0.108:80 -r 192.168.0.134 -g
    #关闭VIP ARP响应
    echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
    echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
    echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
    echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

    两台apache上的配置脚本

    #!/bin/bash
    # vim /usr/local/sbin/lvs_dr_rs.sh
    vip=192.168.0.108
    #添加lo:1
    ifconfig lo:1 $vip broadcast $vip netmask 255.255.255.255 up
    route add -host $vip lo:1
    #关闭VIP ARP响应
    echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
    echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
    echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
    echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
  • 相关阅读:
    工行ATM转账——事务操作
    logstash VS splunk
    centos yum Segmentation fault 问题解决办法
    Disruptor-net 3.3.0
    ISOLAR-A 入门教程
    Arctic教程(2.1)—— AUTOSAR应用程序设计入门(接口)
    Arctic教程(二)—— AUTOSAR应用程序设计入门
    Arctic教程(一)—— 创建AUTOSAR工程
    Arctic 教程
    【转】查看你的AWS服务器已使用流量
  • 原文地址:https://www.cnblogs.com/fungitive/p/9136127.html
Copyright © 2020-2023  润新知