当前位置: 首页 > Linux

安装部署keepalived的HA环境

时间:2023-04-06 11:33:27 Linux

每台配置下keepalived#master01配置:cat>/etc/keepalived/keepalived.conf<<"EOF"!keepalivedglobal_defs{router_idLVS_DEVELscript_userrootenable_script_security}vrrp_scriptchk_apiserver{script"/etc/keepalived/check_apiserver.sh"interval5weight-5fall2rise1#检测一次成功,则认为在线}vrrp_instanceVI_1{stateBACKUPnopreemptinterfaceens160mcast_src_ip10.0.0.20virtual_router_id51priority100advert_int2authentication{auth_typePASSauth_passK8SHA_KA_AUTH}virtual_ipaddress{10.0.0.30}track_script{chk_apiserver}}EOF#Master02配置:cat>/etc/keepalivedconf."!<"keepalived/"!keepalivedglobal_defs的配置文件{router_idLVS_DEVELscript_userrootenable_script_security}vrrp_scriptchk_apiserver{script"/etc/keepalived/check_apiserver.sh"interval5weight-5fall2rise1}vrrp_instanceVI_1{stateBACKUPnopreemptinterfaceens160mcast_src_ip10.0.0.21virtual_router_id51priority99advert_int2authentication{auth_typePASSauth_passK8SHA_KA_AUTH}virtual_ipaddress{10.0.0.30}track_script{chk_apiserver/etcdatep0:EOF#Master/keepalived.conf<<“EOF”!keepalivedglobal_defs的配置文件{router_idLVS_DEVELscript_userrootenable_script_security}vrrp_scriptchk_apiserver{script"/etc/keepalived/check_apiserver.sh"interval5weight-5fall2rise1}vrrp_instanceVI_1{stateBACKUPnopreemptinterfaceens160mcast_src_ip10.0.0.22virtual_router_id51priority98advert_int2authentication{auth_typePASSauth_passK8SHA_KA_AUTH}virtual_ipaddress{10.0.0.30}track_script{chk_apiserver}EOF健康检查脚本cat>/etc/keepalived/check_apiserver.sh<<"EOF"#!/bin/basherr=0forkin$(seq13)docheck_code=$(pgrephaproxy)if[[$check_code==""]];然后err=$(expr$err+1)sleep1continueelseerr=0breakfidoneif[[$err!="0"]];然后echo"systemctlstopkeepalived"/usr/bin/systemctlstopkeepalivedexit1elseexit0fiEOFchmodu+x/etc/keepalived/check_apiserver.shstartservicesystemctldaemon-reloadsystemctlenable--nowkeepalivedhttps://www.oiox.cn/https://www.chenby.cn/https://cby-chen.github.io/https://weibo.com/u/5982474121https://blog.csdn.net/qq_3392…https://my.oschina.net/u/3981543https://www.zhihu.com/people/...https://segmentfault.com/u/hp...https://juejin.cn/user/331578...https://space.bilibili.com/35...https://cloud.tencent.com/dev...https://www.jianshu.com/u/0f8...https://www.toutiao.com/c/use...CSDN、GitHub、知乎、开源中国、师傅、掘金、简书、腾讯云、哔哩哔哩、今日头条、新浪微博、个人博客,全网可搜索《小陈运维》