企业级负载均衡集群---LVS+keepalived健康检测(三)

1.实验前提

宿主机、
VS : server1&server2、
RS : server3&server4、

2.实验步骤

1.环境搭建:

在server1、server2中:

ipvsadm -C					 #清除IPVS中的IP
ipvsadm -ln
ipaddr show del 172.25.10.100/24 dev eth0  	#删除vip
yum install keepalived -y
vim /etc/keepalived/keepalived.conf 		#编写keepalived的配置文件

编写server1的keepalived配置文件:

! Configuration File for keepalived

global_defs {   
    notification_email {     
	root@localhost   
	}	
	notification_email_from keepalived@localhost   	
	smtp_server 127.0.0.1   
	smtp_connect_timeout 30   
	router_id LVS_DEVEL   
	vrrp_skip_check_adv_addr   、
	#vrrp_strict   
	vrrp_garp_interval 0   
	vrrp_gna_interval 0
}
vrrp_instance VI_1 {    
	state MASTER    
	interface eth0    
	virtual_router_id 61
	priority 100    
	advert_int 1    
	authentication {        
	auth_type PASS        
	auth_pass 1111    
}    
	virtual_ipaddress {        
	172.25.10.100    
   }
}

virtual_server 172.25.10.100 80 {    
	delay_loop 6    
	lb_algo rr    
	lb_kind DR    
	#persistence_timeout 50    
	protocol TCP     
	
   real_server 172.25.10.3 80 {        
	weight 1        
	TCP_CHECK {            
	connect_timeout 3            
	nb_get_retry 3            
	delay_before_retry 3        
	}    
   }
   real_server 172.25.10.4 80 {       
	 weight 1        
	 TCP_CHECK {            
	 connect_timeout 3            
	 nb_get_retry 3            
	 delay_before_retry 3        
	 }    
   }
}

编写server2的keepalived配置文件:

! Configuration File for keepalived

global_defs {   
    notification_email {     
	 root@localhost   
  } 
    notification_email_from keepalived@localhost    
    smtp_server 127.0.0.1   
    smtp_connect_timeout 30   
    router_id LVS_DEVEL   
    vrrp_skip_check_adv_addr   、
    #vrrp_strict   
    vrrp_garp_interval 0   
    vrrp_gna_interval 0
}
vrrp_stance VI_1 {    
    state BACKUP    
    interface eth0   
    virtual_router_id 61    
    priority 50    
    advert_int 1    
    authentication {        
    auth_type PASS        
    auth_pass 1111    
  }    
  virtual_ipaddress {        
  172.25.10.100    
  }
}
virtual_server 172.25.10.100 80 {    
    delay_loop 6    
    lb_algo rr    
    lb_kind DR    
    #persistence_timeout 50    
    protocol TCP

real_server 172.25.10.3 80 {        
    weight 1        
    TCP_CHECK {            
    connect_timeout 3            
    nb_get_retry 3            
    delay_before_retry 3        
       }    
    }

real_server 172.25.10.4 80 {        
    weight 1        
    TCP_CHECK {            
    connect_timeout 3            
    nb_get_retry 3            
    delay_before_retry 3        
      }    
    }
}

在server1和server2中:

systemctl restart keepalived.service
tail -f /var/log/messages
ipvsadm -ln 			 #查看ip是否配置完成

2.健康检测:
在server3中:

systemctl stop httpd

在宿主机:

curl 172.25.10.100
#server3的服务已经关闭,通过此命令发现只显示vm4

在server1:

ipvsadm -ln
#查看此时的ip策略

mail
查看邮件信息,会提示server3已经down掉

再在server3中:

systemctl restart httpd
#重启httpd,并在主机中测试curl 172.25.10.100,轮询显示vm3和vm4

3.冗余检测
在server1中:

systemctl stop keepalived

在server2中:

tail -f /var/log/messages
#发现server2已接管server3

在主机中:

curl 172.25.10.11
#发现可正常轮训server3和server4
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页