How do I configure a failover IP address on CentOS 7 ?

Linode Staff

I'm using two CentOS 7 servers and I'd like to configure a failover IP for high availability. I can see that this option is provided in the Remote Access tab but I'm not sure how to handle the failover process internally on the server. How would I automate the process?

1 Reply

KeepaliveD is a great program for configuring IP failover on a Linux server. There is a section in one of the Linode High Availability guides for how to configure KeepaliveD in a cluster:

https://www.linode.com/docs/websites/host-a-website-with-high-availability/#keepalived

If you just want to configure Keepalive between hosts I believe you can use the same general configuration settings with a few tweaks.

  • On the primary Linode obtain an additional floating IPv4 by opening a ticket with the Linode support team.

  • Navigate to the Remote Access tab on the secondary linode and follow the link for IP Failover.

  • Select the newly obtained IPv4 address and save.

  • Install KeepaliveD on both servers:

yum install keepalived

  • Edit the following line in your /etc/sysconfig/keepalived file on all database nodes, adding -P to enable virtual router redundancy protocol:

KEEPALIVED_OPTIONS="-D -P"

  • Create a backup of the keepalived.conf file:

cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.backup

  • Replace the keepalived.conf with the following where 10.10.10.10 is the failover IP and DO SOMETHING is your monitor check:
! Configuration File for keepalived
global_defs {
    notification_email {
    }

    router_id LVS_DBCLUSTER
}

vrrp_script chk_pxc {
    script "DO SOMETHING"
    interval 15
    fall 4
    rise 2
}

vrrp_instance VI_1 {
    state BACKUP
    nopreempt
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1
    track_interface {
        eth0
    }
    track_script {
        chk_pxc
    }
    authentication {
        auth_type PASS
        auth_pass example_password
    }
    unicast_src_ip  192.168.0.1
    unicast_peer {
    192.168.2.3
    192.168.4.5
    }

    virtual_ipaddress {
    10.10.10.10/17
    }
    notify_master "/bin/echo 'now master' > /tmp/keepalived.state"
    notify_backup "/bin/echo 'now backup' > /tmp/keepalived.state"
    notify_fault "/bin/echo 'now fault' > /tmp/keepalived.state"
}
  • Add the following entry to your firewall configuration, within the zones block:

/etc/firewalld/zones/internal.xml

<rule>
    <protocol value="vrrp" />
    <accept />
</rule>
  • Reload the firewall rules:

firewall-cmd --reload

  • Start the keepalived service and enable it to load at boot time:

systemctl start keepalived
systemctl enable keepalived

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct