LVS

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章