On hot standby Keepalived

A basic knowledge of hot standby Keepalived

keepalived official website: www.keepalived.org/ keepalived in a non-LVS environment can also be used as a hot standby software.

1, Keepalived role

keepalived first is a powerful auxiliary tool designed specifically for LVS, mainly used to provide failover and health checks - LVS load balancer determine availability server nodes, timely isolation and replaced with a new server, when a failed host after its return to re-join the cluster. LVS separate deployment environment, then the scheduler downtime occurs, the whole cluster becomes ineffective after a certain web node goes down, the client at the time of the visit, there will always run into situations not visit the page, so the keepalived and LVS combine to form before a true high availability cluster, of course, must be shared storage backend storage server to build a highly available, three of which have a satisfied or not, can not be called a high-availability cluster environment.

2, the hot standby mode Keepalived

keepalived using VRRP (Virtual Routing Redundancy Protocol) protocol hot backup, a software-based multi-function hot standby Linux servers. VRRP backup solution is directed to a router - a multiple routers form a hot standby group, through a common virtual IP (VIP) address external services; the same time each hot backup group only one master router to provide services other routers in a redundant state, if the current line of routers fail, the other automatically takes over the router (priority order decided to take over) the virtual IP address, in order to continue to provide services.

Each router in the hot standby group are likely to be the main router, the IP address of the virtual router (VIP) can be transferred in a hot standby router group, it is also known drift IP address. When using keepalived, addresses the need to manually shift to achieve the establishment of virtual interface configuration files (e.g. ens32: 0), but is automatically managed by the file according to the configuration keepalived.
On hot standby Keepalived

Second, using dual hot standby Keepalived

Hot standby mode based on the VRRP, keepalived failover server may be used, each group may have more than one hot standby server - most commonly used is a multi hot standby. In this multi-machine hot standby scheme, the failover mainly for drift virtual IP address to achieve. Therefore it can be applied to various application servers (either Web, FTP, Mail, or SSH, DNS ....).

Topology as follows:
On hot standby Keepalived

1, configure the master server

Keepalived configuration directory services is located in / etc / keepalived /. Wherein, keepalived.conf main configuration file; further comprising a subdirectory samples /, there are many configurations as the reference sample. In Keepalived profile, using the "global_defs {...}" section specify global parameters, "vrrp_instance instance name {...}" hot backup VRRP parameters specified section, the comment text beginning with "!" Symbol.

[root@centos04 ~]# systemctl stop firewalld   <!--关闭防火墙-->
[root@centos04 ~]# yum -y install ipvsadm keepalived  <!--安装keeplived服务-->
[root@centos04 ~]# cp /etc/keepalived/keepalived.conf 
/etc/keepalived/keepalived.conf.bak   <!--备份keepalived主配置文件-->
[root@centos04 ~]# systemctl start keepalived   <!--启动keepalived服务-->
[root@centos04 ~]# chkconfig --level 35 keepalived on  <!--设置开机自动启动-->
[root@centos04 ~]# vim /etc/keepalived/keepalived.conf  <!--编辑keepalived主配置文件-->
! Configuration File for keepalived

global_defs {
   router_id LVS_HA_Master     <!--修改这里的服务器名称-->
}

vrrp_instance VI_1 {           <!--定义VRRP热备实例-->
    state MASTER               <!--热备状态,MASTER表示主服务器(注意大小写)-->
    interface ens32              <!--承载VIP地址的物理接口-->
    virtual_router_id 51        <!--虚拟路由器的ID号,每个热备组保持一致-->
    priority 100                     <!--优先级0-100,数值越大越优先-->
    advert_int 1                    <!--通告间隔秒数(心跳频率)-->
    authentication {              <!--认证信息,每个热备组保持一致-->
        auth_type PASS         <!--认证类型-->
        auth_pass 1111          <!--密码字串-->
    }
    virtual_ipaddress {          <!--指定漂移地址,可以有多个-->
        192.168.100.253
    } 
}
............     <!--此处省略部分内容-->

After confirming the above configuration is correct, and then start keepalived service, the actual state of the primary server for the MASTER will automatically add ens32 interfaces VIP address, the ip command to view (Note: ifconfig command can not see).

[root@centos04 ~]# systemctl restart keepalived  <!--重启keepalived服务-->
[root@centos04 ~]# ip a show dev ens32 <!--查看ens32接口-->
ens32: <BROADCAST,MULTICAST,UP,LOWER_UPUt qlen 1000
    link/ether 00:0c:29:77:2c:03 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.40/24 brd 192.168.1.255 scope global noprefixroute ens32
       valid_lft forever preferred_lft forever
    inet 192.168.100.253/32 scope global ens32   <!--可以看到VIP已经配置在ens32上-->
       valid_lft forever preferred_lft forever
    inet6 fe80::95f8:eeb7:2ed2:d13c/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

