0

I am using 2 Nginx servers on 2 different machines with Keepalived installed respectively on both machines. Below is the configuration for both Keepalived.

MASTER KEEPALIVED

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 150
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 1111
    }

     track_script {
            chk_http_port
        }

    virtual_ipaddress {
        10.0.80.240
    }

unicast_src_ip 10.0.80.66
    unicast_peer {
        10.0.80.68
    }
}

vrrp_script chk_http_port {
    script "pidof nginx"
    interval 2
}

SLAVE KEEPALIVED

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 1111
    }

    track_script {
        chk_http_port
    }

    virtual_ipaddress {
        10.0.80.240
    }

unicast_src_ip 10.0.80.68
    unicast_peer {
        10.0.80.66
    }
}

vrrp_script chk_http_port {
    script "pidof nginx"
    interval 2
}

NOTE: 10.0.80.66 & 10.0.80.68 are the 2 servers having Nginx and Keepalived installed. 10.0.80.240 is the valid non assigned private IP in the network used as virtual IP here in keepalived configuration

QUESTION: When Nginx with MASTER stated Keepalived on 10.0.80.66 is down, the Keepalived does not redirect request to a Nginx instance alive on 10.0.80.68. Is there any settings I need to do on the machines to make it happen?

Ankur Soni
  • 101
  • 2

1 Answers1

0

The question lack a lot of information on the reasons of this "down" status, but i will go with the obvious: Your 'vrrp_script' only check that the nginx process is present in the system, not that the service is up and running.

For a reliable check you need to go further, for example something like this:

#!/bin/bash
# exit on first error
set -o errexit
# check nginx process exist
pidof nginx
# check nginx static processing ok (if appliable)
curl --silent http://localhost/static/test/
# check dynamic backend (ideally should test backend database connection)
curl --silent http://localhost/service/test/
# everything was ok ? so exit fine
exit 0

Obiously you need to tweak and it can be much more "intelligent"

silmaril
  • 471
  • 3
  • 9
  • Thanks for your time. By being "down" means that process got terminated either gracefully or got abruptly terminated. My question is still the same that when 1 Nginx has died, the keepalive must redirect request to another Nginx alive on other machine. This redirection is not happening. – Ankur Soni Jun 12 '18 at 13:27
  • Keepalived won't "redirect" anything, it should simply move the IP address to the second node. If you manually stop the master keepalive process, does the ip switch-over occur correctly ? – silmaril Jun 12 '18 at 13:47
  • Yes! manually stopping keepalive, it does switch VIP to other Keepalive node. But the problem arise when one Nginx is down, VIP still remains in usage even when Nginx is dead. the netstat for VIP changes from ESTABLISHED to FIN_WAIT1, but it is not assigned to other keepalive. – Ankur Soni Jun 12 '18 at 14:10
  • Keepalived logs (within syslog) - from startup to fault state - and version would be invaluable to help in this case. – silmaril Jun 12 '18 at 22:34
  • I followed https://serverfault.com/questions/718132/keepalived-vrrp-script-not-failing-over and added one more configuration parameter as `weight -4` in both the keepalived.conf and got my issue resolved. – Ankur Soni Jun 13 '18 at 13:29
  • Oh yes, there was a change around keepalived 1.3 on this, with 1.2.2 default weight directly set the instance in Fault state, now it's a bit more complicated. Sorry i forgot that and only looked at our old keepalived setups. However given your configuration i would set a weight of -51 at least – silmaril Jun 14 '18 at 08:31