Monday, July 2, 2018

Keepalived configure for Failover

Friends,

Today I am showing Haproxy setup along with Keepalived. In this blog I will setup Keep alive. HaProxy setup will be done on my next blog.

Keepalived is used to achieve high availability by assigning a VIP to two or more servers.

Installation:-
I am doing this on two ubuntu servers having ip 172.16.1.209 and 172.16.1.211. The virtual IP will be 172.16.1.210.

Install packages

apt-get install keepalived

Configuring keepalived

Create the config file on the first server (172.16.1.209):
vim /etc/keepalived/keepalived.conf
global_defs {
  router_id NM-PRD-HAPROXY-209
}
vrrp_script haproxy {
script "killall -0 haproxy"
interval 1
weight 2
}
vrrp_instance 50 {
virtual_router_id 50
advert_int 1
priority 101
state MASTER
interface eth0
virtual_ipaddress {
172.16.1.210
  }
  track_script {
haproxy
  }
authentication {
        auth_type PASS
        auth_pass We$,J)Og&
    }
}

Create the config file on the second server (172.16.1.211)


vim /etc/keepalived/keepalived.conf
global_defs {
  router_id NM-PRD-HAPROXY-211
}
vrrp_script haproxy {
  script "killall -0 haproxy"
  interval 1
  weight 2
}
vrrp_instance 50 {
  virtual_router_id 50
  advert_int 1
  priority 102
  state MASTER
  interface eth0
  virtual_ipaddress {
    172.16.1.210
  }
  track_script {
    haproxy
  }
authentication {
        auth_type PASS
        auth_pass We$,J)Og&
    }
}

Note :-

We need to enable sysctl setting for no local ip binding allow on the Kernel.
Temporary:
echo 1 > /proc/sys/net/ipv4/ip_nonlocal_bind
Permanent:
Add this to /etc/sysctl.conf:
net.ipv4.ip_nonlocal_bind = 1
Enable with:
sysctl -p

Start service
When our Haproxy setup done, We need to start Keepalived on both servers:
service keepalived start

1 comment:

  1. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    AWS Online Training
    AWS Certification Training
    AWS Certification Course Online
    AWS Training
    AWS Online Course

    ReplyDelete

Renew k8s certificates

Check If certificate expires: amikum@~:03:06:54(⎈ |local-cluster:default):sudo kubeadm certs check-expiration CERTIFICATE                EXP...