ipvs+ldirectord实现高可用ipvs
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ipvs+ldirectord实现高可用ipvs相关的知识,希望对你有一定的参考价值。
一、heartbeat准备
1、接上文HA集群准备工作
2、 安装heartbeat-ldirectord组件包
[[email protected] heartbeat]# yum localinstall heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm
3、ldirectord组件简介
ldirectord依赖于自己的配置文件来生成ipvs的规则,因此,定义LVS集群、添加RS都是在ldirectord的配置文件中指定,而无需手动执行ipvsadm命令。ldirectord对LVS集群的director高可用,并对LVS进群的RS提供健康状态监测,若某节点出现故障,则会把它从集群系统中剔除,并在其回复正常后,将它重新加入集群系统。ldirectord还可以调用ipvsadm命令创建LVS路由表信息,只需要在/etc/ha.d/ldirectord.cf配置文件中指明即可。
4、基本信息
二、配置
RS:
1、准备RS脚本 #!/bin/bash vip=192.168.0.17 interface="lo:0" case $1 in start) echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce ifconfig $interface $vip broadcast $vip netmask 255.255.255.255 up route add -host $vip dev $interface ;; stop) echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 0 > /proc/sys/net/ipv4/conf/eth0/arp_ignore echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce echo 0 > /proc/sys/net/ipv4/conf/eth0/arp_announce ifconfig $interface down ;; status) if ifconfig lo:0 | grep $vip &> /dev/null; then echo "ipvs is running." else echo "ipvs is stopped." fi ;; *) echo "please input : `basename $0` {start|stop|status}" exit 1 esac [[email protected] ~]# chmod +x rs.sh 2、准备httpd [[email protected] ~]# yum install httpd [[email protected] ~]# echo "This is RS" > /var/www/html/index.html [[email protected] ~]# service httpd start [[email protected] ~]# curl 192.168.0.20 This is RS [[email protected] ~]# ./rs.sh start
主备Director测试
[[email protected] ~]# ifconfig eth0:0 192.168.0.17 broadcast 192.168.0.17 netmask 255.255.255.255 up [[email protected] ~]# route add -host 192.168.0.17 dev eth0:0 [[email protected] ~]# ipvsadm -A -t 192.168.0.17:80 -s rr [[email protected] ~]# ipvsadm -a -t 192.168.0.17:80 -r 192.168.0.20 -g
[[email protected] ~]# ipvsadm -C [[email protected] ~]# route del -host 192.168.0.17 [[email protected] ~]# ifconfig eth0:0 down
主Director:node1配置
1、cp样例配置文件 [[email protected] ~]# cd /usr/share/doc/heartbeat-ldirectord-2.1.4/ [[email protected] heartbeat-ldirectord-2.1.4]# cp ldirectord.cf /etc/ha.d [[email protected] heartbeat-ldirectord-2.1.4]# cd /etc/ha.d 2、配置文件 ##全局配置 # Global Directives ##健康状态检测超时时间间隔 checktimeout=3 ##每一秒检查一次 checkinterval=1 #fallback=127.0.0.1:80 ##自动装载配置文件 autoreload=yes ##日志文件 logfile="/var/log/ldirectord.log" ##日志文件级别 #logfile="local0" ##邮件通知警告信息 #emailalert="[email protected]" ##邮件通知间隔1小时 #emailalertfreq=3600 ##邮件通知所有的状态信息 #emailalertstatus=all ##是否工作于静默模式 quiescent=yes ##虚拟服务配置 # Sample for an http virtual service ##VIP virtual=192.168.0.17:80 ##RS gate为dr类型 real=192.168.0.20:80 gate #real=192.168.6.3:80 gate #real=192.168.6.6:80 gate ##backserver fallback=127.0.0.1:80 gate ##健康状态检查基于http协议 service=http ##请求的页面 request=".health.html" ##检查request=“”页面中的字符串是否一致 receive="" ##对多个虚拟主机进行检查 virtualhost=some.domain.com.au ##调度类型为rr scheduler=rr ##持久连接时长 #persistent=600 ##掩码 #netmask=255.255.255.255 ##基于tcp的检查,集群服务类型 protocol=tcp ##检查类型为交互式检查 ##checktype:connect是传输层检查,ping是网络层检查,negotlate是应用层检查 ##当checktype=negotlate时,ldirectord将基于指定的协议与各RS建立连接,完成应用层检查 checktype=negotia ##检查端口为80 checkport=80 ##请求的页面 request="index.html" ##请求的字符串检查 #receive="Test Page" ##对虚拟主机检查 #virtualhost= 3、准备web服务,node1作为back server提供sorry server服务 [[email protected] ha.d]# vim /var/www/html/index.html This is sorry server(node1) [[email protected] ha.d]# service httpd start Starting httpd: httpd: Could not reliably determine the server‘s fully qualified domain name, using 192.168.0.15 for ServerName [ OK ] [[email protected] ha.d]# curl 192.168.0.15 This is sorry server(node1) 4、将配置文件cp给node2 [[email protected] ha.d]# scp ldirectord.cf node2:/etc/ha.d/
备Director:node2配置
[[email protected] ~]# vim /var/www/html/index.html This is sorry server(node2) [[email protected] ~]# service httpd start Starting httpd: httpd: Could not reliably determine the server‘s fully qualified domain name, using 192.168.0.16 for ServerName [ OK ] [[email protected] ~]# curl 192.168.0.16 This is sorry server(node2)
RS准备测试页
[[email protected] ~]# echo "ok" > /var/www/html/.health.html
启动服务
[[email protected] ~]# service heartbeat start; ssh node2 ‘service heartbeat start‘
gui界面配置资源
1、定义资源组ipvs,定义集群ip资源(vip)
2、定义ipvs规则,lsb格式不提供参数,ocf格式的资源代理须提供配置文件
3、启动资源
4、验证node2节点
[[email protected] ~]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.0.17:80 rr -> 192.168.0.20:80 Route 1 0 0 [[email protected] ~]# ip add show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:15:ea:32 brd ff:ff:ff:ff:ff:ff inet 192.168.0.16/24 brd 192.168.0.255 scope global eth0 inet 192.168.0.17/24 brd 192.168.0.255 scope global secondary eth0 inet6 fe80::20c:29ff:fe15:ea32/64 scope link valid_lft forever preferred_lft forever
5、验证负载均衡集群效果
6、检测RS下线,director错误页面
[[email protected] ~]# mv /var/www/html/.health.html /var/www/html/a.html [[email protected] ~]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.0.17:80 rr -> 127.0.0.1:80 Local 1 0 0 -> 192.168.0.20:80 Route 0 0 0
同理检查node1。
本文出自 “linux启航” 博客,请务必保留此出处http://jiayimeng.blog.51cto.com/10604001/1874717
以上是关于ipvs+ldirectord实现高可用ipvs的主要内容,如果未能解决你的问题,请参考以下文章