简单好用的SLA探活工具 - EaseProbe

作者:matrix 发布时间:2022 年 10 月 2 日 分类:零零星星

SLA探活的需求很广泛,简单的可以自己实现。但是专门独立的探活工具倒是极少~

EaseProbeGO编写,不需要其他依赖支持直接使用二进制程序运行。

这几天测试用来给api接口、ssl证书、web 200探活,好用~

图片5579-简单好用的SLA探活工具 - EaseProbe

github仓库

https://github.com/megaease/easeprobe

支持HTTP、TCP、SSH、SSL证书、各种数据库/消息中间件服务探活,和email、Slack、Discord、Telegram、飞书...的通知。还支持消息通知和定时发送报表,可以自定义分类告警渠道

配置config.yaml

参照官方配置,新建文件config.yaml

配置SSL证书过期检测、WEB HTTP200检测、接口HTTP状态检测:

http: # http探活

    # 默认监控网页HTTP是否为200OK
  - name: "HHTJIM.COM OK"
    url: https://www.hhtjim.com
  - name: "LINK.HHTJIM.COM OK"
    url: https://www.hhtjim.com

    # 监控接口是否返回指定状态码
  - name: link mp3 parse
    url: https://link.hhtjim.com/163/5146554.mp3
    method: GET
    insecure: true 
    success_code:
        # 配置允许的状态码范围
      - [200,206] # the code >=200 and <= 206
      - [300,308] # the code >=300 and <= 308
    timeout: 1s # default is 30 seconds

tls: # SSL证书探活

    # 监控网页证书是否临近过期(24小时内触发告警)
  - name: "www.hhtjim.com SSL EXPIRED"
    host: www.hhtjim.com:443
    insecure_skip_verify: true # dont check cert validity
    expire_skip_verify: false # dont check cert expire date
    alert_expire_before: 24h # alert if cert expire date is before X, the value is a Duration, see https://pkg.go.dev/time#ParseDuration. example: 1h, 1m, 1s. expire_skip_verify must be false to use this feature.

    # 监控网页证书是否临近过期(7天内触发告警)
  - name: "link.hhtjim.com SSL EXPIRED"
    host: link.hhtjim.com:443
    insecure_skip_verify: true 
    expire_skip_verify: false 
    alert_expire_before: 168h 

notify: # 告警通知方式

  lark:
    - name: "lark alert service"

        # 配置飞书通知机器人的webhook
      webhook: "https://open.feishu.cn/open-apis/bot/v2/hook/00000-10b1-000000-8949-00000000"

# 全局配置
settings:
  probe:
    timeout: 30s # the time out for all probes
    interval: 1m # probe every minute for all probes

说明:

参照上面注释可自由配置,我这里使用的是飞书通知。也可以其他方式告警~

探活配置参数:
https://github.com/megaease/easeprobe/blob/main/docs/Manual.md#1-probe

告警通知配置参数:
https://github.com/megaease/easeprobe/blob/main/docs/Manual.md#2-notification

开启监控

EaseProbe已经有docker镜像,可以直接一键启停。

# 首次启动
$ docker run -d  -p 8181:8181 --name sla -v $(pwd)/config.yaml:/opt/config.yaml megaease/easeprobe


# 重启
$ docker restart sla


# 关闭
$ docker stop sla

查看状态

访问http://HOST:8181`就能看到web监控面板,且支持api接口http://HOST:8181/api/v1/sla`

图片5569-简单好用的SLA探活工具 - EaseProbe

附. 飞书BOT创建

这里的告警通知使用的是群自定义机器人webhook,需要使用飞书客户端创建(web端没有找到入口)

  • 群设置

图片5581-简单好用的SLA探活工具 - EaseProbe

  • 添加自定义机器人

图片5582-简单好用的SLA探活工具 - EaseProbe

  • 复制webhook地址

参考:

https://mp.weixin.qq.com/s/c73ZPBGOMbqjT-xbRiCJ3g

https://github.com/megaease/easeprobe/blob/main/docs/Manual.md

