mostly unknown keepalived feature

There are lot of introduction to keepalived. Like Setting up a Linux cluster with Keepalived: Basic configuration | Enable Sysadmin (redhat.com) or Keepalived and high availability: Advanced topics | Enable Sysadmin (redhat.com)

But I recently learned that keepalived has a cool feature that makes writing keepalived much easier (Thanks Spindy). Almost all documentation found on the net shows you that you need two different configuration files. But this is not the case. There is an extension that allows you to rollout the same configuration for all nodes.

When you compare this example from the first links. They use this two configurations:

server1# cat /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
        state MASTER
        interface eth0
        virtual_router_id 51
        priority 255
        advert_int 1
        authentication {
              auth_type PASS
              auth_pass 12345
        }
        virtual_ipaddress {
              192.168.122.200/24
        }
}
server2# cat /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
        state BACKUP
        interface eth0
        virtual_router_id 51
        priority 254
        advert_int 1
        authentication {
              auth_type PASS
              auth_pass 12345
        }
        virtual_ipaddress {
              192.168.122.200/24
        }
}

When you look at it its almost the same file – only 2 lines are different, state and priority. Here comes the @format into play. You can rollout this file on both side and it will work the same way as above:

# cat /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
        @server1 state MASTER
        @server2 state BACKUP
        interface eth0
        virtual_router_id 51
        @server1 priority 255
        @server2 priority 254
        advert_int 1
        authentication {
              auth_type PASS
              auth_pass 12345
        }
        virtual_ipaddress {
              192.168.122.200/24
        }
}

So you can configure lines that are only valid for certain hosts by adding a @HOSTNAME in front. More possibilities are explained in the man page keepalived.conf(5) in the section “Conditional configuration and configuration id”

This entry was posted in Enterprise Linux, Fedora, Linux, Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *