加入收藏 | 设为首页 | 会员中心 | 我要投稿 新余站长网 (https://www.0790zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

IP Failover Setup using Keepalived on CentOS/Redhat 6

发布时间:2021-01-25 07:37:36 所属栏目:Linux 来源:网络整理
导读:source url: Keepalived ?is used for IP failover between two servers. It facilities for?load balancing?and high-availability to Linux based infrastructures. It works on VRRP ( Virtual Router Redundancy Protocol ) protocol. We have running

source url:

Keepalived?is used for IP failover between two servers. It facilities for?load balancing?and high-availability to Linux based infrastructures. It works on VRRP ( Virtual Router Redundancy Protocol ) protocol. We have running two?load balance?servers using HAProxy and now we need to implement VRRP between both servers. This tutorial will help you to configure KeepAliveD,Use?tutorial to configure HAProxy on both servers.

  1. LB1 Server: 192.168.10.111 ( eth1 )
  2. LB2 Server: 192.168.10.112 ( eth1 )
  3. Virtual IP: 192.168.10.121

Now we are implementing ip failover setup between LB1 and LB2 servers.

keepalived-vrrp-network

Use following command to install required packages to configure Keepalived on server.

# yum install gcc kernel-headers kernel-devel

Keepalived is available in centos base repository. Install it using yum command line tool.

# yum install keepalived

Keepalived configuration File: /etc/keepalived/keepalived.conf

Edit Keepalived configuration file on LB1 and add following configuration.

vrrp_instance VI_1 {
interface eth1
state MASTER
virtual_router_id 10
priority 101   # 101 on master,100 on backup
virtual_ipaddress {
192.168.10.121
}
}

Edit Keepalived configuration file on LB2 and add following configuration.

vrrp_instance VI_1 {
interface eth1
state BACKUP
virtual_router_id 10
priority 100   # 101 on master,100 on backup
virtual_ipaddress {
192.168.10.121
}
}
Note: 1. priority value will be higher on Master server,It doesn't matter what you used in state.  If your state is MASTER but your priority is lower than the router with BACKUP,you will lose the MASTER state.
2. virtual_router_id should be same on both LB1 and LB2 servers.
3. By default single vrrp_instance support up to 20 virtual_ipaddress. In order to add more addresses you need to add more vrrp_instance 

Start Keepalived service using following command and also configure to auto start on system boot.

# service keepalived start
# chkconfig keepalived on

By default virtual ip will assigned to master server,In case of master get down,it will automatically assigned to slave server. Use following command to show assigned virtual ip on interface.

# ip addr show eth1

Sample output

2: eth1:  mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:0c:29:6f:ed:60 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.111/24 brd 192.168.1.255 scope global eth1
    inet 192.168.10.121/32 scope global eth1
    inet6 fe80::20c:29ff:fe6f:ed60/64 scope link
       valid_lft forever preferred_lft forever

1. Shutdown master server ( LB1 ) and?check?if ips are automatically assigned to slave server.

# ip addr show eth1

2. Now start LB1 and stop slave server ( LB2 ). IPs will automatically assigned to master server.

# ip addr show eth1

3.?Watch?log files to insure its working

# tailf /var/log/messages

Sample Output

Mar 19 17:30:24 localhost Keepalived_vrrp[6958]: VRRP_Instance(VI_1) Transition to MASTER STATE
Mar 19 17:30:25 localhost Keepalived_vrrp[6958]: VRRP_Instance(VI_1) Entering MASTER STATE
Mar 19 17:30:25 localhost Keepalived_vrrp[6958]: VRRP_Instance(VI_1) setting protocol VIPs.
Mar 19 17:30:25 localhost Keepalived_healthcheckers[6957]: Netlink reflector reports IP 192.168.10.121 added
Mar 19 17:30:25 localhost avahi-daemon[1407]: Registering new address record for 192.168.10.121 on eth1.IPv4.
Mar 19 17:30:25 localhost Keepalived_vrrp[6958]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 

I hope this article will help to setup IP failover between two?load balance?servers.

Related posts:
  1. ?Its a good practice to enable email alerts in your...
  2. ?The DNS ( Domain Name System ) is a distributed...
  3. ?Sendmail is a mail server used for sending and receiving...
  4. ?Hi Guys,Being a system administrator,you always need to...

(编辑:新余站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读