Thursday, October 14, 2021

How to Set Weight 0 on real-server Keepalived

How to Set Weight 0 on real-server Keepalived


New keepalived version has a limitation of set weight 0 on real-server. As per most of the forums, there is no proper solution for this. (https://githubmemory.com/repo/acassen/keepalived/issues/1757)
Most people use this option to offload the traffic for real-server. 

In this blog I am going to show workaround for this limitation.

I am having keepalived version v2.1.5




















Configuration Steps

  • Create a folder call "status" inside the "/etc/keepalived" folder.
  • Create two files "active" and "passive"
  • Content inside the active file should be "0". Content inside passive file should be non-zero.











  • Apply the keepalived configurations as follow.
    • We have to define two track file. One for active. Other one for passive.  
track_file _active {
file /etc/keepalived/status/active
weight 1
}

track_file _passive {
        file /etc/keepalived/status/passive
        weight 0
}

    •  Include this track file to real_server

real_server 5.79.56.40 9006 {
weight 1

TCP_CHECK {
        connect_port 9006
        connect_timeout 3
        retry 3
        delay_before_retry 2
        }
FILE_CHECK {
track_file _active
#track_file _passive
}
}

Full configuration 

global_defs {
router_id TestQS
}

vrrp_instance Float_QS_Test {
    state BACKUP
    interface enp0s3
    virtual_router_id 66
    priority 101        # 101 on master, 100 on backup
    advert_int 1
    nopreempt
    smtp_alert

    virtual_ipaddress {
        192.168.8.201/24        #data.directfn.com
    }
}

track_file _active {
file /etc/keepalived/status/active
weight 1
}

track_file _passive {
        file /etc/keepalived/status/passive
        weight 0
}

virtual_server 192.168.8.201 9006 {
        lvs_sched rr
        lvs_method DR
        protocol TCP
inhibit_on_failure

        real_server 5.79.56.40 9006 {
weight 1

        TCP_CHECK {
                connect_port 9006
                connect_timeout 3
                retry 3
                delay_before_retry 2
                }
FILE_CHECK {
track_file _active
#track_file _passive
}
        }
        real_server 78.136.25.234 9006 {
weight 1

        TCP_CHECK {
                connect_port 9006
                connect_timeout 3
                retry 3
                delay_before_retry 2
                }

        FILE_CHECK {
                track_file _active
                #track_file _passive
                }
        }
}



No comments:

Post a Comment