This commit is contained in:
zeaslity
2024-10-30 16:30:51 +08:00
commit 437acbeb63
3363 changed files with 653948 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
#!/bin/bash
export log_file=/etc/keepalived/report.log
if [[ $( ip addr | grep -c "192.168.148.131") -eq 1 ]]; then
echo "当前主机为 主loadbalancer节点 当前时间为 $(date) " >> ${log_file}
echo "start to sync nginx conf to another loadbalancer" >> ${log_file}
rclone sync /etc/nginx/ loadbalancer:/etc/nginx/ >> ${log_file}
echo "start to reload the other loadbalancer nginx" >> ${log_file}
ssh loadbalancer "systemctl restart nginx"
echo "" >> ${log_file}
echo "----------------------------" >> ${log_file}
fi

View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
nginx
boge14@Level5
*/15 * * * * /etc/keepalived/check-lb-ip.sh

View File

@@ -0,0 +1,28 @@
! Configuration File for keepalived
global_defs {
router_id web-1 ##标识节点的字符串通常为本机hostname
}
vrrp_script chk_nginx {
script "/etc/keepalived/nginx_check.sh" ##执行脚本位置
interval 2 ##检测时间间隔
weight -20 ##如果条件成立则权重减20
}
vrrp_instance VI_1 {
state MASTER ## 主节点为MASTER备份节点为BACKUP-该配置非常重要
interface ens192: ## 绑定虚拟IP的网络接口网卡可以使用ifconfig查看
virtual_router_id 110 ## 虚拟路由ID号主备节点一定要相同-该配置非常重要
mcast_src_ip 192.168.148.141 ## 本机ip地址
priority 200 ##优先级配置0-254的值,一般主节点的权重大于备份节点
nopreempt
advert_int 2 ## 组播信息发送间隔俩个节点必须配置一致默认1s
authentication { ## 认证匹配
auth_type PASS
auth_pass super-cyy
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.148.131 ## 虚拟ip
}
}

View File

@@ -0,0 +1,28 @@
! Configuration File for keepalived
global_defs {
router_id web-2 ##标识节点的字符串通常为本机hostname
}
vrrp_script chk_nginx {
script "/etc/keepalived/nginx_check.sh" ##执行脚本位置
interval 2 ##检测时间间隔
weight -20 ##如果条件成立则权重减20
}
vrrp_instance VI_2 {
state BACKUP ## 主节点为MASTER备份节点为BACKUP-该配置非常重要
interface ens192 ## 绑定虚拟IP的网络接口网卡可以使用ifconfig查看
virtual_router_id 110 ## 虚拟路由ID号主备节点一定要相同-该配置非常重要
mcast_src_ip 192.168.148.142 ## 本机ip地址
priority 100 ##优先级配置0-254的值,一般主节点的权重大于备份节点
nopreempt
advert_int 2 ## 组播信息发送间隔俩个节点必须配置一致默认1s
authentication { ## 认证匹配
auth_type PASS
auth_pass super-cyy
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.148.131 ## 虚拟ip
}
}

View File

@@ -0,0 +1,18 @@
#!/bin/bash
log_file=/etc/keepalived/report.log
COUNT=$(systemctl status nginx | grep -c "active (running)")
if [ "$COUNT" -eq 0 ];then
echo "[ERROR] moniter nginx failure ! $(date) " >> ${log_file}
systemctl restart nginx
sleep 2
if [ $(systemctl status nginx | grep -c "active (running)") -eq 0 ];then
echo "[ERROR] restart nginx failed ! $(date) " >> ${log_file}
killall keepalived
fi
fi