首页 > 其他 > 详细

LVS

时间:2016-02-08 01:10:15      阅读:240      评论:0      收藏:0      [点我收藏+]

office documentation:

http://www.linuxvirtualserver.org/VS-DRouting.html


http://wenku.baidu.com/view/f352412e2af90242a895e565.html

http://wenku.baidu.com/view/30f7115c3b3567ec102d8abb.html?re=view

http://wenku.baidu.com/view/f13a142c453610661ed9f41e.html

http://wenku.baidu.com/view/b9c7cd52f01dc281e53af027.html


LVS DR(direct routing):性能最好


serverip(eth0)vip
director server192.168.1.105eth0:0 192.168.1.111
real server 1192.168.1.102lo:0 192.168.1.111
real server 2192.168.1.104lo:0 192.168.1.111


  1. install lvs on director server

    wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz

    tar xzvf ipvsadm-1.26.tar.gz

    cd ipvsadm-1.26

    ln -s /usr/src/kernels/$(uname -r) /usr/src/linux #注意内核版本号,编译时lvs通过linux软连接找到相应的头文件和库文件

    make

    make install

  2. check lvs

    ipvsadm

    lsmod | grep -i ip_vs #you cannot check the ipvsadm by "ps -ef | grep ipvsadm"

  3. change the kernel parameters on network in /etc/sysctl.conf

    net.ipv4.ip_forward = 0

    net.ipv4.conf.all.send_redirects = 1

    net.ipv4.conf.eth0.send_redirects = 1

    net.ipv4.conf.default.send_redirects = 1

    sysctl -p   #生效

    sysctl -a   #检测参数值

  4. 配置VIP和路由

    ifconfig eth0:0 192.168.1.111 broadcast 192.168.1.111 netmask 255.255.255.255 up

    route add -host 192.168.1.111 dev eth0:0

  5. 配置lvs(通过ipvsadm配置,就像netfilter是通过iptables配置的一样)

    ipvsadm -C

    ipvsadm -A -t 192.168.1.111:80 -s rr #add a vitual ip and port,and use round-robin

    ipvsadm -a -t 192.168.1.111:80 -r 192.168.1.102:80 -g

    ipvsadm -a -t 192.168.1.111:80 -r 192.168.1.104:80 -g

  6. 启动lvs

    ipvsadm

    ipvsadm -ln  #check lvs状态

    ====================================================================================

    work on real server 1 and 2, the same setup on both 1 and 2

  7. change kernel parmater on network in /etc/sysctl.conf

    net.ipv4.ip_forward = 0

    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


    sysctl -p  #生效

    sysctl -a  #confirm

  8. 配置VIP&路由

    ifconfig lo:0 192.168.1.111 broadcast 192.168.1.111 netmask 255.255.255.255 up

    route add -host 192.168.1.111 dev lo:0

  9. start web server

    nginx

    =====================================================================================

    work on client end to test

    open 10 tabs to access http://192.168.1.111

    =====================================================================================

    work on director server

  10. stop lvs

    ipvsadm -C

    ifconfig eth0:0 down

  11. caution: in prd env, use script to configure LVS‘s start and stop

LVS

原文:http://dannyswallow.blog.51cto.com/5062777/1741377

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!