LVS--DR模式下的健康检测(ldirectord)

在生产工作中,我们的服务器并不是一致都处于健康状态
有服务器出现故障时,系统会自动剔除该服务器,其他的服务器接替
它的工作,使得用户访问不受影响
当服务器故障排除时,系统将会自动添加该服务器,服务器继续正常工作

LVS/ldirectord
通过直接路由实现虚拟服务
客户端向目标vip发出请求,lvs接收 ,LVS根据负载均衡算法选择一台活跃的的节点,将此节点的ip所在网卡的mac地址作为目标mac地址,发送到局域网里
节点在局域网中收到这个帧,拆开后发现目标IP(VIP)与本地匹配,于是处理这个报文.随后重新封装报文,发送到局域网.此时IP包的目标ip是客户端,源ip是自己的vip地址。

实验具体操作
实验条件
一台LVS服务器,二台Apache后端服务器,一台测试机,共4台主机

实验环境
Redhat7.3版本下实验,关闭防火墙及selinux
DS lvs调度器服务器
RS后端真实主机服务器
CS客户端服务器
DS服务器

主机名server1 eth0网卡ip:192.168.0.1/24
RS服务器1 主机名server2 ip:192.168.0.2/24
RS服务器2 主机名server3 ip:192.168.0.3/24
主机名client ip:192.168.0.10/24

实验目标
使用ldirectord搭建web群集,作为健康体检,实现负载均衡和高可用

实验要求
1、添加VIP
2、安装lvs管理工具——ipvsadm服务
3、设置arptables的访问策略
4、 RS服务器搭建apache资源
5、 安装 ldirectord
5、 CS客户测试端测试

实验步骤
server1>>>
eth0上添加VIP

ip addr add 192.168.0.100/24 dev eth0

安装ipvsadm
yum install ipvsadm -y
添加策略
ipvsadm -A -t 192.168.0.100:80 -s rr
ipvsadm -a -t 192.168.0.100:80 -r 192.168.0.2:80 -g -w 1
ipvsadm -a -t 192.168.0.100:80 -r 192.168.0.3:80 -g -w 1

server2>>>
eth0上添加VIP
ip addr add 192.168.0.100/24 dev eth0

设置arptables的访问策略
安装 arptables
yum install -y arptables
192.168.0.100来源输入全部丢弃
arptables -A INPUT -d 192.168.0.100 -j DROP
192.168.0.100输出转化为192.168.0.2
arptables -A OUTPUT -s 192.168.0.100 -j mangle --mangle-ip-s192.168.0.2
查看规则
cat /etc/sysconfig/arptables
保存策略
arptables-save > /etc/sysconfig/arptables
再次查看,策略已保存
cat /etc/sysconfig/arptables
重启服务
systemctl restart arptables

server3>>>
eth0上添加VIP
ip addr add 192.168.0.100/24 dev eth0

设置arptables的访问策略
安装 arptables
yum install -y arptables
192.168.0.100来源输入全部丢弃
arptables -A INPUT -d 192.168.0.100 -j DROP
192.168.0.100输出转化为192.168.0.3
arptables -A OUTPUT -s 192.168.0.100 -j mangle --mangle-ip-s192.168.0.3
查看规则
cat /etc/sysconfig/arptables
保存策略
arptables-save > /etc/sysconfig/arptables
再次查看,策略已保存
cat /etc/sysconfig/arptables
重启服务
systemctl restart arptables

server2及server3设置apache
server2>>>
下载apache
yum install httpd -y
启动
systemctl start httpd
echo server2 > /var/www/html/index.html
systemctl restart httpd

server3>>>
安装apache
yum install httpd -y
启动
systemctl start httpd
echo server3 > /var/www/html/index.html
systemctl restart httpd

安装 ldirectord
yum install -y ldirectord-*.rpm
该安装包需要高可用 HighAvailability 安装源
查看配置文件
rpm -qpl ldirectord-3.9.5-3.1.x86_64.rpm
复制配置文件到配置目录
cp /usr/share/doc/ldirectord-3.9.5/ldirectord.cf /etc/ha.d
编辑配置文件
vim /etc/ha.d/ldirectord.cf
virtual=192.168.0.100:80
real=192.168.0.2:80 gate
real=192.168.0.3:80 gate
fallback=127.0.0.1 gate
service=http
scheduler=rr
protocol=tcp
checktype=negotiate
checkport=80
request=“index.html”
启动
/etc/init.d/ldirectord start

安装 apache
yum install -y httpd
开启
systemctl start httpd
开机自启
systemctl enable httpd
编辑
vim /var/www/html/index.html
gameover!!!
重启
systemctl restart httpd

CS客户测试端>>>
测试
访问192.168.0.100可以看到 server2 与 server3 轮流响应请求
curl 192.168.0.100
server2
curl 192.168.0.100
server3
关闭server2的apache服务自动跳转server3
curl 192.168.0.100
server3
全部关闭显示srever1的apache内容
curl 192.168.0.100
gameover!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值