3

I'm using keepalived to setup a virtual ip that points to a master server. When a failover happens it should point the virtual ip to the backup, and the IP should stay there until I manually enable (fix) the master.

The reason this is important is that I'm running mysql replication on the servers and writes should only be on the master. When I failover I promote the slave to master.

The master server:

  global_defs {
    ! this is who emails will go to on alerts
     notification_email {
           xx@gmail.com
     ! add a few more email addresses here if you would like
   }
   notification_email_from root@xx.se 

   ! I use the local machine to relay mail
   smtp_server 127.0.0.1
   smtp_connect_timeout 30

   ! each load balancer should have a different ID
   ! this will be used in SMTP alerts, so you should make
   ! each router easily identifiable
    lvs_id APP1         
} 

vrrp_instance APP1 {
         interface eth0
         state EQUAL
         virtual_router_id 61
         priority 999
    nopreempt
         virtual_ipaddress {
             217.x.x.129
         }

    smtp_alert
}

Backup server:

 global_defs {
   ! this is who emails will go to on alerts
   notification_email {
       xx@gmail.com
   ! add a few more email addresses here if you would like
  }
  notification_email_from root@xx.se 

  ! I use the local machine to relay mail
  smtp_server 127.0.0.1
  smtp_connect_timeout 30

  ! each load balancer should have a different ID
  ! this will be used in SMTP alerts, so you should make
  ! each router easily identifiable
   lvs_id APP2           
   } 

vrrp_instance APP2 {
    interface eth0
    state EQUAL
    virtual_router_id 61   
  priority 100            
    virtual_ipaddress {
        217.xx.xx.129
    }

notify_master "/etc/keepalived/notify.sh del app2"
notify_backup "/etc/keepalived/notify.sh add app2"
notify_fault "/etc/keepalived/notify.sh add app2”
smtp_alert
}
Chrille
  • 463
  • 2
  • 5
  • 10
  • possible duplicate of [Prevent VRRP Master from becoming Master once it has failed](http://serverfault.com/questions/44122/prevent-vrrp-master-from-becoming-master-once-it-has-failed) – quanta Jun 08 '12 at 10:17
  • I've tried all on that link, but it doesn't work. The thread is from 09 so maybe they changed the configuration? – Chrille Jun 08 '12 at 10:34
  • I set state on both servers to BACKUP, combined with `nopreempt` option and it worked like a charm. Give it a try. – quanta Jun 27 '12 at 09:39

2 Answers2

2

I had same problem as you. Solved it by setting nopreempt on both keepalived servers, and also (which is very important according to http://article.gmane.org/gmane.linux.keepalived.devel/1537) setting both servers in state BACKUP (with different priorities).

Works great! :-)

Tomasz Olszewski
  • 868
  • 9
  • 20
0

This may not be the most elegant solution, but couldn't you stop keepalived in the notify_backup and notify_fault scripts on the master? That way, you would have to restart it in order to gain control again.

Something like that:

notify_backup "/etc/init.d/keepalived stop"
notify_fault "/etc/init.d/keepalived stop"
Oliver
  • 5,883
  • 23
  • 32