Fail2ban 在 ubuntu 22.04 上运行前需要重新启动

Fail2ban 在 ubuntu 22.04 上运行前需要重新启动

我从今天开始在 ubuntu 22.04 上使用 ipv6 运行 fail2ban,当我启动 ubuntu 时,每次启动时日志都会显示:

2023-04-21 23:43:39,740 fail2ban.server [1662]: INFO
正在关闭... 2023-04-21 23:43:39,741 fail2ban.observer
[1662]: INFO 观察者停止...尝试结束队列 5 秒 2023-04-21 23:43:39,762 fail2ban.observer [1662]: INFO
观察者已停止,剩余 0 个事件。 2023-04-21 23:43:39,803 fail2ban.server [1662]: INFO 停止所有 jail 2023-04-21 23:43:39,804 fail2ban.filter [1662]: INFO 已删除日志文件:'/var/log/auth.log' 2023-04-21 23:43:40,026 fail2ban.actions [
1662]: NOTICE [sshd] 使用 iptables-multiport 刷新票证 2023-04-21 23:43:41,007 fail2ban.jail [1662]: INFO Jail'sshd' 已停止 2023-04-21 23:43:41,008 fail2ban.database [1662]: INFO 与数据库的连接已关闭。 2023-04-21 23:43:41,009 fail2ban.server [1662]: INFO 退出 Fail2ban

我需要运行该命令sudo service fail2ban restart,然后 fail2ban 服务才会按预期运行。我做错了什么?

该服务似乎已被终止

$ sudo systemctl status fail2ban.service 
○ fail2ban.service - Fail2Ban Service
     Loaded: loaded (/lib/systemd/system/fail2ban.service; disabled; vendor preset: enabled)
     Active: inactive (dead)
       Docs: man:fail2ban(1)

我也尝试过更新/lib/systemd/system/fail2ban.service并将重启选项设置为始终:

[Unit]
Description=Fail2Ban Service
Documentation=man:fail2ban(1)
After=network.target iptables.service firewalld.service ip6tables.service ipset.service nftables.service
PartOf=firewalld.service

[Service]
Type=simple
Environment="PYTHONNOUSERSITE=1"
ExecStart=/usr/bin/fail2ban-server -xf start
# if should be logged in systemd journal, use following line or set logtarget to sysout in fail2ban.local
# ExecStart=/usr/bin/fail2ban-server -xf --logtarget=sysout start
ExecStop=/usr/bin/fail2ban-client stop
ExecReload=/usr/bin/fail2ban-client reload
RuntimeDirectory=fail2ban
PIDFile=/run/fail2ban/fail2ban.pid
Restart=always
RestartPreventExitStatus=0 255
Environment="PYTHONNOUSERSITE=yes"

[Install]
WantedBy=multi-user.target

答案1

好吧,问题出在我身上,而不是 f2b。日志被误解了,因为 f2b 服务在启动后没有停止,它在关机前就停止了,而且由于它在启动时没有启动,所以日志只显示停止日志。

我不知道为什么,因为我已经重新安装了 f2b 很多次,但 f2b 服务在 systemctl 中没有启用。使用以下命令启用 f2b 后

systemctl fail2ban.service enable

一切正常。在我使用 f2b 的这些年里,从来没有需要这个。我不确定这是 bug 还是想要的。

相关内容