惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
A
About on SuperTechFans
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Blog — PlanetScale
Blog — PlanetScale
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
G
Google Developers Blog
J
Java Code Geeks
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
Cloudbric
Cloudbric
L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog
H
Heimdal Security Blog
PCI Perspectives
PCI Perspectives
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
Latest news
Latest news
I
Intezer
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
月光博客
月光博客
T
Threatpost
博客园 - 【当耐特】
S
Schneier on Security
P
Privacy International News Feed
G
GRAHAM CLULEY
T
Tenable Blog
AWS News Blog
AWS News Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
博客园 - Franky
Engineering at Meta
Engineering at Meta
美团技术团队
S
Secure Thoughts
T
Troy Hunt's Blog
Microsoft Security Blog
Microsoft Security Blog
SecWiki News
SecWiki News
V
Visual Studio Blog
人人都是产品经理
人人都是产品经理
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cisco Talos Blog
Cisco Talos Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Martin Fowler
Martin Fowler
Webroot Blog
Webroot Blog
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - 一起走过的路

Nginx GeoIP2 模块编译安装与配置指南(附防国外访问实战) MySQL查询当前连接数的语句 Apollo批量给新创建的用户授可编辑权限 物理机Jenkins接入K8s环境 ingress配置https报错certificate.lua:259: call(): failed to set DER private key: d2i_PrivateKey_bio() failed, context: ssl_certificate_by_lua* elk收集分析nginx日志,并绘制图形 Zabbix Scheduled reports中文乱码 kubernetes mysql-StatefulSet报错处理 Jenkins合并代码Git报错处理过程 nginx集群同步方案 zabbix密码复杂度有效期安全增强,符合三级等保要求。 archery关闭导出功能 自动同步bing壁纸 CentOS7更新OpenSSH8 elk监听Java日志发送微信报警 OPENVPN 同时连接多个VPN - 一起走过的路 nginx拒绝国外IP访问 执迷不悟 splunk设置索引周期和索引大小
keepalived健康检查及双主MySQL健康检查脚本
一起走过的路 · 2020-12-21 · via 博客园 - 一起走过的路

一、http检查

HTTP_GET:工作在第5层,向指定的URL执行http请求,将得到的结果用md5加密并与指定的md5值比较看是否匹配,不匹配则从服务器池中移除;此外还可以指定http返回码来判断检测是否成功。HTTP_GET可以指定多个URL用于检测,这个一台服务器有多个虚拟主机的情况下比较好用。

real_server 10.21.10.30 80 {

weight 1
HTTP_GET {
        url {
        path /keeptest/index.html
        digest 3b9bc8d36a113971683321ad4fa02daf
        }
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        }

}
#使用命令获取URL的hash
/usr/bin/genhash  -s 10.21.10.30 -p 80 -u /keeptest/index.html

二、tcp端口检查

SSL_GET:跟上面的HTTP_GET相似,不同的只是用SSL连接 

三、tcp端口检查

TCP_CHECK:工作在第4层,keepalived向后端服务器发起一个tcp连接请求,如果后端服务器没有响应或超时,那么这个后端将从服务器池中移除。

    real_server xxx.xx.xx.66 3306 {
        weight 1
        TCP_CHECK {
             connect_timeout 3 
             retry 3
             delay_before_retry 3  
             connect_port 3306    
        } 
    }   

四、脚本检查

MISC_CHECK:用脚本来检测,脚本如果带有参数,需将脚本和参数放入双引号内。脚本的返回值需为:             0)  检测成功             1)  检测失败,将从服务器池中移除             2-255)检测成功;如果有设置misc_dynamic,权重自动调整为 退出码-2,如退出码为200,权重自动调整为198=200-2。

五、邮件检查

SMTP_CHECK:用来检测邮件服务的smtp的。没用过不描述了自己搜吧

keepalive的双主MySQL健康检查

    real_server xxx.xx.xx.66 3306 {
        weight 1
        TCP_CHECK {
             connect_timeout 3 
             retry 3
             delay_before_retry 3  
             connect_port 3306    
        } 
        MISC_CHECK {
           misc_path "/etc/keepalived/mysql_check.sh 172.16.0.66"
           misc_timeout 3
        }   
    }     

mysql_check.sh内容如下

#!/bin/bash
if [ $# -ne 1 ];then
    echo "Error: please use $0 xxx.xx.xx.66"
    exit 1
else
    CHECK_IP=$1
    Slave_status=$(mysql -u xxxxx -p'*********' -h $CHECK_IP -e "show slave status\G" | grep -wE 'Slave_SQL_Running|Slave_IO_Running' | awk -F": " '{print $2}' | wc -l)
    Seconds_Behind_Master=$(mysql -u xxxxx -p'*********' -h $CHECK_IP -e "show slave status\G" | grep -w Seconds_Behind_Master | awk -F": " '{print $2}')
    if [ ${Slave_status} -eq 2 ] && [ ${Seconds_Behind_Master} -lt 300 ];then
        exit 0
    else
        #异步调用钉钉发送通知。第一次脚本用了for i in {1..20}次,发现keepalive每次检查都要发送钉钉通知,故只通知一次。
        {
            message="$CHECK_IP Slave_status=$Slave_status Seconds_Behind_Master = $Seconds_Behind_Master"
            curl --connect-timeout 2 "https://oapi.dingtalk.com/robot/send?access_token=**********************************************" \
                -H "Content-Type: application/json" \
                -d '{"msgtype": "text", 
                "text": {
                    "content": "'"${message}"'"
                }
            }'
        } &

        exit 1
    fi
fi

#注意mysql_check.sh增加可执行权限