https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN?lang=zh-CN

acme.sh配置泛域名证书Let'sEncrypt

作者:matrix 发布时间:2019 年 9 月 18 日 分类:Linux

环境:
阿里云centos + dnspod.cn

acme.sh项目:https://github.com/Neilpang/acme.sh

安装

$ curl  https://get.acme.sh | sh

图片5018-使用acme.sh配置泛域名证书Let'sEncrypt
出现Install success!安装成功。

dns验证方式-获取域名dns token

这里使用域名解析服务商的token来进行域名拥有验证
在dnspod.cn上操作申请获取ID和token。
ssh执行命令设置变量,便于后面脚本读取。

$ export DP_Id="000000"
$ export DP_Key="26****************************ed"

阿里云dns:

$ export Ali_Id="000000"
$ export Ali_Key="26****************************ed"

阿里云dns获取api和key:https://usercenter.console.aliyun.com/#/manage/ak 进去申请AccessKey ID与Access Key Secret就好。

其他域名解析商的api token操作:
https://github.com/Neilpang/acme.sh/wiki/dnsapi

申请泛域名证书

为域名hhtjim.com申请证书。

$ source .bashrc #执行资源更新 确保acme.sh别名可用
$ acme.sh --issue --dns dns_dp -d hhtjim.com -d *.hhtjim.com

说明:
dns_dp 为dnspod ,如果是阿里云dns则为 dns_ali
前面-d参数指定根域名,后面-d指定子级泛域名
.hhtjim.com的证书只能支持通配符当前级别的域名,也就是xxx.hhtjim.com
如果要三级子域名就需要单独申请:
.xxx.hhtjim.com,参数为-d xxx.hhtjim.com -d *.xxx.hhtjim.com

执行之后等待几分钟出现绿色文字提示key,cer证书所在位置就酸完成了。

图片5019-使用acme.sh配置泛域名证书Let'sEncrypt

The domain key is here: /root/.acme.sh/hhtjim.com/hhtjim.com.key

Your cert is in  /root/.acme.sh/hhtjim.com/hhtjim.com.cer 
Your cert key is in  /root/.acme.sh/hhtjim.com/hhtjim.com.key 
The intermediate CA cert is in  /root/.acme.sh/hhtjim.com/ca.cer 
And the full chain certs is there:  /root/.acme.sh/hhtjim.com/fullchain.cer

证书生成完成,使用的时候把证书移动到nginx配置相关目录。

nginx证书使用

