zoukankan      html  css  js  c++  java
  • Linux 针对nginx日志文件做ip防刷限制

    针对nginx日志做ip访问限制

    1.cat /var/log/server/nginx/access.log| awk -F '?' '/optionid/{print $1}'|awk '{print $1}' 获取含有optionid字符串行的行的ip

    2.sort -r| uniq -c |sort -nr |awk '$1>1000{print $2}' >/var/log/server/nginx/denyip.log对获取的ip排序,计算大于1000次写入到denyip.log文件中

    3.读取denyip.log文件中的ip地址,查看是否已经写入防火墙,没有的话添加iptables防火墙命令

     1 #! /bin/bash
     2 cat /var/log/server/nginx/www.test.com_access.log| awk -F '?' '/optionid/{print $1}'|awk '{print $1}'|sort -r| uniq -c |sort -nr |awk '$1>1000{print $2}' >/var/log/server/nginx/denyip.log
     3 for i in `cat /var/log/server/nginx/denyip.log|sort -nr|uniq -u`
     4 do
     5     NUM=`/etc/init.d/iptables status|grep -c $i`
     6     echo $NUM
     7     if [ $NUM -eq '0' ];then
     8         iptables -I INPUT -s "$i" -j DROP
     9     fi
    10 done
  • 相关阅读:
    poj 3744 题解
    hdu 1850 题解
    New World
    CSP2019游记
    LOJ6052 DIV
    CF809E Surprise me!
    Luogu4548 歌唱王国
    Luogu4581 想法
    Note 5.26-5.28
    LOJ6519 魔力环
  • 原文地址:https://www.cnblogs.com/GNblog/p/6934147.html
Copyright © 2011-2022 走看看