利用Keepalived实现VIP+LVS+后端状态检测(TCP检测或HTTP检测)

更新时间:2023-07-15 03:11:17 阅读: 评论:0

利⽤Keepalived实现VIP+LVS+后端状态检测(TCP检测或HTTP检测)⼀、实验环境
VIP+LVS 服务器:10.0.0.11(keepalived-1)、10.0.0.12(keepalived-2)
nginx服务器:10.0.0.13(nginx-web-1)、10.0.0.14(nginx-web-2)
VIP:10.0.0.100
⼆、VIP配置
keepalived-1 配置
[root@keepalived-1 ~]# mkdir /etc/keepalived/conf/
[root@keepalived-1 ~]# vim /etc/f
global_defs {
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
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}数学家
virtual_ipaddress {
10.0.0.100 dev eth0 label eth0:0
}
}
include /etc/keepalived/conf/*.conf
[root@keepalived-1 ~]# systemctl restart keepalived.rvice
keepalived-2 配置
[root@keepalived-2 ~]# mkdir /etc/keepalived/conf/
[root@keepalived-2 ~]# vim /etc/f global_defs {
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
时间曲线}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.100 dev eth0 label eth0:0
experience}
}
include /etc/keepalived/conf/*.conf
emotionless
[root@keepalived-2 ~]# systemctl restart keepalived.rvice 三、Nginx配置访问页⾯
nginx-web-1 配置
[root@nginx-web-1 ~]# vim /apps/nginx/html/index.html 10.0.0.13-nginx-web1
nginx-web-2 配置
[root@nginx-web-2 ~]# vim /apps/nginx/html/index.html 10.0.0.14-nginx-web2
四、LVS配置
keepalived-1 配置
lb_kind DR
persistence_timeout 120
protocol TCP
sorry_rver 10.0.0.101 80
real_rver 10.0.0.13 80 {
weight 1
TCP_CHECK {
connect_timeout 5
成绩查询入口nb_get_retry 3
delay_before_retry 3
}
}
real_rver 10.0.0.14 80 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@keepalived-1 ~]# systemctl restart keepalived.rvice
[root@keepalived-1 ~]# ipvsadm -Ln    #查看LVS配置是否⽣效,加上--stats可以查看更详细的信息IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port          Forward Weight ActiveConn InActConn
TCP  10.0.0.100:80 wrr persistent 120
-> 10.0.0.13:80                Route  1      0          0
-> 10.0.0.14:80                Route  1      0          0
keepalived-2 配置
lb_kind DR
persistence_timeout 120
protocol TCP
sorry_rver 10.0.0.101 80
real_rver 10.0.0.13 80 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
}
}
real_rver 10.0.0.14 80 {
weight 1
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@keepalived-2 ~]# systemctl restart keepalived.rvice
[root@keepalived-2 ~]# ipvsadm -Ln
kingbrightIP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port          Forward Weight ActiveConn InActConn TCP  10.0.0.100:80 wrr persistent 120
-> 10.0.0.13:80                Route  1      0          0
-> 10.0.0.14:80                Route  1      0          0
nginx-web-1 在RS上配置VIP,实现DR功能
[root@nginx-web-1 ~]# vim lvs_dr_rs.sh
LVS_VIP=10.0.0.100
source /etc/rc.d/init.d/functions
ca"$1"in
start)
/sbin/ifconfig lo:0 $LVS_VIP netmask 255.255.255.255 broadcast $LVS_VIP    /sbin/route add -host $LVS_VIP dev lo:0
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
sysctl -p > /dev/null 2>&1
echo"Real Server Start OK!"
;;
hobbyist
stop)
/sbin/ifconfig lo:0 down
/sbin/route del $LVS_VIP> /dev/null 2>&1
echo"0"> /proc/sys/net/ipv4/conf/all/arp_ignore
echo"0"> /proc/sys/net/ipv4/conf/lo/arp_ignore
echo"0"> /proc/sys/net/ipv4/conf/all/arp_announce
echo"0"> /proc/sys/net/ipv4/conf/lo/arp_announce
echo"Real Server Stoped!"
;;
*)
echo"Usage: (baname0) start|stop"
exit 1
;;
esac
[root@nginx-web-1 ~]# bash lvs_dr_rs.sh start
Real Server Start OK!
nginx-web-2 在RS上配置VIP,实现DR功能
[root@nginx-web-2 ~]# vim lvs_dr_rs.sh
LVS_VIP=10.0.0.100
source /etc/rc.d/init.d/functions
ca"$1"in
start)
/sbin/ifconfig lo:0 $LVS_VIP netmask 255.255.255.255 broadcast $LVS_VIP    /sbin/route add -host $LVS_VIP dev lo:0obeis
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
sysctl -p > /dev/null 2>&1
echo"Real Server Start OK!"
;;
stop)
square怎么读/sbin/ifconfig lo:0 down
/sbin/route del $LVS_VIP> /dev/null 2>&1
echo"0"> /proc/sys/net/ipv4/conf/all/arp_ignore
echo"0"> /proc/sys/net/ipv4/conf/lo/arp_ignore
echo"0"> /proc/sys/net/ipv4/conf/all/arp_announce
echo"0"> /proc/sys/net/ipv4/conf/lo/arp_announce
echo"Real Server Stoped!"
;;
*)
echo"Usage: (baname0) start|stop"
exit 1
;;
esac
[root@nginx-web-2 ~]# bash lvs_dr_rs.sh start
Real Server Start OK!

本文发布于:2023-07-15 03:11:17,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/177779.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:检测   配置   实现
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图