Hello! 欢迎来到阿波的世界

keepalived高可用


avatar
ljb 2024-11-30 19

安装环境为ROCKY9

yum y install keepalived

高可用的配置文件为

/etc/keepalived/keepalived.conf

需要配置以下内容:

! Configuration File for keepalived

 

global_defs {

router_id nginx1 #matser和backup这里不同

}

vrrp_script check_nginx { #将所有nginx设为高可用,当这台nginx挂掉的时候,停止keepalived服务,vip漂移到别的backup上

script “/etc/keepalived/nginx.sh” #脚本所在位置,记得加执行权限

interval 5

fall 2

rise 2 #自己执行2遍脚本,判断服务挂没挂

weigth 60

}

vrrp_instance VI_1 {

state MASTER 这台keepalivedmaster

interface ens33

virtual_router_id 80 #同一组keepalived这里要一样

priority 100 #优先级为100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.107.200/24 #添加的虚拟ip

}

track_script { #执行上面添加的脚本

check_nginx

}

}

check_nginx脚本内容:

复制代码

#!/bin/bash

curl localhost &>/dev/null

if [ $? ne 0 ];then

systemctl stop keepalived

fi

暂无评论

发表评论
AbosLove