linux————Keepalived—web dual-machine hot backup

I. Overview

        Keepalived is a high-availability solution for LVS services based on the VRRP protocol, which can solve the single point of failure problem in static routing.

principle

        In an LVS service cluster, there are usually servers with two roles: master server (MASTER) and backup server (BACKUP). However, they appear as a virtual IP to the outside world. The master server will send VRRP notification information to the backup server. When the backup server cannot receive it, When a VRRP message is received, that is, when the main server is abnormal, the backup server will take over the virtual IP and continue to provide services, thus ensuring high availability.

2. Installation

Configure three hosts and two nginx services, one for the shared directory

yum install -y epel-release (nginx service)

yum install -y nginx (nginx service)

yum install -y keepalived (nginx service)

yum install -y nfs-utils (three hosts)

nginx1  ip     192.168.100.10

nginx 2 ip     192.168.100.11

nfs    ip         192.168.100.12

keepalived configuration file analysis

router_id 1 Define the node id
state MASTER|BACKUP Define the node master-slave state
interface ens33 Configure the monitoring network card
virtual_router_id 51 The same hot standby group must be consistent
priority 100 Node priority
advert_int 1 How many seconds to perform a heartbeat detection
authentication {   
        auth_type PASS keepalived node Authentication method,
        auth_pass 1111 The same keepalived dual-machine hot standby group must be consistent
    }   

virtual_ipaddress Configure VIP, that is, drift address
vrrp virtual ip related configuration

3. Function module

The core main process starts
vrrp vrrp protocol: hot backup routing protocol
check health status detection

4. Configure dual-machine hot standby

1. Configure keepalived of nginx service

Modify configuration file

 

 After modification

 test

 Temporarily stop keepalived in nginx 1 and configure keepalived in nginx2

 2. Configure nfs

Achieve consistent content of nginx hot standby web pages

Configure nfs shared directory

mkdir   /optpub

vim /etc/exports

exportfs -avr

 3. nginx service mounts shared directory

 4. Test

5. Split-brain phenomenon in dual-machine hot standby

        If the virtual_router_id parameter configuration at both ends of the same VRRP instance in the Keepalived configuration
        is inconsistent, it will also cause a split-brain problem.
        The vrrp instance names are inconsistent and the priorities are consistent.
        The firewall is turned on, causing the heartbeat to fail to communicate normally.
        The network card is faulty. The network card is multiplexed (the network card cannot be disabled for testing).

Guess you like

Origin blog.csdn.net/a872182042/article/details/132480140