Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am a newbie to CentOS/Linux/HAProxy/Keepalived, so I have had a lot to learn over the past few days!

I have 2 CentOS 6.5 servers in Amazon AWS running on their own EC2 Micro instances. I also have 1 Elastic IP set up. Each instance has the following installed:

  • Amazon EC2 API Tools
  • HAProxy
  • Keepalived
  • Apache / httpd
  • Java OpenJDK 1.6

I have got HAProxy installed and configured on both instances. For testing purposes I installed Apache to serve a basic index.html page so I could test that HAProxy was carrying out the LB task and round robin is working fine.

What I am trying to achieve, is using Keepalived to monitor the haproxy process on LB1 (Has EIP assigned), if it fails or stops for some reason, it calls a script which uses the AWS EC2 API Tools to reassign an Elastic IP to the second Loadbalancer to take over..

I have googled and looked at the documentation to create a script that achieves this, however, when I test it and the HAProxy service is stopped, it does not run the script..

LB1 - Contents of keepalived.conf

vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 2
weight 2

vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 101
vrrp_unicast_bind 10.xx.xx.01 # The IP of the host this file is stored on
vrrp_unicast_peer 10.xx.xx.23 # The IP of the other host
advert_int 1
track_script {
notify_fault /etc/keepalived/vrrp.sh

Output from Tailing the log

Jun 18 12:03:11 ip-10-xx-xx-xx Keepalived_vrrp[25199]: Opening file '/etc/keepalived/keepalived.conf'.
Jun 18 12:03:11 ip-10-xx-xx-xx Keepalived_vrrp[25199]: Configuration is using : 60618 Bytes
Jun 18 12:03:11 ip-10-xx-xx-xx Keepalived_vrrp[25199]: Using LinkWatch kernel netlink reflector...
Jun 18 12:03:11 ip-10-xx-xx-xx Keepalived_vrrp[25199]: VRRP sockpool: [ifindex(2), proto(112), fd(10,11)]
Jun 18 12:03:11 ip-10-xx-xx-xx Keepalived_vrrp[25199]: VRRP_Script(chk_haproxy) succeeded
Jun 18 12:03:12 ip-10-xx-xx-xx Keepalived_vrrp[25199]: VRRP_Instance(VI_1) Transition to MASTER STATE
Jun 18 12:03:13 ip-10-xx-xx-xx Keepalived_vrrp[25199]: VRRP_Instance(VI_1) Entering MASTER STATE
Jun 18 12:03:19 ip-10-xx-xx-xx Keepalived_vrrp[25199]: VRRP_Script(chk_haproxy) failed

My first impression is that it has detected the haproxy service failure, but it doesnt seem to execute the vrrp.sh script. (contents below)

cd $EC2_BASE/tools/bin
#DisAssociate EIP from this instance.
./ec2-disassociate-address  54.xx.xx.xx
#Mapping EIP to secondary server
./ec2-associate-address 54.xx.xx.xx -i [instance-id]

If I run the vrrp.sh script by itself on the server, it runs the commands and successfully re-assigns the EIP. Just not when it is called from the keepalived.conf script.

Any ideas!? I've been scratching my head all day and the laptop is about to be launched out the window..

share|improve this question

2 Answers 2

The notify_fault script is invoked when keepalived enters the fault state.

You want to configure your script using

notify_master /etc/keepalived/vrrp.sh
share|improve this answer
I tried this also, but it still failed to run the script. So if Keepalived enters the master state it would then run the script which would reassign the script to the other load balancer? Slave? I think i'm confusing myself now.. :-/ –  Chris Jun 19 '14 at 12:51
Can you verify this from the logs? A desparate try could be to make it the general notify script, and check the first command line argument to determine if the current transition is to MASTER state. –  Felix Frank Jun 19 '14 at 12:54
My Logs: [root@ip-xx.xx.xx.xx ~]# tail /var/log/messages Jun 19 13:13:53 ip-xx.xx.xx.xx Keepalived_vrrp[19601]: VRRP sockpool: [ifindex(2), proto(112), fd(10,11)] Jun 19 13:13:54 ip-xx.xx.xx.xx Keepalived_vrrp[19601]: VRRP_Instance(VI_1) Transition to MASTER STATE Jun 19 13:13:55 ip-xx.xx.xx.xx Keepalived_vrrp[19601]: VRRP_Instance(VI_1) Entering MASTER STATE Jun 19 13:13:59 ip-xx.xx.xx.xx Keepalived_vrrp[19601]: VRRP_Script(chk_haproxy) succeeded Jun 19 14:10:30 ip-xx.xx.xx.xx Keepalived_vrrp[19601]: VRRP_Script(chk_haproxy) failed –  Chris Jun 19 '14 at 15:49

Can you please paste your backup.conf and slave.conf files?

Also, you should check these two articles:

http://www.trk7.com/blog/keepalived-instance-not-entering-failed-state/ or http://comments.gmane.org/gmane.linux.keepalived.devel/4102 ?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.