用Linux架設SLB(負載平衡)設備

參考資料:
http://kb.hyve.com/wiki/Setup%20a%20Loopback%20adaptor%20in%20Windows%202008%20for%20loadbalancer%20VIP

網路架構 (todo):

 

SLB主機安裝:
1. 灌好CentOS 6.5 OS
2. yum -y install ipvsadm keepalived
3. 編輯/etc/keepalived/keepalived.conf,範例如下

! Configuration File for keepalived

global_defs {
   notification_email {
     your-email@email.com
   }
   notification_email_from email-sender@email.com
   smtp_server 10.10.10.1
   smtp_connect_timeout 30
   router_id LVS_TF4F
}

#vrrp_instance VI_1 {
#    state MASTER
#    interface eth0
#    virtual_router_id 51
#    priority 100
#    advert_int 1
#    authentication {
#        auth_type PASS
#        auth_pass yourpassword
#    }
#    virtual_ipaddress {
#       127.0.0.5
#    }
#}

virtual_server 10.176.20.152 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 1200
    protocol TCP
    virtualhost slb.idc.local
    real_server 10.176.20.131 80 {
        weight 1
        HTTP_GET {
            url {
              path /iisstart.htm
              digest dfbd1ee66a4e792349591b88660c0956
            }
        }
    }
    real_server 10.176.20.132 80 {
        weight 1
        HTTP_GET {
            url {
              path /iisstart.htm
              digest dfbd1ee66a4e792349591b88660c0956
            }
        }

    }
    real_server 10.176.20.153 80 {
        weight 0
        HTTP_GET {
            url {
              path /slb.php
              digest 509f04652b5e1b2d2b9e6bc121a87e50
            }
        }
    }
}

4.啟動keepalived

  chkconfig keepalived on
  service keepalived start

5.觀看目前SLB連線狀態

 ipvsadm -Ln

 

Real Server安裝(CentOS 5/6 Linux)

編輯/etc/sysctl.conf加入下面兩行,設定後記得使用sysctl -p生效

net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

新增/etc/sysconfig/ifcfg-lo:0檔案並加入下面內容

DEVICE=lo:0
IPADDR=10.176.20.152
NETMASK=255.255.255.255
ONBOOT=yes

啟動loopback網卡

ifup lo:0

 

Real Server安裝(Windows 2008 R2) (todo)
1.新增Loopback Interface
1

 

 

 

 

 

 

 

 

 

 

 

 

 

2 3 4 5 6 7

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

最後請執行下面指令

netsh interface ipv4 set interface "區域連線" weakhostreceive=enabled
netsh interface ipv4 set interface "Loopback" weakhostreceive=enabled
netsh interface ipv4 set interface "Loopback" weakhostsend=enabled

 

 

 

 

 

 

 

 

 

Facebook Comments Box

Leave a Reply