Introduction and construction steps of LVS+Keepalived high availability cluster

catalogue

I   Introduction to keepalived tool

1. A health examination tool specially designed for LVS and HA

2. Implementation principle of keepalived

3.VRRP (virtual routing Redundancy Protocol)

2, Construction of LVS+Keepalived high availability cluster

1. Main DR server (192.168.68.200)

1. Install the Keepalived program

two   Backup the master configuration file

3. Modify the master configuration file  

4. View virtual network card vip  

5. Turn off the redirection parameter response of the Linux kernel

  6. Refresh configuration

  7. Load module

2. Standby DR server (192.168.68.30)

1. Install the Keepalived program

two   Backup the master configuration file

3. Modify the master configuration file  

4. View virtual network card vip  

5. Turn off the redirection parameter response of the Linux kernel

  6. Refresh configuration

7. Load module

three   Web server 1 (192.168.68.105)

1. Install the http service and start it

2. Create a web page file in the web page site directory and write the content

3. Enter your own ip in the web1 browser for verification

4. Create a virtual interface and configure it  

5. Open the virtual interface and view it

6. Adjust the proce response parameters

7. Update configuration

four   Web server 2 (192.168.68.40)

1. Install the http service and start it

2. Create a web page file in the web page site directory and write the content

3. Enter your own ip in the web1 browser for verification

4. Create a virtual interface and configure it  

5. Open the virtual interface and view it

6. Adjust the proce response parameters

7. Update configuration

5. Test

I   Introduction to keepalived tool

1. A health examination tool specially designed for LVS and HA

  • Support automatic failover
  • Support node health check
  • Official website: http://www.keepalived.org/

2. Implementation principle of keepalived

Keepalived adopts VRRP hot backup protocol to realize the multi machine hot backup function of Linux server

3.VRRP (virtual routing Redundancy Protocol)

A backup for routers

  • A hot standby group is composed of multiple routers to provide services through the shared virtual IP address
  • Only one router in each hot standby group provides services at the same time, and other routers are in redundant state
  • If the current online router fails, other routers will automatically take over the virtual IP address according to the set priority and continue to provide services

2, Construction of LVS+Keepalived high availability cluster

The LVS cluster structure based on LVS + kept includes at least two hot standby load schedulers and more than three node servers

Main DR server: 192.168.68.200
Standby DR server: 192.168.68.30
Web server 1: 192.168.68.105
Web server 2: 192.168.68.40
vip: 192.168.68.95
Client: 192.168.68.138  

Configure load scheduler (active and standby are the same)

1. Main DR server (192.168.68.200)

1. Install the Keepalived program

two   Backup the master configuration file

3. Modify the master configuration file  

 [root@localhost keepalived]# vim keepalived.conf

Delete everything after line 42 and replace with

4. View virtual network card vip  

5. Turn off the redirection parameter response of the Linux kernel

 [root@localhost keepalived]# vim /etc/sysctl.conf 

6. Refresh configuration

7. Load module

