• 虚拟机中Lvs配置


    参考:http://zh.linuxvirtualserver.org/node/272
    环境,三台centos 5.2。基于ipvsadm的负载均衡,采用DR方式,负载均衡的服务是web。
    内核版本: linux 2.6.18-92.el5
    Director PC:192.168.2.11
    Virtual ip :192.168.2.10 255.255.255.0
    Real server 1: 192.168.2.12
    Real server 2: 192.168.2.13
    由于linux的内核版本支持安装ipvs了。所以机器均DIRECTOR 上面操作:
    这只需要下载一个ipvsadm-1.24.tar.gz
    # tar zxvf ipvsadm-1.24.tar.gz
    # cd ipvsadm-1.24
    # ls -alh /usr/src/
    [root@localhost network-scripts]# ls -alh /usr/src
    total 36K
    drwxr-xr-x 4 root root 4.0K Dec 11 01:41 .
    drwxr-xr-x 15 root root 4.0K Dec 11 01:42 ..
    drwxr-xr-x 3 root root 4.0K Dec 11 00:20 kernels
    lrwxrwxrwx 1 root root   36 Dec 11 01:41 linux -> /usr/src/kernels/2.6.18-92.el5-i686/

    //查看有没有linux目录,如果没有根据自己的内核版本做个软连接,否则安装 安装heartbeat-2.0.2.tar.gz 是集成安装说吧
    //yum -y install gcc+
    //yum -y install wget
    //yum -y install httpd
    //yum -y install libnet
    //yum -y install ipvaadm
    //yum -y install heartbeat
    除了编辑:vi /etc/sysctl.conf
    echo "1" > /proc/sys/net/ipv4/ip_forward
    [root@localhost network-scripts]# sysctl -p
    net.ipv4.ip_forward = 1

    还需要增加以下几项:
    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

    /etc/sysconfig/network-scripts
    [root@localhost network-scripts]# touch ifcfg-eth0:0
    [root@localhost network-scripts]# vi ifcfg-eth0:0
    //ifconfig eth0:0 192.168.2.10 netmask 255.255.255.255 broadcast 192.168.2.10 up //这样添加到网卡地址重起系统或者重起网络服务后,地址随即丢失
    DEVICE=eth0:0
    ONBOOT=yes
    BOOTPROTO=static
    IPADDR=192.168.2.10
    NETMASK=255.255.255.255
    BROADCAST=192.168.2.255
    [root@localhost network-scripts]# ifconfig eth0:0 192.168.2.10 netmask 255.255.255.255 up
    [root@localhost network-scripts]# route add -host 192.168.2.10 dev eth0:0   
    [root@localhost network-scripts]# service network restart
    [root@localhost network-scripts]# ifconfig
    eth0      Link encap:Ethernet HWaddr 00:0C:29:2A:5E:D9
              inet addr:192.168.2.11 Bcast:192.168.2.255 Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fe2a:5ed9/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
              RX packets:30970 errors:0 dropped:0 overruns:0 frame:0
              TX packets:6686 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:6998626 (6.6 MiB) TX bytes:788838 (770.3 KiB)
              Interrupt:177 Base address:0×1080

    eth0:0    Link encap:Ethernet HWaddr 00:0C:29:2A:5E:D9
              inet addr:192.168.2.10 Bcast:192.168.2.255 Mask:255.255.255.255
              UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
              Interrupt:177 Base address:0×1080

    lo        Link encap:Local Loopback
              inet addr:127.0.0.1 Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING MTU:16436 Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
    [root@localhost network-scripts]# ipvsadm -C
    [root@localhost network-scripts]# ipvsadm -A -t 192.168.2.10:80 -s rr
    [root@localhost network-scripts]# ipvsadm -a -t 192.168.2.10:80 -r 192.168.2.12 -g
    [root@localhost network-scripts]# ipvsadm -a -t 192.168.2.10:80 -r 192.168.2.13 -g
    [root@localhost network-scripts]# ipvsadm -L
    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
    -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
    TCP 192.168.2.10:http rr
    -> 192.168.2.13:http            Route   1      0          0        
    -> 192.168.2.12:http            Route   1      0          0        
    [root@localhost network-scripts]# service iptables stop

    2、realserver服务器
    //ifconfig eth0:0 192.168.1.254 netmask 255.255.255.255 broadcast 192.168.1.254 up 这样配置的关键之一配置/etc/sysctl.conf文件来关闭arp。

    echo "1" > /proc/sys/net/ipv4/ip_forward
    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 "0" > /proc/sys/net/ipv4/conf/lo/rp_filter

    配置ip地址和网关。

    [root@localhost html]# ifconfig
    eth0      Link encap:Ethernet HWaddr 00:0C:29:08:55:6E
              inet addr:192.168.2.12 Bcast:192.168.2.255 Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fe08:556e/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
              RX packets:23169 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2837 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:2329432 (2.2 MiB) TX bytes:319497 (312.0 KiB)
              Interrupt:177 Base address:0×1080

    lo        Link encap:Local Loopback
              inet addr:127.0.0.1 Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING MTU:16436 Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

    lo:0      Link encap:Local Loopback
              inet addr:192.168.2.10 Mask:255.255.255.255
              UP LOOPBACK RUNNING MTU:16436 Metric:1

    另一台一样配置

    [root@localhost html]# ifconfig
    eth0      Link encap:Ethernet HWaddr 00:0C:29:5C:E6:60
              inet addr:192.168.2.13 Bcast:192.168.2.255 Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fe5c:e660/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
              RX packets:24133 errors:0 dropped:0 overruns:0 frame:0
              TX packets:6582 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:2369914 (2.2 MiB) TX bytes:1004032 (980.5 KiB)
              Interrupt:177 Base address:0×1080

    lo        Link encap:Local Loopback
              inet addr:127.0.0.1 Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING MTU:16436 Metric:1
              RX packets:16 errors:0 dropped:0 overruns:0 frame:0
              TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:1344 (1.3 KiB) TX bytes:1344 (1.3 KiB)

    lo:0      Link encap:Local Loopback
              inet addr:192.168.2.10 Mask:255.255.255.255
              UP LOOPBACK RUNNING MTU:16436 Metric:1

    Iptables 先也全部关闭。测试后开启相应端口。
    分别访问:http://192.168.2.11 http://192.168.2.12 http://192.168.2.13 都可以访问
    不断刷新http://192.168.2.10 即可见轮询
    [root@localhost network-scripts]# ipvsadm -L
    IP Virtual Server version 1.2.1 (size=4096)
    Prot LocalAddress:Port Scheduler Flags
    -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
    TCP 192.168.2.10:http rr
    -> 192.168.2.13:http            Route   1      0          31       
    -> 192.168.2.12:http            Route   1      0          27  

    转自:http://cache.baiducontent.com/c?m=9d78d513d9d437a94f9be7690c66c0101b43f7682ba6d60208d48449e3732b31501290ac26520775d1d20b1316ae394b9af22102371456b28cb88a5ddccbc37f73ce7a75671cf75663d50ed9ba5124b137e15dfed81ff0ccf425e2afc5d2af0a178b44040a97818b4d7416de28b04a3eb9e0df0a025e63a7f07b38a2112d6e882337e71aa6fd256f73c3e1dc2a4dc1&p=8b2a970480d011a058ed9760565e90&newp=9b62e71d8ad212a05abd9b7e0d15cc231610db2151d2d212&user=baidu&fm=sc&query=%D4%DA%D0%E9%C4%E2%BB%FA%C0%EF%B0%B2%D7%B0centos+%C4%DC%C5%E4%D6%C3lvs%C2%F0&qid=&p1=1

  • 相关阅读:
    线上一个数组查询遇到的坑
    Java加密解密字符串
    图片和字符串相互转换
    fastweixin 微信服务器开发框架
    从url下载图片--java与python实现方式比较
    jvm 配置,看看
    牛腩新闻公布系统---外键约束下怎样删除记录
    jquery常见面试题
    [Oracle] 位图索引
    hadoop经常使用的压缩算法总结和实验验证
  • 原文地址:https://www.cnblogs.com/pricks/p/3811816.html
Copyright © 2020-2023  润新知