由于公司之前使用了大量的单域名免费SSL证书, 开通时间又各不相同, 因自己的疏忽大意,终究还是吃了HTTPS证书过期导致APP出现线上事故的亏
其实阿里云自带了SSL证书到期预警, 但是预警消息只会发送给注册账号时使用的邮箱, 外加免费SSL证书每个账号只有20个额度, 这就导致SSL证书分散到了各个账号上, 无形中增加了维护成本
利用阿里云的云监控, 配置HTTPS接口地址也能实现监控的目的 - 不过他是收费的
那么既然有自己的服务器, 为什么不自己写一个监控脚本呢?
要点
1. 使用shell脚本遍历配置文件里所有的域名
2. 使用openssl查询域名的HTTPS证书剩余时间
3. 使用server酱进行预警通知
配置文件 domain_ssl.info
, 用于配置需要检测的域名, 一行一个
www.jijidown.com
anime-music.jijidown.com
xiaoc.cn
新建httpsCheck.sh
脚本, 并使用chmod +x httpsCheck.sh
增加执行权限
#!/bin/bash
script_dir=$( cd "$( dirname "$0" )" && pwd )
script_name=$(basename ${0})
readFile="${script_dir}/domain_ssl.info"
grep -v '^#' ${readFile} | while read line;do
get_domain=$(echo "${line}")
get_port=443
END_TIME=$(echo | openssl s_client -servername ${get_domain} -connect ${get_domain}:${get_port} 2>/dev/null | openssl x509 -noout -dates |grep 'After'| awk -F '=' '{print $2}'| awk -F ' +' '{print $1,$2,$4 }' )
END_TIME1=$(date +%s -d "$END_TIME")
NOW_TIME=$(date +%s -d "$(date "+%Y-%m-%d")")
RST=$(($(($END_TIME1-$NOW_TIME))/(60*60*24)))
echo $get_domain: "${RST}"
if [ $RST -lt 10 ]; then
# 当过期时间小于10天时, 使用server酱发送微信提示
curl https://sc.ftqq.com/你自己在server酱的token.send?text=${get_domain}SSL证书还有${RST}天过期
fi
done
大哥,你的JiJiDown被人贩卖了,是一个博客,还贩卖其他人软件
看来是个专门搞这种的网站。。