2

I am trying to create load balancer using Virtual IP. I referred this link Load Balancer using Virtual IP. After configuring by mistake I started the backup server's keepalived service first and then I started master server's keepalived. The problem is the backup server's keepalived is working fine but I can't start the master server's keepalived. I tried uninstall the keepalived and installed again but that didn't work. Here is the config files

Master Server

vrrp_script chk_haproxy {
   script "killall -0 haproxy"   # verify the pid existance
   interval 2                    # check every 2 seconds
   weight 2                      # add 2 points of prio if OK
}

vrrp_instance VI_1 {
   interface eth0                # interface to monitor
   state MASTER
   virtual_router_id 51          # Assign one ID for this route
   priority 101                  # 101 on master, 100 on backup
   virtual_ipaddress {
       192.168.0.54            # the virtual IP
   }
   track_script {
       chk_haproxy
   }
}

Backup Server

vrrp_script chk_haproxy {
   script "killall -0 haproxy"   # verify the pid existance
   interval 2                    # check every 2 seconds
   weight 2                      # add 2 points of prio if OK
}

vrrp_instance VI_1 {
   interface eth0                # interface to monitor
   state MASTER
   virtual_router_id 51          # Assign one ID for this route
   priority 100                  # 101 on master, 100 on backup
   virtual_ipaddress {
       192.168.0.54            # the virtual IP
   }
   track_script {
       chk_haproxy
   }
}

Output of Master Server while starting the keepalived service

$ sudo service keepalived start
* Starting keepalived keepalived                                        [fail]

Output of Backup Server while starting the keepalived service

$ sudo service keepalived start
* Starting keepalived keepalived                                        [Ok]

Is anyone having suggestion what I am doing wrong here??

Update according to comments: Master Server Log:

cat /var/log/syslog | grep VRRP_Instance

Here it does not prints anything which mean that the keepalived does not start on Master server

Backup servers log:

cat /var/log/syslog | grep VRRP_Instance
Mar 27 02:39:22 ubuntu keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Mar 27 02:39:23 ubuntu keepalived_vrrp: VRRP_Instance(VI_1) Entering to MASTER STATE
Mar 27 02:39:38 ubuntu keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Mar 27 02:39:39 ubuntu keepalived_vrrp: VRRP_Instance(VI_1) Entering to MASTER STATE
Mar 27 02:52:16 ubuntu keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert
Mar 27 02:52:16 ubuntu keepalived_vrrp: VRRP_Instance(VI_1) Entering to BACKUP STATE

Also one more thing after referring to a website I changed the state in keepalived.conf file of backup server to state BACKUP

3 Answers3

0

You have misconfigured your VRRP instance. You have state MASTER on both nodes, but you can have only one master. Set backup server to state BACKUP and it will work. In general, rules are quite simple:

Same on both servers:

  • virtual_router_id - must be uniq for each group of servers
  • virtual_ip

Different on both servers:

  • Instance name ( vrrp_instance THIS-IS-INSTANCE-NAME { )
  • state (MASTER on one, BACKUP on others)
  • priority (uniq for each node, highest for master)
Ondra Sniper Flidr
  • 2,623
  • 11
  • 18
  • I can comment that I'm using keepalived 2. I establish in config file for three nodes as Master state for testing. The first node is working as master and when I execute systemctl restart keepalived for second and third nodes, it detects automatically that a Master node exists. Furthermore the second and third nodes are established as Backup state. – user3637971 Nov 16 '21 at 14:41
0

state MASTER can only be set one of the node. Alternatively, both set to state BACKUP, It will be automatically selected in MASTER by priority.

Taichi Yanagiya
  • 392
  • 1
  • 6
0

It would be useful if you could repost your current config. Maybe give this a try though.

Master server

vrrp_script chk_haproxy {
   script "pidof haproxy"        # check the pid not kill it
   interval 2                    # check every 2 seconds
   weight 2                      # add 2 points of prio if OK
}

vrrp_instance VI_1 {
   interface eth0                # interface to monitor
   state MASTER
   virtual_router_id 51          # Assign one ID for this route
   priority 150                  # 150 on master, 100 on backup
   unicast_peer {
       <backup ip address>
   }
   virtual_ipaddress {
       192.168.0.54            # the virtual IP
   }
   track_script {
       chk_haproxy
  }
}

Backup server

All the same as the master but change:

state BACKUP
priority 100
unicast_peer {
     <master ip address>
}

ensure you are allowing VRRP protocol (IP proto 112) between master and backup. Check state of each at /var/run/keepalived.INSTANCE.VI_1.state Make sure haproxy starts before keepalived.

JohnA
  • 556
  • 3
  • 12