首页 > 其他分享 >安全:用logrotate实现fail2ban日志按天切分

安全:用logrotate实现fail2ban日志按天切分

时间:2024-09-23 11:48:59浏览次数:1  
标签:bin cgi log 按天 logrotate fail2ban 日志

一,fail2ban默认安装了日志分割文件

文件位置:/etc/logrotate.d/fail2ban

[root@blog logrotate.d]# rpm -qf /etc/logrotate.d/fail2ban
fail2ban-server-1.0.2-12.el9.noarch

可以看到此文件来自于fail2ban-server这个rpm包

配置文件默认内容:

[root@iZ2zejc9t0hf6pnw6sewrxZ logrotate.d]# more fail2ban
#
# Gentoo:
# http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/net-analyzer/fail2ban/files/fail2ban-logrotate?view=markup
#
# Debian:
# https://github.com/fail2ban/fail2ban/blob/debian/debian/fail2ban.logrotate

/var/log/fail2ban.log {
    missingok
    notifempty
    postrotate
      /usr/bin/fail2ban-client flushlogs >/dev/null || true
    endscript
}

二,设置为每天转存一个文件:

设置后的配置文件:

[root@blog logrotate.d]# more fail2ban
#
# Gentoo:
# http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/net-analyzer/fail2ban/files/fail2ban-logrotate?view=markup
#
# Debian:
# https://github.com/fail2ban/fail2ban/blob/debian/debian/fail2ban.logrotate

/var/log/fail2ban.log {
    missingok
    daily
    rotate 30
    notifempty
    dateext
    sharedscripts
    postrotate
      /usr/bin/fail2ban-client flushlogs >/dev/null || true
    endscript
}

各配置项的说明:

daily: 每天轮转一次日志
rotate 30: 保留30份旧日志
dateext: 这个参数的作用: 切割后的日志文件以当前日期为格式结尾,如xxx.log-20131216这样,
            如果注释掉,切割出来是按数字递增,即前面说的 xxx.log-1这种格式
sharedscripts: 作用是: 有多个日志时,在所有日志都轮转后统一执行一次脚本。
                    如果没有配置这个,那么每个日志轮转后都会执行一次脚本
missingok
: 在日志轮循期间,任何错误将被忽略,例如“文件无法找到”之类的错误。
notifempty: 如果日志文件为空,轮循不会进行。
postrotate/endscript: 在所有其它指令完成后,postrotate和endscript里面指定的命令将被执行。
                                

设置完成后无需重启服务

标签:bin,cgi,log,按天,logrotate,fail2ban,日志
From: https://www.cnblogs.com/architectforest/p/18426795

相关文章

  • 安全:查看fail2ban使用的backend
    一,区分不同的后端:日志是从哪里读取依赖于backend的设置,如果通过systemd读取时设置为 backend=systemd,否则,不要设置backend或改为backend=auto,如果不是通过systemd访问,设置了 backend=systemd,此时fail2ban不会读取我们设置的logpath例子:使用systemd[sshd]enabled=tru......
  • 安全: fail2ban的日常操作/配置
    一,指定监控多个日志文件:例子如下:[apache-w00tw00t]enabled=truefilter=apache-w00tw00taction=iptables-allportslogpath=/var/www/vhosts/site1.com/log/errorlog/var/log/apache*/*error.log/var/www/vhosts/site1.com/subdom/lo......
  • centos(linux): logrotate常用功能
    一,测试配置是否正确?-d:打印debug信息-v:显示详细的输出信息[[email protected]]#logrotate-d/etc/logrotate.d/secure-v二,配置/var/log/secure按天分割/etc/logrotate.d/secure/var/log/secure{missingokdailyrotate90notifemptydatee......
  • fail2ban 下载 安装 使用
    安装Python(如果未安装)Fail2ban是基于Python开发的,所以首先需要在Windows上安装Python。访问Python官方网站(PythonReleasesforWindows|Python.org),下载适合您Windows版本的Python安装程序。运行安装程序,在安装过程中,确保勾选“AddPythontoPATH”选项,以......
  • centos(linux): logrotate是怎么触发日志轮询的?
    一,通过查看crontab中的配置,没有logroate1,查看crontab[[email protected]]#more/etc/crontabSHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=root#Fordetailsseeman4crontabs#Exampleofjobdefinition:#.----------------minute(0-59)#......
  • 【待做】【Linux系列】使用fail2ban配置动态防火墙
    一、安装二、测试三、基本配置四、相关命令原创戒一双LINUX开源玩家前面说的防火墙基本是静态的情况,在实际运行中我们可能需要动态调整防火墙策略,此时可以考虑使用Fail2ban。Fail2ban可以通过创建规则,自动更改防火墙配置,在尝试登录失败达到一定次数后禁止特定IP,......
  • fail2ban: 使用firewalld的富规则rich rule
    一,fail2ban中的时间设置:m:分钟h:小时d:天w:周y:年 -1:永久二,安装:1,通过yum安装用yum安装:[root@blog~]#yuminstallfail2ban安装后查看状态:未启动[root@blog~]#systemctlstatusfail2ban.service○fail2ban.service-Fail2BanServiceLoaded:lo......
  • centos(linux): 安装管理fail2ban
    一,官网:https://www.fail2ban.org会跳转到代码站:https://github.com/fail2ban/fail2ban二,安装:用yum安装:[root@blog~]#yuminstallfail2ban安装后查看状态:未启动[root@blog~]#systemctlstatusfail2ban.service○fail2ban.service-Fail2BanServiceLo......
  • LogRotate 切割 Nginx 日志
     发布于 2023-12-0410:20:327140举报文章被收录于专栏:码农UP2U一直以来做日志切割都是使用shell+crontab来搞,shell脚本可以在网上找到各种版本的,改改就用了,懒省事。这样的做法很传统,却忽略了系统的给我们提供的优秀的工具——logrotate。......
  • 基于Fail2ban及iptables的SSH端口爆破防御方案
    君衍.一、本篇介绍二、Fail2ban1、简介2、工作方式3、优缺点4、工作原理5、目录结构6、功能特点三、更改默认SSH端口1、更改配置文件2、重启服务四、SSH日志审计1、连接失败的IP2、失败IP次数排行3、连接成功的IP4、成功IP次数排行五、Fail2ban1、安装2、配置3、日志......