[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install -y ipvsadm.x86_64 keepalived.x86_64 
[root@localhost ~]# cd /etc/keepalived/
[root@localhost keepalived]# cp keepalived.conf keepalived.conf.bak
[root@localhost keepalived]# vim keepalived.conf
 10    smtp_server 127.0.0.1
 12    router_id LVS_01
 14    #vrrp_strict   ##Comment out line 14

 19 vrrp_instance VI_1 {
 20     state MASTER
 21     interface ens33
 22     virtual_router_id 10
 23     priority 100
 24     advert_int 1
 25     authentication {
 26         auth_type PASS
 27         auth_pass 123123
 28     }
 29     virtual_ipaddress {
 30         192.168.68.95
 31     } 

 34 virtual_server 192.168.68.95 80 {
 35     delay_loop 6
 36     lb_algo rr
 37     lb_kind DR
 38     persistence_timeout 50
 39     protocol TCP

 41     real_server 192.168.68.105 80 {
 42         weight 1
 43         TCP_CHECK {
 44                 connect_port 80
 45                 connect_timeout 3
 46                 nb_get_retry 3
 47                 delay_before_retry 3
 48         }
 49   }
 50     real_server 192.168.68.40 80 {
 51         weight 1
 52         TCP_CHECK {
 53                 connect_port 80
 54                 connect_timeout 3
 55                 nb_get_retry 3
 56                 delay_before_retry 3
 57         }
 58   }
 59 }
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vim ifcfg-ens33:0
NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.68.95
NETMASK=255.255.255.255
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# ifconfig 
[root@localhost keepalived]# vim /etc/sysctl.conf 
##Add at the end
 11 net.ipv4.ip_forward = 0
 12 net.ipv4.conf.all.send_redirects = 0
 13 net.ipv4.conf.default.send_redirects = 0
 14 net.ipv4.conf.ens33.send_redirects = 0
[root@localhost keepalived]# sysctl -p
[root@localhost keepalived]# modprobe ip_vs
[root@localhost keepalived]# cat /proc/net/ip_vs
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP  C0A8445F:0050 rr  persistent 50000 FFFFFFFF
[root@localhost keepalived]# ipvsadm-save >/etc/sysconfig/ipvsadm
[root@localhost keepalived]# systemctl start ipvsadm.service 
[root@localhost keepalived]# ipvsadm -C
[root@localhost keepalived]# ipvsadm -A -t 192.168.68.95:80 -s rr
[root@localhost keepalived]# ipvsadm -a -t 192.168.68.95:80 -r 192.168.68.105:80 -g
[root@localhost keepalived]# ipvsadm -a -t 192.168.68.95:80 -r 192.168.68.40:80 -g
[root@localhost keepalived]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  localhost.localdomain:http rr
  -> 192.168.68.40:http           Route   1      0          0         
  -> 192.168.68.105:http          Route   1      0          0         
[root@localhost keepalived]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.68.95:80 rr
  -> 192.168.68.40:80             Route   1      0          0         
  -> 192.168.68.105:80            Route   1      0          0         
[root@localhost keepalived]# ipvsadm-save >/etc/sysconfig/ipvsadm

2. Standby DR server (192.168.68.30)

1. Install the Keepalived program

two   Backup the master configuration file

3. Modify the master configuration file  

 [root@localhost keepalived]# vim keepalived.conf

Delete everything after line 42 and replace with

4. View virtual network card vip  

5. Turn off the redirection parameter response of the Linux kernel

 [root@localhost keepalived]# vim /etc/sysctl.conf 

6. Refresh configuration

7. Load module

[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install -y ipvsadm.x86_64 keepalived.x86_64 
[root@localhost ~]# cd /etc/keepalived/
[root@localhost keepalived]# cp keepalived.conf keepalived.conf.bak
[root@localhost keepalived]# vim keepalived.conf
 10    smtp_server 127.0.0.1
 12    router_id LVS_01
 14    #vrrp_strict   ##Comment out line 14

 19 vrrp_instance VI_1 {
 20     state MASTER
 21     interface ens33
 22     virtual_router_id 10
 23     priority 100
 24     advert_int 1
 25     authentication {
 26         auth_type PASS
 27         auth_pass 123123
 28     }
 29     virtual_ipaddress {
 30         192.168.68.95
 31     } 

 34 virtual_server 192.168.68.95 80 {
 35     delay_loop 6
 36     lb_algo rr
 37     lb_kind DR
 38     persistence_timeout 50
 39     protocol TCP

 41     real_server 192.168.68.105 80 {
 42         weight 1
 43         TCP_CHECK {
 44                 connect_port 80
 45                 connect_timeout 3
 46                 nb_get_retry 3
 47                 delay_before_retry 3
 48         }
 49   }
 50     real_server 192.168.68.40 80 {
 51         weight 1
 52         TCP_CHECK {
 53                 connect_port 80
 54                 connect_timeout 3
 55                 nb_get_retry 3
 56                 delay_before_retry 3
 57         }
 58   }
 59 }
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vim ifcfg-ens33:0
NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.68.95
NETMASK=255.255.255.255
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# ifconfig 
[root@localhost keepalived]# vim /etc/sysctl.conf 
##Add at the end
 11 net.ipv4.ip_forward = 0
 12 net.ipv4.conf.all.send_redirects = 0
 13 net.ipv4.conf.default.send_redirects = 0
 14 net.ipv4.conf.ens33.send_redirects = 0
[root@localhost keepalived]# sysctl -p
[root@localhost keepalived]# modprobe ip_vs
[root@localhost keepalived]# cat /proc/net/ip_vs
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP  C0A8445F:0050 rr  persistent 50000 FFFFFFFF
[root@localhost keepalived]# ipvsadm-save >/etc/sysconfig/ipvsadm
[root@localhost keepalived]# systemctl start ipvsadm.service 
[root@localhost keepalived]# ipvsadm -C
[root@localhost keepalived]# ipvsadm -A -t 192.168.68.95:80 -s rr
[root@localhost keepalived]# ipvsadm -a -t 192.168.68.95:80 -r 192.168.68.105:80 -g
[root@localhost keepalived]# ipvsadm -a -t 192.168.68.95:80 -r 192.168.68.40:80 -g
[root@localhost keepalived]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  localhost.localdomain:http rr
  -> 192.168.68.40:http           Route   1      0          0         
  -> 192.168.68.105:http          Route   1      0          0         
[root@localhost keepalived]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.68.95:80 rr
  -> 192.168.68.40:80             Route   1      0          0         
  -> 192.168.68.105:80            Route   1      0          0         
[root@localhost keepalived]# ipvsadm-save >/etc/sysconfig/ipvsadm

three   Web server 1 (192.168.68.105)

1. Install the http service and start it

2. Create a web page file in the web page site directory and write the content

 [root@localhost html]# vim index.html

 

3. Enter your own ip in the web1 browser for verification

4. Create a virtual interface and configure it  

5. Open the virtual interface and view it

6. Adjust the proce response parameters

[root@localhost network-scripts]# vim /etc/sysctl.conf

7. Update configuration

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install -y httpd 
[root@localhost ~]# systemctl start httpd.service 
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# vim index.html
hello oyyyyy!!!!!!!
[root@localhost html]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
DEVICE=lo
IPADDR=192.168.68.95
NETMASK=255.255.255.255
NETWORK=127.0.0.0
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
#BROADCAST=127.255.255.255
ONBOOT=yes
#NAME=loopback
[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ifconfig lo:0
[root@localhost network-scripts]# vim /etc/sysctl.conf
##Add these parameters at the end
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@localhost network-scripts]# sysctl -p

four   Web server 2 (192.168.68.40)

1. Install the http service and start it

2. Create a web page file in the web page site directory and write the content

 [root@localhost html]# vim index.html

 

3. Enter your own ip in the web1 browser for verification

4. Create a virtual interface and configure it  

5. Open the virtual interface and view it

6. Adjust the proce response parameters

[root@localhost network-scripts]# vim /etc/sysctl.conf

7. Update configuration

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install -y httpd 
[root@localhost ~]# systemctl start httpd.service 
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# vim index.html
hello wangyibo!!!!!!!!!
[root@localhost html]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
DEVICE=lo
IPADDR=192.168.68.95
NETMASK=255.255.255.255
NETWORK=127.0.0.0
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
#BROADCAST=127.255.255.255
ONBOOT=yes
#NAME=loopback
[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ifconfig lo:0
[root@localhost network-scripts]# vim /etc/sysctl.conf
##Add these parameters at the end
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@localhost network-scripts]# sysctl -p

5. Test

Enter 192.168.68.95 in the browser  

Wait 1 minute to refresh

Enter 192.168.68.95 after the ens33:0down of the primary server is turned off

After refresh

Tags: Linux Operation & Maintenance Nginx cluster lvm

Posted on Sun, 21 Nov 2021 04:29:05 -0500 by sspoke