Keepalived


Setp 1 - Download

Download

Keepalived is a routing software written in C. The main goal of this project is to provide simple and robust facilities for loadbalancing and high-availability to Linux system and Linux based infrastructures. Loadbalancing framework relies on well-known and widely used Linux Virtual Server (IPVS) kernel module providing Layer4 loadbalancing. Keepalived implements a set of checkers to dynamically and adaptively maintain and manage loadbalanced server pool according their health. On the other hand high-availability is achieved by VRRP protocol. VRRP is a fundamental brick for router failover. In addition, Keepalived implements a set of hooks to the VRRP finite state machine providing low-level and high-speed protocol interactions. In order to offer fastest network failure detection, Keepalived implements BFD protocol. VRRP state transition can take into account BFD hint to drive fast state transition. Keepalived frameworks can be used independently or all together to provide resilient infrastructures.

Setp 2 - Install

    yum install keepalived

    keepalived.conf

    ! Configuration File for keepalived
    
    global_defs {
       notification_email {
    		acassen@firewall.loc
    		failover@firewall.loc
    		sysadmin@firewall.loc
       }
       notification_email_from Alexandre.Cassen@firewall.loc
       smtp_server 192.168.200.1
       smtp_connect_timeout 30
       router_id LVS_DEVEL
       vrrp_skip_check_adv_addr
       vrrp_strict
       vrrp_garp_interval 0
       vrrp_gna_interval 0
    }
    
    vrrp_instance VI_1 {
        state MASTER
        interface eth0
        virtual_router_id 50
        nopreempt
        priority 100
        advert_int 1
       authentication {
          auth_type PASS
          auth_pass 1111
    }
        virtual_ipaddress {
            192.168.200.11
            192.168.200.12
            192.168.200.13
        }
    }
    
    virtual_server 192.168.200.100 443 {
        delay_loop 6
        lb_algo rr
        lb_kind NAT
        persistence_timeout 50
        protocol TCP
    
        real_server 192.168.201.100 443 {
            weight 1
            SSL_GET {
                url {
                  path /
                  digest ff20ad2481f97b1754ef3e12ecd3a9cc
                }
                url {
                  path /mrtg/
                  digest 9b3a0c85a887a256d6939da88aabd8cd
                }
                connect_timeout 3
                retry 3
                delay_before_retry 3
            }
        }
    }
    virtual_server 10.10.10.2 1358 {
        delay_loop 6
        lb_algo rr
        lb_kind NAT
        persistence_timeout 50
        protocol TCP
    
        sorry_server 192.168.200.200 1358
    
        real_server 192.168.200.2 1358 {
            weight 1
            HTTP_GET {
                url {
                  path /testurl/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334d
                }
                url {
                  path /testurl2/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334d
                }
                url {
                  path /testurl3/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334d
                }
                connect_timeout 3
                retry 3
                delay_before_retry 3
            }
        }
    
        real_server 192.168.200.3 1358 {
            weight 1
            HTTP_GET {
                url {
                  path /testurl/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334c
                }
                url {
                  path /testurl2/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334c
                }
                connect_timeout 3
                retry 3
                delay_before_retry 3
            }
        }
    }
    
    virtual_server 10.10.10.3 1358 {
        delay_loop 3
        lb_algo rr
        lb_kind NAT
        persistence_timeout 50
        protocol TCP
    
        real_server 192.168.200.4 1358 {
            weight 1
            HTTP_GET {
                url {
                  path /testurl/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334d
                }
                url {
                  path /testurl2/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334d
                }
                url {
                  path /testurl3/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334d
                }
                connect_timeout 3
                retry 3
                delay_before_retry 3
            }
        }
    
        real_server 192.168.200.5 1358 {
            weight 1
            HTTP_GET {
                url {
                  path /testurl/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334d
                }
                url {
                  path /testurl2/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334d
                }
                url {
                  path /testurl3/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334d
                }
                connect_timeout 3
                retry 3
                delay_before_retry 3
            }
        }
    }
    
    virtual_server 10.0.0.1 80 {
        delay_loop 6
        lb_algo rr
        lb_kind NAT
        protocol TCP
    
        real_server 192.168.1.20 80 {
            TCP_CHECK {
                    connect_timeout 10
            }
        }
        real_server 192.168.1.21 80 {
            TCP_CHECK {
                    connect_timeout 10
            }
        }
        real_server 192.168.1.22 80 {
            TCP_CHECK {
                    connect_timeout 10
            }
        }
        real_server 192.168.1.23 80 {
            TCP_CHECK {
    			connect_timeout 10
    			connect_port 80
            }
        }
    
    }
    
    
    
    global_defs :
     -. notification_email : 알림메일을 위한 이메일 설정
     -. router_id :
    
    
    vrrp_instance VI_1 : Virtual Router에 대한 설정이다.
     -. 인스턴스의 이름 이 Vl_1 이다.
     -. State : MASTER or BACKUP
     -. Interface : 요청받을 네트워크 인터페이스
     -. virtual_router_id : VRRP 인스턴스가 참여할 가상 라우터의 ID, 같은 그룹이면 이 ID가 같아야 한다.
     -. Priority : 우선순위, 값이 높은게 우선순위가 높음. 마스터가 죽었을때, Backup 서버중에 우선순위가 높은 서버가 먼저 VIP를 받는다.
     -. advert_int : advertisement를 송신할 주기.
     -. Authentication : 라우터 간에 인증을 위해 사용한다. 동일한 라우터들은 같은 설정을 해야 한다.
     -. virtual_ipaddress : Keepalived를 통해 설정할 VIP
     
    
    virtual_server 10.10.10.2 1358
     -. delay_loop 6 : 체크 시간 간격
     -. lb_algo rr : 부하분산 알고리즘(rr : 라운드로빈 / wrr : 가중치 라운드로빈  / sh, rr,wlc)
     -. lb_kind NAT : 부하분산 종류 NAT, DR
     -. persistence_timeout 50 : 세션 유지 시간
     -. protocol TCP : 프로토콜