# Lvs健康检测

> 来源：梦飞idc云平台 | 原文：https://www.mfisp.com/12181.html | 发布：2022-11-04 | 更新：2022-11-04 | 分类：建站教程、投稿分享

## Lvs健康检测

 

1. 调度器正常的情况下将server2的Apache服务停止使得  
这样的话使用轮询呼叫会出现一半无法成功访问，但是调度器显示是正常的  
2. VS出现问题了则整个服务无法访问出现问题，整个网络无法访问

 

## 1.实验环境搭建

 

| 主机 | 作用 |
|---|---|
| server1 | 主VS |
| server2 | 后端RS节点 |
| server3 | 后端RS节点 |
| server4 | 从VS |

  

主VS

 

yum install keepalived -y  
ipvsadm -C #清空调度策略

  

从VS

 

yum install keepalived -y

 

## 2.VS端配置文件编写

 

vim /etc/keepalived/keepalived.conf  
global_defs {  
 notification_email {  
 root@localhost #邮件发送到谁的所在位置  
 }  
 notification_email_from keepalived@localhost #本地发送的邮件使用什么名义进行发送  
 smtp_server 127.0.0.1 #改为回环接口的IP  
 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 #MASTER表示为主节点BACKUP为从节点  
 interface eth0 #本地网卡名称显示什么用什么  
 virtual_router_id 51 #一个集群的标志同一个集群使用一个编号  
 priority 100 #节点的有优先级越高越优先  
 advert_int 1  
 authentication {  
 auth_type PASS  
 auth_pass 1111  
 }  
 virtual_ipaddress {  
 172.25.254.100/24 #设置本地的vip不加PREFIX则默认为32  
 }  
}

 

virtual_server 172.25.254.100 80 { #表示访问172.25.254.100的80端口  
 delay_loop 6  
 lb_algo rr #设定调度算法  
 lb_kind DR #表示使用什么模式  
 #persistence_timeout 50  
 protocol TCP

 

real_server 172.25.254.92 80 { #添加后端的RS  
 weight 1  
 TCP_CHECK {  
 connect_timeout 3  
 delay_before_retry 3  
 }  
 }  
 real_server 172.25.254.93 80 {  
 weight 1  
 TCP_CHECK {  
 connect_timeout 3  
 delay_before_retry 3  
 }  
 }  
}

  

从VS节点中

 

state MASTER #改为state BACKUP  
priority 100 #优先级必须小于100

 

## 2.测试部分

 

主VSserver1down掉

 

![Lvs健康检测](https://www.mfisp.com/wp-content/uploads/2021/10/20221104114619huYmzH.jpeg)

 

![Lvs健康检测](https://www.mfisp.com/wp-content/uploads/2021/10/20221104114634hWuQmY.jpeg)

 

![Lvs健康检测](https://www.mfisp.com/wp-content/uploads/2021/10/20221104114752mVCdQv.jpeg)

 

![Lvs健康检测](https://www.mfisp.com/wp-content/uploads/2021/10/20221104114807ACj91E.jpeg)

 

当把后端的RS节点down掉后keepalived随即会更改策略将访问调度到另外一个RS上进行调度

 

![Lvs健康检测](https://www.mfisp.com/wp-content/uploads/2021/10/20221104114912wTpboH.png)

 

![Lvs健康检测](https://www.mfisp.com/wp-content/uploads/2021/10/20221104114924gux7ew.png)

---
本页由 梦飞idc云平台（https://www.mfisp.com）提供。站点导航见 https://www.mfisp.com/llms.txt
