![我的自定义fail2ban监狱无法加载,即使fail2ban-regex表明它应该可以工作?](https://linux22.com/image/198036/%E6%88%91%E7%9A%84%E8%87%AA%E5%AE%9A%E4%B9%89fail2ban%E7%9B%91%E7%8B%B1%E6%97%A0%E6%B3%95%E5%8A%A0%E8%BD%BD%EF%BC%8C%E5%8D%B3%E4%BD%BFfail2ban-regex%E8%A1%A8%E6%98%8E%E5%AE%83%E5%BA%94%E8%AF%A5%E5%8F%AF%E4%BB%A5%E5%B7%A5%E4%BD%9C%EF%BC%9F.png)
我在fail2ban 中编写了一个自定义监狱和过滤器,用于登录我的服务。日志文件位于/var/log/motion/motion.log
,登录失败会生成如下行:
[0:ml1] [ALR] [STR] [Nov 02 11:42:59] handle_basic_auth: motion-stream - failed auth attempt from <ip>
我的监狱/etc/fail2ban/jail.local
是这样的:
[motion-auth]
enabled = true
port = 8008
filter = motion-auth.conf
logpath = /var/log/motion/motion.log
banaction = %(banaction_allports)s
maxretry = 3
findtime = 10800
bantime = 259200
我的命名过滤器/etc/fail2ban/filter.d
如下motion-auth.conf
所示:
[Definition]
failregex = \[0:ml1\] \[ALR\] \[STR\] \[.*\] handle_basic_auth: motion-stream - failed auth attempt from <HOST>
当我运行时,fail2ban-regex /var/log/motion/motion.log /etc/fail2ban/filter.d/motion-auth.conf
我得到确认,我的过滤器实际上按预期运行:
Running tests
=============
Use failregex filter file : motion-auth, basedir: /etc/fail2ban
Use log file : /var/log/motion/motion.log
Use encoding : UTF-8
Results
=======
Failregex: 186 total
|- #) [# of hits] regular expression
| 1) [186] \[0:ml1\] \[ALR\] \[STR\] \[.*\] handle_basic_auth: motion-stream - failed auth attempt from <HOST>
`-
Ignoreregex: 0 total
Date template hits:
|- [# of hits] date format
| [2640] (?:DAY )?MON Day %k:Minute:Second(?:\.Microseconds)?(?: ExYear)?
`-
Lines: 2929 lines, 0 ignored, 186 matched, 2743 missed
[processed in 1.06 sec]
但是当我尝试重新加载/重新启动fail2ban以添加新过滤器时,我收到如下消息:
Found no accessible config files for 'filter.d/motion-auth.conf' under /etc/fail2ban
Unable to read the filter 'motion-auth.conf'
Errors in jail 'motion-auth'. Skipping...
OK
有谁知道我做错了什么?
答案1
在 jam.conf 中,过滤器行应与其名称一起使用,而不是文件名。像这样:
[motion-auth]
...
filter = motion-auth