Fail2Ban 排查错误

背景

Fail2Ban 安装完后( 参考 安装过程 ),用 systemctl status fail2ban 查看,发现报错:

1
fail2ban.service: Main process exited, code=exited, status=255

排查过程

首先查看 log:

1
sudo cat /var/log/fail2ban.log

发现日志为空,无线索。

有搜索了一下,可以通过下面命令查看系统log:

1
sudo journalctl -xe | tail -n 50

检查了一下,发现以下报错:

1
Failed during configuration: Have not found any log file for sshd jail

感觉是配置文件问题,搜索了一下,找到以下解决方案:

编辑jail.conf文件:

1
sudo vim /etc/fail2ban/jail.conf

找到 ‘backend = auto‘ 修改为 ‘backend = systemd

重启fail2ban 服务:

1
sudo systemctl restart fail2ban

发现还是报错,查了以下,需要手工创建log文件:

1
sudo touch /var/log/auth.log

该文件定义在 fail2ban.local 文件中

再次重启fail2ban 服务,问题解决:

1
2
3
4
5
6
7
8
9
10
> sudo fail2ban-client status sshd
Status for the jail: sshd
|- Filter
| |- Currently failed: 0
| |- Total failed: 0
| `- File list: /var/log/auth.log
`- Actions
|- Currently banned: 0
|- Total banned: 0
`- Banned IP list:

请我喝杯咖啡吧~

支付宝
微信