2, the configuration from the node

Keepalived hot standby in the same group, all servers keepalived profile substantially the same, including the ID number of the virtual router , authentication information , drift address , heart rate and the like . The main difference is that the name of the router, hot standby status, priority.

  • Router name (route_id): recommendations specify a different name for each server involved in hot standby.

  • Hot Standby state (state): have at least one primary server, set the status to the MASTER; can have more than one backup server, sets the status to BACKUP.

  • Priority (priority): to obtain higher value of the control VIP higher the priority, so the priority should be set to the primary maximum and services; other backup servers in descending order, but not identical, in order to avoid contention occurs when control VIP conflict.

When configured standby server (which may be more than one), the master server may reference the configuration file for the text keepa.conf, simply change the name of the router, the hot standby state, the priority of it.

[root@centos05 ~]# systemctl stop firewalld   <!--关闭防火墙-->
[root@centos05 ~]# yum -y install keepalived ipvsadm<!--安装相关工具-->
[root@centos05 ~]# scp 
[email protected]:/etc/keepalived/keepalived.conf
/etc/keepalived/
<!--使用从节点服务器root用户将主节点服务器的keepalived配置文件复制过来-->
[email protected] s password: <!--输入主节点root用户的密码-->
keepalived.conf                             100% 3549     3.5MB/s   00:00   
[root@centos05 ~]# vim /etc/keepalived/keepalived.conf  
                  <!--编辑keepalived主配置文件-->
global_defs {
   ...............
   router_id LVS_DEVEL2          <!--修改这里的服务器名称-->
  .....................

}
                ..............
vrrp_instance VI_1 {
    state BACKUP  <!--修改这里的状态,改为BACKUP-->
    interface ens32  <!--若该服务器承载VIP的物理接口有变,则这里也要修改-->
    virtual_router_id 51
    priority 90               <!--修改优先级,要比主服务器低-->
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }   
    virtual_ipaddress {
    192.168.100.253
    }
}   
              .................
<!--改动上述几行后,保存退出即可-->
[root@centos05 ~]# systemctl start keepalived  <!--启动服务-->
[root@centos05 ~]# systemctl enable keepalived<!--设置开机自启动-->

Confirm the configuration is correct, the same need to start keepalived service. At this time, the primary server is still online, the VIP address is actually still controlled by the master server, another server in the backup state, and therefore does not add VIP addresses ens32 the interface in the backup server.

[root@centos05 ~]# ip a show dev ens33       <!--查看ens33接口,不会看到VIP-->
ens32: <BROADCAST,MULTICAST,Udel state UP group default qlen 1000
    link/ether 00:0c:29:9a:09:98 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.50/24 brd 192.168.1.255 scope global noprefixroute ens32
       valid_lft forever preferred_lft forever
    inet6 fe80::3050:1a9b:5956:5297/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

3, dual-function test Hot Standby

The main server is down, or stop keepalived service, wait about 15 seconds to view the backup server ens32 card, you will find the address has been transferred from the drift, indicating Hot Standby function dual effect. After the primary server is powered on, drift address will be automatically transferred back to the primary server.

[root@centos05 ~]# ip a show dev ens32   <!--主服务器关机后查看备份服务器的网卡信息-->
ens32: <BROADCAST,MULTICAST,UP state UP group default qlen 1000
    link/ether 00:0c:29:9a:09:98 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.50/24 brd 192.168.1.255 scope global noprefixroute ens32
       valid_lft forever preferred_lft forever
    inet 192.168.100.253/32 scope global ens32 <!--漂移地址已经转移过来了-->
       valid_lft forever preferred_lft forever
    inet6 fe80::3050:1a9b:5956:5297/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

Then the primary server is powered on, you will find VIP has been transferred back to the primary server and backup server and finding out VIP:

[root@centos04 ~]# ip a show dev ens32   <!--在主服务器上进行查看-->
ens32: <BROADCAST,MULTICAST,UP,Lefault qlen 1000
    link/ether 00:0c:29:77:2c:03 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.40/24 brd 192.168.1.255 scope global noprefixroute ens32
       valid_lft forever preferred_lft forever
    inet 192.168.100.253/32 scope global ens32 <!--VIP地址在这里了-->
       valid_lft forever preferred_lft forever
    inet6 fe80::95f8:eeb7:2ed2:d13c/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@centos05 ~]# ip a show dev ens32  <!--在备份服务器上进行查看-->
ens32: <BROADCAST,MULTICAST,UP,P grou00
    link/ether 00:0c:29:9a:09:98 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.50/24 brd 192.168.1.255 scope goute ens32
       valid_lft forever preferred_lft forever
    inet6 fe80::3050:1a9b:5956:5297/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

------ This concludes the article, thanks for reading ------

Guess you like

Origin blog.51cto.com/14156658/2457605