当前位置:网站首页>[cluster] lvs+keepalived high availability cluster

[cluster] lvs+keepalived high availability cluster

2022-06-11 07:34:00 Sprite, don't be angry


Preface

The content of this blog is only to record the thoughts of bloggers , For reference only , Everything is subject to the results of their own practice .


One 、LVS+keepalived

1.0 Architecture Overview

effect IP Address Installation services
Main load balancer 192.168.13.10ipvsadm/keepalived
Node server 1192.168.13.20httpd
Node server 2192.168.13.30httpd
Backup load balancer 192.168.13.40ipvsadm/keepalived

1.2 Node server

yum install -y httpd
cd /etc/sysconfig/network-scripts/
cp ifcfg-lo ifcfg-lo:0
vim ifcfg-lo:0
	DEVICE=lo:0
	IPADDR=192.168.13.100
	NETMASK=255.255.255.255
	ONBOOT=yes

vim /etc/rc.local
	route add -host 192.168.13.100 dev lo:0
chmod +x /etc/rc.d/rc.local
vim /etc/sysctl.conf
	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
sysctl -p
echo '<h1>This is the first test web1!</h1>' > /var/www/html/index.html
systemctl start httpd

# Repeat for another node server 

1.2 Main load balancing server

yum install -y ipvsadm keepalived
cd /etc/keepalived
vim keepalived.conf
	10 That's ok :smtp_server 127.0.0.1
	12 That's ok :router_id LVS_01
	13-16 That's ok : Delete 
	
#vrrp Hot backup module #
	17 That's ok :interface ens33
	19 That's ok (priority 100 Insert... Above ):nopreempt
	27 That's ok :192.168.13.100
	28-29 That's ok : Delete 
	
#virtual Virtual server module #
	31 That's ok :192.168.13.100 80
	34 That's ok :lb_kind DR
	35 That's ok :persistence_timeout 0
	36 That's ok :protocol TCP
	
	38 That's ok :real_server 192.168.13.20 80 {
    
	39 That's ok :weight 1
	40 That's ok :TCP_CHECK {
    
	41 That's ok :connect_port 80
	42 That's ok :connect_timeout 3
	43 That's ok :nb_get_retry 3
	44 That's ok :delay_before_retry 3
	45 That's ok :}
	46 That's ok :}
	
	47-55 That's ok :38,46 co 46
	# The above 9 Copy the row node server configuration , Change the node server IP address 
	56 That's ok :}
	56 Below row : Delete all 

systemctl start keepalived
scp keepalived.conf 192.168.13.40:`pwd`
ipvsadm-save > /etc/sysconfig/ipvsadm
systemctl restart keepalived
ipvsadm -ln

1.3 Standby load balancing server

yum install -y ipvsadm keepalived
cd /etc/keepalived/
vim keepalived.conf
	12 That's ok :router_id LVS_02
	16 That's ok :state BACKUP
	20 That's ok :priority 90
systemctl start keepalived
ipvsadm-save > /etc/sysconfig/ipvsadm
systemctl start ipvsadm
systemctl restart keepalived
ipvsadm -ln

1.4 test

  • 1、 Web access 192.168.13.100, Generate load balancing effect
  • 2、 Main load :systemctl stop keepalived,VIP Address jumps to standby load balancer (ip addr see )

Two 、 Load balancer profile template

! Configuration File for keepalived

global_defs {
    
   notification_email {
    
     [email protected].loc
     [email protected].loc
     [email protected].loc
   }
   notification_email_from Alexandre.[email protected].loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_01
}

vrrp_instance VI_1 {
    
    state MASTER
    interface ens33
    virtual_router_id 51
    nopreempt
    priority 100
    advert_int 1
    authentication {
    
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    
        192.168.13.100
    }
}

virtual_server 192.168.13.100 80 {
    
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 0
    protocol TCP

    real_server 192.168.13.20 80 {
    
        weight 1
        TCP_CHECK{
    
        connect_port 80
        connect_timeout 3
        nb_get_retry 3
        delay_before_retry 3
        }
    }
    real_server 192.168.13.30 80 {
    
        weight 1
        TCP_CHECK{
    
        connect_port 80
        connect_timeout 3
        nb_get_retry 3
        delay_before_retry 3
        }
    }

3、 ... and 、 Conclusion

  • Good mentality
原网站

版权声明
本文为[Sprite, don't be angry]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110729301723.html