zoukankan      html  css  js  c++  java
  • 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 se 转到ee小结
    objective c基本知识
    2013_11_14:递归算法(2)—全排列
    2013_11_13:递归算法(1)
    2013_11_13:关于 new 和delelte 的使用
    c++调试问题
    模式匹配BM算法介绍与实现
    一个n数组求和问题
    机试题
    算法题目
  • 原文地址:https://www.cnblogs.com/networking/p/6084715.html
Copyright © 2011-2022 走看看