centos服务器fail2ban部署指南标准流程

安装

sudo 复制代码
sudo yum install fail2ban -y

Fail2Ban的默认配置文件在/etc/fail2ban/jail.conf,但不建议直接编辑这个文件。/etc/fail2ban/jail.local的优先级默认更高,无需指定路径。

复制代码
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo vim /etc/fail2ban/jail.local

[api-worktool]
enabled  = true
port     = http,https
filter   = nginx-errors
logpath  = /www/wwwlogs/api.worktool.ymdyes.cn.log
maxretry = 10

[site2]
enabled  = true
port     = http,https
filter   = nginx-errors
logpath  = /www/wwwlogs/site2.example.com.log
maxretry = 3

创建或编辑过滤器文件 /etc/fail2ban/filter.d/nginx-errors.conf,添4xx、5xx错误码

复制代码
sudo vim /etc/fail2ban/filter.d/nginx-errors.conf

[Definition]
failregex = ^<HOST> -.* "(GET|POST|PUT|DELETE|HEAD).*HTTP/.*" (4\d{2}|5\d{2}) 

重启fail2ban生效

复制代码
sudo systemctl enable fail2ban
sudo systemctl restart fail2ban

检查和测试

复制代码
sudo fail2ban-client status
sudo fail2ban-client status api-worktool
sudo fail2ban-client status site2
sudo fail2ban-client -d

Fail2Ban会使用iptables来禁止IP地址。确保你的防火墙允许Fail2Ban添加规则。(缺省)

复制代码
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
相关推荐
行止62 小时前
OpenStack云平台管理
linux·openstack
岁岁岁平安3 小时前
CentOS-7-x86_64解决:使用NAT模式无法ping通www.baidu.com或无法ping 8.8.8.8问题。
linux·运维·centos·centos-7
运维小贺3 小时前
各服务器厂商调整BIOS睿频教程
linux·运维·服务器·性能优化
特种加菲猫3 小时前
指尖上的魔法:优雅高效的Linux命令手册
linux·笔记
★Orange★4 小时前
Linux Kernel kfifo 实现和巧妙设计
linux·运维·算法
bemyrunningdog4 小时前
Mock数据
linux·运维·ubuntu
是阿建吖!4 小时前
【Linux | 网络】网络编程套接字
linux·网络
退役小学生呀5 小时前
十、K8s集群资源合理化分配
linux·云原生·容器·kubernetes·k8s
Winner13005 小时前
Debian、Buildroot 和 Ubuntu 都是基于 Linux 的系统区别
linux·ubuntu·debian
1nullptr6 小时前
UNIX程序设计基本概念和术语
linux