小言_互联网的博客

企业-LVS实现健康检测(DR模式)

181人阅读  评论(0)

如果一个服务器宕机,访问的链接将时好时坏,这时就需要通过调度器对后端服务器进行健康检查

高可用:(两个web挂掉之后)

配置server1高可用的yum源

[HighAvailability]
name=HighAvailability
baseurl=http://172.25.254.38/rhel7.3/addons/HighAvailability
gpgcheck=0



server1:
下载:ldirectord-3.9.5-3.1.x86_64.rpm安装包

yum install -y ldirectord-3.9.5-3.1.x86_64.rpm			配好yum源再安装可以解决ldirectord的依赖性


rpm -qa |grep ldirectord
rpm -ql ldirectord-3.9.5-3.1.x86_64				查看配置文件

ll /etc/init.d/ldirectord
file /etc/init.d/ldirectord						查看文件类型,是一个脚本

yum install -y httpd
vim /var/www/html/index.html		编辑httpd默认发布页面,若后端服务器都宕机,此时代理服务器也可以提供服务
网页正在维护...
systemctl restart httpd

ipvsadm -C
ipvsadm -ln
modprobe -r ipip			删除隧道模块
ip addr del 172.25.38.100/24 dev tunl0
ipvsadm -A -t 172.25.38.100:80 -s rr
ipvsadm -a -t 172.25.38.100:80 -r 172.25.38.3:80 -g
ipvsadm -a -t 172.25.38.100:80 -r 172.25.38.2:80 -g

vim  /etc/ha.d/ldirectord.cf		

virtual=172.25.38.100:80
        real=172.25.38.2:80 gate	两个RS
        real=172.25.38.3:80 gate
        fallback=127.0.0.1:80 gate	表示调度器自己的回环接口,两台RS都挂了就访问这个

/etc/init.d/ldirectord restart


server2 & server3:

modprobe -r ipip			删除隧道模块
ip addr add 172.25.38.100/24 dev eth0



真机测试:

curl 172.25.38.100


如果不轮询:因为客户端存储了真实服务器的地址,MAC地址是server2的

客户端:

arp -an |grep 100		查看主机mac地址


arp -d 172.25.29.100		清理缓存


客户端进行访问的时候,因为DS和RS在同一IP对外提供服务,所以MAC地址会随机选取,后端谁抢到就是谁的
所以产生一个问题,客户端访问时会访问到RS,没有访问到LVS代理服务器。从而使RS访问量过大

server2 & server3:

yum install arptables -y

arptables -L					查看火墙策略
arptables -A INPUT -d 172.25.29.100 -j DROP	对于100的访问拒绝不回应
arptables -A OUTPUT -s 172.25.29.100 -j mangle --mangle-ip-s 172.25.29.2	让访问100的ip出去是29.2
arptables-save > /etc/sysconfig/arptables	将策略保存


清除缓存的MAC地址后发现访问到LVS代理服务器

web1坏掉,自动踢出集群


web1和web2都坏掉


发现lvs的http服务



转载:https://blog.csdn.net/weixin_45368526/article/details/101703948
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场