LVS实现健康性检查Ldirectord使用

独立的lvs并不具备对后端服务器执行健康检查的机制,这时通常需要配合第三方的工具来一起使用。
而ldirectord的作用就是用来监测Real Server,当Real Server失效时,把它从虚拟服务器列表中删除,恢复时重新添加到列表。

1.LVS不可用,整个系统将不可用;SPoF Single Point of Failure
解决方案:高可用
	keepalived heartbeat/corosync

2.RS不可用时,Director依然会调度请求至此RS
解决方案: 由Director对各RS健康状态进行检查,失败时禁用,成功时启用
	keepalived  heartbeat/corosync   ldirectord
	检测方式:
	(a) 网络层检测,icmp
	(b) 传输层检测,端口探测
	(c) 应用层检测,请求某关键资源
	RS全不用时:backup server, sorry server

 Idirectord 软件和配置文件说明:

包名:ldirectord-3.9.6-0rc1.1.1.x86_64.rpm 
下载:http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/x86_64/
安装:yum install ldirectord-3.9.6-0rc1.1.2.x86_64.rpm -y  (需要epel源中的Perl)

文件:
	/etc/ha.d/ldirectord.cf 主配置文件
	/usr/share/doc/ldirectord-3.9.6/ldirectord.cf 配置模版
	/usr/lib/systemd/system/ldirectord.service 服务
	/usr/sbin/ldirectord 主程序,Perl实现
	/var/log/ldirectord.log 日志
	/var/run/ldirectord.ldirectord.pid pid文件


Ldirectord配置文件说明
checktimeout=20           #判定real server出错的时间间隔。
checkinterval=10          #指定ldirectord在两次检查之间的间隔时间。
fallback=127.0.0.1:80     #当所有的real server节点不能工作时,web服务重定向的地址。
autoreload=yes            #是否自动重载配置文件,选yes时,配置文件发生变化,自动载入配置信息。
logfile="/var/log/ldirectord.log"   #设定ldirectord日志输出文件路径。
logfile="local0"		    #rsyslog方式定义日志输出。

quiescent=no              			#当RS服务down时状态时, yes权重设为0,no为删除RS服务器。
当选择no时,如果一个节点在checktimeout设置的时间周期内没有响应,ldirectord将会从LVS的路由表中直接移除real server,此时,将中断现有的客户端连接,并使LVS丢掉所有的连接跟踪记录和持续连接模板,
如果选择为yes,当某个real server失效时,ldirectord将失效节点的权值设置为0,新的连接将不能到达,但是并不从LVS路由表中清除此节点,同时,连接跟踪记录和程 序连接模板仍然保留在Director上。
virtual=5 			    #指定虚拟的IP地址和端口号,FWM(标签)或 IP:PORT
virtual=192.168.60.200:80           #指定虚拟的IP地址和端口号
   real=192.168.60.132:80 gate      #指定Real Server服务器地址和端口,同时设定LVS工作模式,用gate表示DR模式,ipip表示TUNL模式,masq表示NAT模式。
   real=192.168.60.144:80 gate
   fallback=127.0.0.1:80 gate       #sorry server
   service=http                     #指定服务的类型,这里是对http服务做负载均衡。
   request="index.html"             #ldirectord将根据指定的RealServer地址,结合该选项给出的请求路径,发送访问请求,检查RealServer上的服务是否正常运行,确保这里给出的页面地址是可访问的,不然ldirectord会误认为此节点已经失效,发生错误监控现象。
   receive="Test Page"              #指定请求和应答字串。
   scheduler=rr                     #指定调度算法,这里是rr(轮叫)算法。
   protocol=tcp                     #指定协议的类型,LVS支持TCP和UDP协议。
   checktype=negotiate              #指定Ldirectord的检测类型,默认为negotiate。
   checkport=80                     #指定监控的端口号。
   persistence=360                  #持久连接
   virtualhost=www.gaojf.com        #虚拟服务器的名称,随便指定

  案例图:

 

 

前期规则设置(参考: 实践LVS的DR模式,lvs与rs不同网段)
CIP:192.168.10.50      gateway:192.168.10.60 
Route: eth0(192.168.10.60)    eth0(192.168.80.60 、10.0.0.200/8 ) 启用IP_forward的功能
LVS:DIP:192.168.80.100  gateway:192.168.80.60   VIP: 10.0.0.100/32    gateway和VIP两个IP绑定在同一个网卡上
RS1: RIP:192.168.80.110  gateway:192.168.80.60   VIP: 10.0.0.100/32	 VIP绑定在lo
RS2: RIP:192.168.80.120  gateway:192.168.80.60   VIP: 10.0.0.100/32	 VIP绑定在lo


Route设置
ip a a  10.0.0.200/8 dev eth0   与80.60同一网卡上。
		

LVS服务器设置:
设置VIP地址   
	ip addr add  10.0.0.100/8 dev eth0 

RS的服务器设置:
	echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
	echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
	echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
	echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
两台RS设置VIP地址
	ip addr add 10.0.0.100/8 dev lo:1

安装sorry Sever服务器,和 ldirectord服务
	yum install ldirectord-3.9.6-0rc1.1.2.x86_64.rpm -y
	yum install httpd -y
	echo Sorry Server > /var/www/html/index.html
	systemctl start httpd
清空规则,复制配置文件模版
	ipvsadm -C   
	cp /usr/share/doc/ldirectord-3.9.6/ldirectord.cf /etc/ha.d/
设置配置文件
Ldirectord配置文件说明
	checktimeout=3     				#检查RS次数
	checkinterval=1    				#检查RS时间
	autoreload=yes
	logfile=“/var/log/ldirectord.log“ #日志文件
	#logfile="local0"				  #日志级别
	quiescent=no 					  #当RS服务down时状态时, yes权重设为0,no为删除RS服务器。
virtual=10.0.0.100:80
	real=192.168.80.110:80 gate 2		#gate指DR模型,权重为 2 
	real=192.168.80.120:80 gate 1
	fallback=127.0.0.1:80 gate		    #sorry server, 当两个RS服务器出现问题,LVS的提示。
	service=http
	scheduler=wrr
	protocol=tcp
	checktype=negotiate
	checkport=80
	request="index.html"


# systemctl restart ldirectord.service 


 while true ; do curl http://10.0.0.100 ;sleep 1; done    systemectl stop httpd 测试
192.168.80.120
192.168.80.110
192.168.80.120
192.168.80.110
192.168.80.120
192.168.80.120
sorry services
sorry services

  

 

posted @ 2022-08-02 19:33  yuanbangchen  阅读(325)  评论(0编辑  收藏  举报