• linux LVS DR模式配置


    拓扑图:

    测试环境:CentOS 6.5 X86 64位

    配置步骤:

    1、  安装测试环境

    [root@UCS-1 ~]# yum -y install httpd

    [root@UCS-1 ~]# chkconfig --add httpd

    [root@UCS-1 ~]# chkconfig --level 35 httpd on

    [root@UCS-1 ~]# cd /var/www/html/

    [root@UCS-1 html]# touch index.html

    [root@UCS-1 html]# vi index.html

    <h1>服务器IP地址:192.168.5.11</h1>

    [root@UCS-1 html]# chown -R apache:apache index.html

    [root@UCS-1 html]# /etc/init.d/httpd start

    [root@UCS-2 ~]# yum -y install httpd

    [root@UCS-2 ~]# chkconfig --add httpd

    [root@UCS-2 ~]# chkconfig --level 35 httpd on

    [root@UCS-2 ~]# vi /etc/httpd/conf/httpd.conf

    [root@UCS-2 ~]# cd /var/www/html/

    [root@UCS-2 html]# touch index.html

    [root@UCS-2 html]# vi index.html

    <h1>服务器IP地址:192.168.5.12</h1>

    [root@UCS-2 html]# chown -R apache:apache index.html

    [root@UCS-2 html]# /etc/init.d/httpd start

    2、  安装LVS软件

    [root@UCS-3 data]# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz  

    [root@UCS-3 data]# tar zxvf ipvsadm-1.24.tar.gz

    [root@UCS-3 data]# cd ipvsadm-1.24

    [root@UCS-3 ipvsadm-1.24]# ln -s /usr/src/kernels/2.6.32-431.el6.x86_64/ /usr/src/linux

    [root@UCS-3 ipvsadm-1.24]# make all

    [root@UCS-3 ipvsadm-1.24]# make install

    [root@UCS-3 ipvsadm-1.24]# ipvsadm --version

    ipvsadm v1.24 2005/12/10 (compiled with getopt_long and IPVS v1.2.1)

    [root@UCS-3 ipvsadm-1.24]#

    3、  配置网卡

    [root@UCS-3 data]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0

    [root@UCS-3 data]# vi /etc/sysconfig/network-scripts/ifcfg-eth0:0

    DEVICE=eth0:0

    TYPE=Ethernet

    ONBOOT=yes

    NM_CONTROLLED=yes

    BOOTPROTO=static

    IPADDR=192.168.5.10

    NETMASK=255.255.255.255

    打开网卡转发功能

    [root@UCS-3 data]# vi /etc/sysctl.conf

    net.ipv4.ip_forward =1

    [root@UCS-3 data]# sysctl –p

    [root@UCS-3 data]# route add -host 192.168.5.10 dev eth0:0

    [root@UCS-1 ~]# cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:0

    [root@UCS-1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-lo:0

    DEVICE=lo:0

    IPADDR=192.168.5.10

    NETMASK=255.255.255.255

    ONBOOT=yes

    关闭ARP广播响应

    #!/bin/bash
    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

    [root@UCS-2 ~]# cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:0

    [root@UCS-2 ~]# vi /etc/sysconfig/network-scripts/ifcfg-lo:0

    DEVICE=lo:0

    IPADDR=192.168.5.10

    NETMASK=255.255.255.255

    ONBOOT=yes

    ~ net.ipv4.conf.lo.arp_ignore = 1

    net.ipv4.conf.lo.arp_announce = 2

    net.ipv4.conf.all.arp_ignore = 1

    net.ipv4.conf.all.arp_announce = 2                                                                                                                                            

    ~[root@UCS-2 ~]# sysctl –p

    [root@UCS-2 ~]# /etc/init.d/network restart

    [root@UCS-2 ~]# route add -host 192.168.5.10 dev lo:0

    [root@UCS-3 ~]# ipvsadm –C

    [root@UCS-3 ~]# ipvsadm -At 192.168.5.10:80 -s rr

    [root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.11:80 -g

    [root@UCS-3 ~]# ipvsadm -at 192.168.5.10:80 -r 192.168.5.12:80 –g

    [root@UCS-3 ~]# ipvsadm -L -n

    IP Virtual Server version 1.2.1 (size=4096)

    Prot LocalAddress:Port Scheduler Flags

      -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

    TCP  192.168.5.10:80 rr

      -> 192.168.5.12:80              Route   1      0          3        

      -> 192.168.5.11:80              Route   1      0          2        

    [root@UCS-3 ~]#

    [root@UCS-3 ~]# ipvsadm -L -c

    IPVS connection entries

    pro expire state       source             virtual            destination

    TCP 01:29  FIN_WAIT    192.168.101.190:51228 192.168.5.10:http  192.168.5.11:http

    TCP 01:35  FIN_WAIT    192.168.101.190:51231 192.168.5.10:http  192.168.5.12:http

    TCP 01:29  FIN_WAIT    192.168.101.190:51227 192.168.5.10:http  192.168.5.12:http

    4、  测试如下

  • 相关阅读:
    java数组转list
    【转载】tomcat端口被占用问题完美解决方案!
    基于apicloud的英语课堂app设计与实现
    springboot整合mybatis(SSM开发环境搭建)
    POI Excel读取图片对应位置和顺序生成图片方法
    E: Sub-process /usr/bin/dpkg returned an error code (1) 出错解决方案
    Ubuntu 虚拟机无法关机的解决方案
    Celery 提示[ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 61] Connection refused.
    Python @classmethod&@staticmethod 区别
    SyntaxError: non-default argument follows default argument
  • 原文地址:https://www.cnblogs.com/networking/p/6084715.html
Copyright © 2020-2023  润新知