如果爱,请深爱,千万不要松手; 若不爱,请放开,千万不要回头。 收藏本站
登陆 / 注册 搜索

阅读:6.1K   回复: 3

当系统负载过高,自动开启 cloudflare 5 秒盾

原创 [复制链接]
小执念 古黑浩劫论坛大牛 2019-9-3 18:26 |显示全部楼层

可遇不可求的事:故乡的云,上古的玉,随手的诗,十九岁的你。

管理员
应用场景 : 当网站被 CC/DDoS 攻击导致服务器 CPU 飙升时, 通过 cloudflare 的 api 开启 5 秒盾.

此项目在 github 开源, 地址 : https://github.com/Machou/Cloudflare-Block

下载代码, 并保存到 DDoS 目录下👨‍🎨‏💎📡🤬🤛
  1. git clone https://github.com/Machou/Cloudflare-Block.git DDoS
复制代码

将配置文件 config.template 重命名为 config 并编辑它, 从 cloudflare 账户 获取 api key ,填写到下面的 api_key, email

zone_id= 这个参数在这里
当系统负载过高,自动开启 cloudflare 5 秒盾 TIM截图20190905173801.png

或者直接编辑 Cloudflare.sh 文件, 在里面填写也行.🧑‍⚕️‍🩰📱😆🦷
  1. # Copy it to 'config' and change for your liking

  2. # Your Global API Key (https://dash.cloudflare.com/profile)
  3. api_key=
  4. # Email of your Cloudflare account👨‍⚕️‌🩰📬🤪👀
  5. email=
  6. # Zone ID (https://dash.cloudflare.com/)
  7. zone_id=
  8. # Default security level when there is no attack, see in readme
  9. default_security_level=high
    🦴🌡🧊ℹ🪶‏
  10. # Whether to write debug messages to the debug.log file under script dir
  11. debug=0
复制代码


还需要修改 Cloudflare.sh 文件里面的 maxload= 7 参数, 这个是指系统负载情况. 单核负载为 1 就是 CPU 使用 100% ,双核负载为 2 就是 CPU 使用 100%.
🧑‍⚕️‍🕶✒😰
简单设置为你的核心数*1.1 比如你 CPU 是双核的,可以设置为 2.2, 根据自己的系统/需求来设置.

增加执行权限 :
  1. chmod u+x Cloudflare.sh
复制代码


创建日志文件:👨‍🎨‏👗🪜😭👀

  1. touch /var/log/cf.log
复制代码

写入定时任务:
  1. */1 * * * * /root/DDoS/Cloudflare.sh 0  > /var/log/cf.log 2>&1
  2. */10 * * * * /root/DDoS/Cloudflare.sh 1  > /var/log/cf.log 2>&1
复制代码
🧑‍⚕️‏👖📏😋👍
尊敬的游客, 此内容需要支付 10个金币 才能浏览, 如何获取古黑币/金币?立即支付

上一篇
下一篇
帖子热度 6082 ℃

小执念 古黑浩劫论坛大牛 2019-9-5 17:44 |显示全部楼层

可遇不可求的事:故乡的云,上古的玉,随手的诗,十九岁的你。

管理员
把 Cloudflare.sh 里面的 debug 改为 1,可以看到日志文件 debug.log
  1. debug=1
复制代码

👀🏝🌰➡🐯‎

运行命令
  1. ./Cloudflare.sh 0
复制代码

测试, 如果提示
  1. ./Cloudflare.sh: line 57: bc: command not found
复制代码

是因为没有 bc 命令👨‍🚒‎🩴🔌🤩🤳

yum 安装上
  1. yum -y install bc
复制代码


👵‌💎📬😃👏
左岸云烟 「出类拔萃」 2019-9-3 18:32 |显示全部楼层

这个用户很懒,还没有填写自我介绍呢~

小白一个 顶一下
心微凉 「龙战于野」 2019-10-18 16:06 |显示全部楼层

那个费劲心思逗你笑的人,终究比不上你一见面就开心的人。

小白一个 顶一下
您需要登录后才可以回帖 登录 | 免费注册  

本版积分规则

快速回复 返回列表