server {
    listen 443;
    server_name www.hhtjim.com;
    root /htdocs/www.hhtjim.com;
    index index.html index.htm index.php;
    ssl on;

    ssl_certificate /certificate_file_PATH/hhtjim.com/fullchain.cer;
    ssl_certificate_key /certificate_file_PATH/hhtjim.com/hhtjim.com.key;
    ...

ssl_certificate和ssl_certificate_key对应fullchain.cer和域名.key文件即可。
以后的所有子域名都可以使用这个路径的证书。

证书更新

脚本会自行写入crontab

36 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null

每天定时检测过期再更新。

参考:

https://github.com/Neilpang/acme.sh/wiki/%E8%AF%B4%E6%98%8E
https://lnmp.org/faq/letsencrypt-wildcard-ssl.html
https://juejin.im/post/5b6542ed51882519d3468d6d

ubuntu安装Let’s Encrypt证书实测

作者:matrix 发布时间:2017 年 1 月 15 日 分类:兼容并蓄 零零星星

Let’s Encrypt证书出来已经有很长时间,之前用主机未到期,也就干瞪眼。
现在手上拿了一台有设备,其实算下来价格也都差不多,国外的速度是慢点,但是好处很多。

测试环境:
ubuntu 14 64bit
lnmp 1.3

获取证书

git clone https://github.com/letsencrypt/letsencrypt 
cd letsencrypt
./letsencrypt-auto certonly --standalone --email hhtjim@foxmail.com -d hhtjim.com -d www.hhtjim.com
# 若服务器已经占用80端口开启webserver则只需执行webroot:
#  ./letsencrypt-auto certonly --webroot --email hhtjim@foxmail.com -d link.hhtjim.com

执行完上面三个命令之后会有图形界面出现
gui图形界面
选择Agree之后出现这个也就完成了证书的获取

安装证书

修改域名对应下的nginx配置
进入/usr/local/nginx/conf/vhost目录找到和域名同名的conf文件
在server代码块中添加:

listen 443 ssl;
        #listen [::]:80;
        ssl on;
        ssl_certificate /etc/letsencrypt/live/域名/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/域名/privkey.pem;

参考如下完整配置

server
    {
        listen 80;
        listen 443 ssl;
        #listen [::]:80;
        ssl on;
        ssl_certificate /etc/letsencrypt/live/hhtjim.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/hhtjim.com/privkey.pem;

        server_name hhtjim.com www.hhtjim.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/hhtjim.com;

        include other.conf;
        #error_page   404   /404.html;
        include enable-php.conf;
        include wordpress.conf;

                if ($http_host !~ "^www.hhtjim.com$"){
                    rewrite  ^(.*)    https://www.hhtjim.com$1 permanent;
                }
                if ($scheme = "http"){ 
                        rewrite ^(.*)$  https://$host$1 permanent;
                }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/hhtjim.com.log;
    }

接着准备重启nginx:lnmp nginx restart

参考:loazuo

更新操作

按照网上大多执行的命令我这里就会出现交互界面,需要手动选择webroot目录

How would you like to authenticate with the ACME CA? 

       x x          1  Place files in webroot directory (webroot)           x x  
       x x          2  Spin up a temporary webserver (standalone)  


还好找到办法,只需要添加参数 --webroot -w 设置好存放web路径即可。最终参考如下

ubuntu下保存为sh文件。记得附加x执行权限。然后执行该sh文件即可自动更新证书.

#!/bin/sh
~/letsencrypt/letsencrypt-auto certonly --webroot -w /home/wwwroot/www.hhtjim.com/ --renew-by-default --email hhtjim@foxmail.com -d hhtjim.com -d www.hhtjim.com && lnmp nginx restart

若报错Failed authorization procedure...则需要修改-w参数为网站根目录
如:

-w /home/wwwroot/hhtjim.com/

且nginx配置中将.well-known加入白名单:

location ~ /.well-known {
            allow all;
    }

参考:
http://letsencrypt.readthedocs.io/en/latest/using.html
https://www.ubock.com/article/25
https://stackoverflow.com/questions/42269107/using-certbot-to-apply-lets-encrypt-certificate-failed-authorization-procedure

最后的定时执行

修改定时任务 crontab -e
0 0 1 * * /root/updateLetsEncrypt.sh #每月1号执行sh脚本

重启定时服务 /etc/init.d/cron restart

peace

Let’s Encrypt 项目提供免费的SSl证书

作者:matrix 发布时间:2015 年 9 月 15 日 分类:兼容并蓄 零零星星

官网:https://letsencrypt.org
github: https://github.com/letsencrypt/letsencrypt
letsencrypt

这将表示如果一个网站只是需要最基本的HTTPS加密,那么将无需任何花费购买SSL证书。

Mozilla、思科、Akamai、IdenTrust、EFF 和密歇根大学研究人员宣布了 Let’s Encrypt CA项目,计划为网站提供免费 ssl 证书,加速将 Web 从 HTTP 过渡到 HTTPS。

上个月才看到了这个消息,大咖阵容提供的公益项目。之前说好的9月份发布,怎么又推迟到了Q4 2015。
网站使用https协议非常不错 。至少比普通网站多了一个绿色的标识,好看还安全~不容易被『挤挨服达不溜』监听到通讯内容。
BUT网站使用https协议必须要有ssl证书,大多都是收费的。不过目前也有免费的,沃通、CloudFlare。。。。。

沃通这些没用过,看到有这么好的公益项目那当然是首推!!值得等待。

Postscript:百度在前几个月都默默启用了全站SSL

阅读剩余部分 »