LVS+Keepalived實現高可用集羣 二

五.利用Keepalvied實現負載均衡和和高可用性

1.配置在主負載均衡服務器上配置keepalived.conf

#vi /etc/keepalived/keepalived.conf (主調度器)

 

! Configuration File for keepalived

global_defs {
   notification_email {
    
[email protected]
    
[email protected]
    
[email protected]
   }
   notification_email_from
[email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.2.170
    }
}

virtual_server 192.168.2.170 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    persistence_timeout 60
    protocol TCP
  
    real_server 192.168.2.171 80 {
        weight 3            
        TCP_CHECK {
        connect_timeout 10  
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
 } 
    }

    real_server 192.168.2.172 80 {
        weight 3
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80

        }

     }

}

 

在備用調度器上:

#vi /etc/keepalived/keepalived.conf (備用調度器)

 

! Configuration File for keepalived

global_defs {
   notification_email {
    
[email protected]
    
[email protected]
    
[email protected]
   }
   notification_email_from
[email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.2.170
    }
}

virtual_server 192.168.2.170 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    persistence_timeout 60
    protocol TCP
  
    real_server 192.168.2.171 80 {
        weight 3            
        TCP_CHECK {
        connect_timeout 10  
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
 } 
    }

    real_server 192.168.2.172 80 {
        weight 3
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80

        }

     }

}

 

2. BACKUP服務器同上配置,先安裝lvs再按裝keepalived,仍後配置/etc/keepalived/keepalived.conf,只需將紅色標示的部分改一下即可.

3. vi /etc/rc.local
   #/usr/local/sbin/lvs-dr.sh  
lvs-dr.sh這個腳本註釋掉。
   #/usr/local/sbin/lvs-dr.sh stop
停止lvs-dr腳本
   #/etc/init.d/keepalived start  
啓動keepalived 服務,keepalived就能利用keepalived.conf
   
文件,實現負載均衡和高可用.

4.
查看lvs服務是否正常
  

#watch ipvsadm –ln

 

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddressort Scheduler Flags

  -> RemoteAddressort           Forward Weight ActiveConn InActConn

TCP  61.164.122.8:80 wrr persistent 60

  -> 61.164.122.10:80            Route   3      0          0

  -> 61.164.122.9:80             Route   3      0          0

複製代碼

#tail –f /var/log/message  監聽日誌,查看狀態,測試LVS負載均衡及高可用性是否有效。

5
.停Master服務器的keepalived服務,查看BAKCUP服務器是否能正常接管服務。


四.相關參考

1LVS 基礎知識彙總


LVS
的算法介紹            http://www.linuxtone.org/viewthread.php?tid=69
學習LVS的三種轉發模式     http://www.linuxtone.org/viewthread.php?tid=77
LVS
中的IP負載均衡技術     http://www.linuxtone.org/viewthread.php?tid=68

更多的請到http://www.linuxtone.org 負載均衡版查看

Keepalived
相關參考資料。
   
http://www.keepalived.org/documentation.html

原文地址 http://blog.chinaunix.net/u/18630/showart_1889903

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