当前位置:网站首页>Keepalived to achieve high service availability

Keepalived to achieve high service availability

2022-06-26 06:00:00 Interview with Java factory

1. Keepalived summary

1.1 Keepalived What is it? ?
Keepalived Software was originally designed for LVS Designed by load balancing software , To manage and monitor LVS The status of each service node in the cluster system , Later, we added the high availability VRRP function . therefore ,Keepalived Besides being able to manage LVS Software outside , It can also be used as other services ( for example :Nginx、Haproxy、MySQL etc. ) High availability solution software .

Keepalived Software is mainly through VRRP Protocol for high availability .VRRP yes Virtual Router Redundancy Protocol( Virtual router redundancy protocol ) Abbreviation ,VRRP The purpose is to solve the problem of single point failure of static routing , It can guarantee that when individual nodes are down , The whole network can run continuously .

therefore ,Keepalived On the one hand, it has configuration management LVS The function of , At the same time, it also has the right to LVS The health check function of the following nodes , On the other hand, it can also realize the high availability function of system network service .

1.2 Keepalived Three important functions of service
management LVS Load balancing software
Realization LVS Cluster node health check
High availability as a system network service (failover)

1.3 Keepalived High availability failover principle
Keepalived Failover between pairs of highly available services , It's through VRRP (Virtual Router Redundancy Protocol, Virtual router redundancy protocol ) To achieve .

stay Keepalived When the service is working , Lord Master The node will continuously send ( The way of multicasting ) Heartbeat message , To inform for Backup Node itself still live to see , When the Lord Master When a node fails , Can't send a heartbeat message , Therefore, the standby node cannot continue to detect the arrival of autonomy Master Node's heartbeat , So call your own receiver , Take over the master Master Node IP Resources and services . And be the Lord Master When the node recovers , To prepare Backup The node will release its own takeover when the primary node fails IP Resources and services , Return to the original standby role .

What is? VRRP?
VRRP, Full name Virtual Router Redundancy Protocol, The Chinese name is virtual routing redundancy protocol ,VRRP The emergence of static routing is to solve the single point of failure problem ,VRRP It is through an election mechanism to hand over the routing task to a certain station VRRP The router .

1.4 Keepalived working principle
Keepalived High availability clusters are connected by VRRP communication , therefore , Let's get to know VRRP:

  1. VRRP, Full name Virtual Router Redundancy Protocol, The Chinese name is virtual routing redundancy protocol ,VRRP The emergence of static routing is to solve the single point of failure problem .
  2. VRRP It is through a campaign protocol mechanism to hand over routing tasks to a certain station VRRP The router .
  3. VRRP use IP The way of multicasting ( Default multicast address (224.0_0.18)) Realize the communication between high availability clusters .
  4. When working, the main node is contracted , Prepare node connection package , When the standby node can't receive the packet sent by the primary node , Start a takeover program to take over the resources of the master node . There can be multiple standby nodes , Through a priority campaign , But not so Keepalived System operation and maintenance work is a pair of .
  5. VRRP Encryption protocol is used to encrypt data , but Keepalived At present, the official still recommends that the authentication type and password be configured in clear text .

Keepalived How services work :
Keepalived High availability clusters are connected by VRRP Communicating ,VRRP It's through the campaign mechanism to determine who's in charge , The primary node has higher priority than the standby node , therefore , When working, the master node will get all the resources first , The standby node is waiting , When the master node is down , The standby node will take over the resources of the primary node , Then replace the primary node to provide external services .

stay Keepalived Between Service Clusters , Only the server as the master node will always send VRRP Broadcast packet , Tell him he's still alive , At this time, the standby node will not occupy the primary node , When the Lord is not available , That is, when the standby cannot listen to the broadcast packet sent by the primary node , It will start relevant services to take over resources , Ensure business continuity , The fastest connection speed can be less than 1 second .

2. Keepalived Use

2.1 install
Linux Execute command installation on the server :

yum install keepalived -y
/etc/keepalived/keepalived.conf     # keepalived Service master profile 
/etc/rc.d/init.d/keepalived         #  Service startup script 

2.2 The configuration file keepalived.conf Related configuration and description

! Configuration File for keepalived
# Global configuration 
global_defs {
    
   #  Load balancing flag , It should be unique in the LAN . Usually the host name .
   router_id  Host name 
}

# Define examples 
vrrp_instance VI_1 {
    
    #  Appoint keepalived Role ,MASTER Mainly ,BACKUP For the case 
    state MASTER
    #  The current in vrrp Communication network interface card ( At present centos Network card of )
    interface ens33
    #  Appoint VRRP example ID( Virtual route number ), The scope is 0-255, Be consistent 
    virtual_router_id 202
    #  priority , The greater the numerical , The higher the priority of getting the request processed ,  The high priority will be MASTER.
    priority 100
    #  Specify send VRRP Notice interval , The default is 1s(vrrp Number of seconds of multicast cycle )
    advert_int 1
    #  Set the authentication type and password ,MASTER and BACKUP The same password must be used for normal communication 
    authentication {
    
        #  Specify the authentication method .PASS Simple password authentication ( recommend ),AH:IPSEC authentication ( Not recommended ).
        auth_type PASS
        #  Specify the password to use for authentication . most 8 position .
        auth_pass 2020
    }

    #  Define the virtual ip(VIP), Can be more , Each row of a 
    virtual_ipaddress {
    
        192.168.199.143
    }
}

2.3 start-up

/etc/init.d/keepalived start

3. High availability

Keepalived + Nginx Configure Links :
keepalived Installation and combination nginx Configure load for high availability

Last

At the end of the article, the author collated a lot of information for you ! Include java Core knowledge points + Full set of architect learning materials and videos + Interview guide for first-line large factories + Interview Resume Template +Java Architecture, e-books, etc !
All for free , If you need a friend Just click here and download directly , Verification Code :csdn
 Insert picture description here

原网站

版权声明
本文为[Interview with Java factory]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180502200842.html