2013年5月6日 星期一

簡單的 linux H.A 架構 keepalived (linux vrrp) Part II

透過 keepalived 達成簡單的 linux H.A 架構. (linux vrrp)
http://www.keepalived.org/
延續這個主題.
http://xrcd2.blogspot.tw/2013/04/linux-ha-keepalived-linux-vrrp.html
加入切換條件, 如 track_script































Master config 如下

! Configuration File for keepalived
vrrp_script check_sh {
    script "/etc/keepalived/chk_ftp.sh"
    interval 2                       # check every 2 seconds
    weight -30                       # default prio: -30
    fall 2                           # require 2 failures
    rise 2                           # require 2 successes
}
vrrp_script chk_httpd {
            script "killall -0 httpd"      
            interval 2                    
            weight -30                      
            fall 2                         
            rise 2                         
}
vrrp_script chk_8080_port {
 script "</dev/tcp/127.0.0.1/8080"
 interval 1
 weight -30
 fall   2    
 rise   2    
}
global_defs {
   notification_email {
     xrcd2@xrcd2.com.tw
   }
   notification_email_from keepalived@xrcd2.com.tw
   smtp_server 192.168.1.100
   smtp_connect_timeout 30
   router_id NodeA
}
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 1
    priority 100
    advert_int 1
    smtp_alert
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.3
    }
    track_script {
     check_sh
     chk_httpd
     chk_8080_port

    }
    track_interface{
     eth0   
    }

}

DIY 檢查的 shell
======================
cat /etc/keepalived/chk_ftp.sh
#!/bin/bash
chktcp21=`nmap 127.0.0.1 | grep '21/tcp' | wc -l`
if [ $chktcp21 = 1 ]
then
 #echo "============="
 #echo " FTPD Is Up "
 #echo "============="
 exit 0
else
 #echo "============="
 #echo " FTPD Is Down "
 #echo "============="
 exit 1
fi
=====================

Backup config 如下

! Configuration File for keepalived
vrrp_script check_sh {
    script "/etc/keepalived/chk_ftp.sh"
    interval 2                      # check every 2 seconds
    weight -30                      # default prio: -30
    fall 2                          # require 2 failures
    rise 2                          # require 2 successes
}
vrrp_script chk_httpd {
            script "killall -0 httpd"       
            interval 2                     
            weight -30                     
            fall 2                          
            rise 2                          
}
vrrp_script chk_8080_port {
 script "</dev/tcp/127.0.0.1/8080"
 interval 1
 weight -30
 fall   2   
 rise   2   
}
global_defs {
   notification_email {
     xrcd2@xrcd2.com.tw
   }
   notification_email_from keepalived@xrcd2.com.tw
   smtp_server 192.168.1.100
   smtp_connect_timeout 30
   router_id NodeB
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 1
    priority 90
    advert_int 1
    smtp_alert
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.3
    }
    track_script {
     check_sh
     chk_httpd
     chk_8080_port

    }
    track_interface{
     eth0   
    }

}

運作通知!


切換通知!



沒有留言:

張貼留言