设为首页 收藏本站
查看: 880|回复: 0

[经验分享] CentOS7下fail2ban配合apache

[复制链接]

尚未签到

发表于 2018-11-18 11:22:01 | 显示全部楼层 |阅读模式
  官网地址:http://www.fail2ban.org/wiki/index.php/Main_Page
DSC0000.png

  download fail2ban-0.10.tar.gz,然后rz到服务器,
  tar -xvf fail2ban-0.10.tar.gz
  进入解压后的目录,查看README
[root@localhost tmp]# cd fail2ban-0.10/
[root@localhost fail2ban-0.10]# cat README.md #查看python版本是否满足
[root@localhost fail2ban-0.10]# python --version
Python 2.7.5  安装fail2ban
[root@localhost fail2ban-0.10]#python setup.py install  添加系统服务
  fail2ban.service 服务脚本配置文件
[Unit]
Description=Fail2Ban Service
Documentation=man:fail2ban(1)
After=network.target iptables.service firewalld.service
PartOf=iptables.service firewalld.service
[Service]
Type=simple
ExecStartPre=/bin/mkdir -p /var/run/fail2ban
ExecStart=/usr/bin/fail2ban-server -xf start
# if should be logged in systemd journal, use following line or set logtarget to stdout in fail2ban.local
# ExecStart=/usr/bin/fail2ban-server -xf --logtarget=stdout start
ExecStop=/usr/bin/fail2ban-client stop
ExecReload=/usr/bin/fail2ban-client reload
PIDFile=/var/run/fail2ban/fail2ban.pid
Restart=on-failure
RestartPreventExitStatus=0 255
[Install]
WantedBy=multi-user.target  把配置文件加入systemd
[root@localhost system]# ls f*
final.target       firewalld.service  fprintd.service    fstrim.service     fstrim.timer
#拷贝文件到服务统一位置/usr/lib/systemd/system
[root@localhost system]# cp /tmp/fail2ban-0.10/files/fail2ban.service  /usr/lib/systemd/system[root@localhost system]# ls -l /etc/systemd/system/fail2ban.service
lrwxrwxrwx. 1 root root 16 Jul 14 17:41 /etc/systemd/system/fail2ban.service -> fail2ban.service
[root@localhost multi-user.target.wants]# ln -s /usr/lib/systemd/system/fail2ban.service ./multi-user.target.wants/
[root@localhost multi-user.target.wants]# systemctl list-unit-files -t service |grep fail2ban.service
fail2ban.service                              enabled[root@localhost files]# systemctl start fail2ban.service
[root@localhost files]# systemctl status fail2ban.service
● fail2ban.service - Fail2Ban Service
   Loaded: loaded (/usr/lib/systemd/system/fail2ban.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2017-07-14 18:04:26 CST; 12s ago
     Docs: man:fail2ban(1)
  Process: 72114 ExecStartPre=/bin/mkdir -p /var/run/fail2ban (code=exited, status=0/SUCCESS)
Main PID: 72116 (fail2ban-server)
   CGroup: /system.slice/fail2ban.service
           └─72116 /usr/bin/python /usr/bin/fail2ban-server -xf start  配置文件
[root@localhost fail2ban]# ls -1
action.d                             #定义fail2ban的操作,iptables、mails、
fail2ban.conf                         #定义日志级别、日志位置、socket文件位置
fail2ban.d         
filter.d                              #条件,过滤日志设置
jail.conf                             #主要配置文件,模块。启动ban动作服务和动作阀值
jail.d
paths-arch.conf
paths-common.conf
paths-debian.conf
paths-fedora.conf
paths-freebsd.conf
paths-opensuse.conf
patahs-osx.conf  修改 fail2ban.conf配置文件
[root@localhost files]# vim /etc/fail2ban/jail.conf
限制时间
# "bantime" is the number of seconds that a host is banned.
  bantime  = 3600                         #默认为秒,指定分钟后面m,这里指定的是1小时
时间间隔
# A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
  findtime  = 60
次数
# "maxretry" is the number of failures before a host get banned.
maxretry = 200
backend
# "backend" specifies the backend used to get files modification.
# Available options are "pyinotify", "gamin", "polling", "systemd" and "auto".
# This option can be overridden in each jail as well.
#
# pyinotify: requires pyinotify (a file alteration monitor) to be installed.
#              If pyinotify is not installed, Fail2ban will use auto.
# gamin:     requires Gamin (a file alteration monitor) to be installed.
#              If Gamin is not installed, Fail2ban will use auto.
# polling:   uses a polling algorithm which does not require external libraries.
# systemd:   uses systemd python library to access the systemd journal.
#              Specifying "logpath" is not valid for this backend.
#              See "journalmatch" in the jails associated filter config
# auto:      will try to use the following backends, in order:
#              pyinotify, gamin, polling.
#
# Note: if systemd backend is chosen as the default but you enable a jail
#       for which logs are present only in its own log files, specify some other
#       backend for that jail (e.g. polling) and provide empty value for
#       journalmatch. See https://github.com/fail2ban/fail2ban/issues/959#issuecomment-74901200
backend = auto
# true:  jail will be enabled and log files will get monitored for changes
# false: jail is not enabled
enabled = false
# HTTP servers
#
[apache-auth]    #检测验证失败
port     = http,https
logpath  = %(apache_error_log)s

[apache-badbots]          #检测抓取邮件地址的爬虫
# Ban hosts which agent identifies spammer robots crawling the web
# for email addresses. The mail outputs are buffered.
port     = http,https
logpath  = %(apache_access_log)s
bantime  = 48h
maxretry = 1
[apache-noscript]  #漏洞和PHP脆弱性扫描
port     = http,https
logpath  = %(apache_error_log)s

[apache-overflows]     #溢出检测
port     = http,https
logpath  = %(apache_error_log)s
maxretry = 2

[apache-nohome]     #检测在服务器查找主目录
port     = http,https
logpath  = %(apache_error_log)s
maxretry = 2

[apache-botsearch]
port     = http,https
logpath  = %(apache_error_log)s
maxretry = 2

[apache-fakegooglebot]
port     = http,https
logpath  = %(apache_access_log)s
maxretry = 1
ignorecommand = %(ignorecommands_dir)s/apache-fakegooglebot

[apache-modsecurity]
port     = http,https
logpath  = %(apache_error_log)s
maxretry = 2

[apache-shellshock]
port    = http,https
logpath = %(apache_error_log)s
maxretry = 1

[openhab-auth]
filter = openhab
action = iptables-allports[name=NoAuthFailures]
logpath = /opt/openhab/logs/request.log  日志过滤器存放位置
/etc/fail2ban/filter.d
[root@localhost filter.d]# cd /etc/fail2ban/filter.d
[root@localhost filter.d]# ls
3proxy.conf                domino-smtp.conf        mysqld-auth.conf      selinux-common.conf
apache-auth.conf           dovecot.conf            nagios.conf           selinux-ssh.conf
apache-badbots.conf        dropbear.conf           named-refused.conf    sendmail-auth.conf
apache-botsearch.conf      drupal-auth.conf        nginx-botsearch.conf  sendmail-reject.conf
apache-common.conf         ejabberd-auth.conf      nginx-http-auth.conf  sieve.conf
apache-fakegooglebot.conf  exim-common.conf        nginx-limit-req.conf  slapd.conf
apache-modsecurity.conf    exim.conf               nsd.conf              sogo-auth.conf
apache-nohome.conf         exim-spam.conf          openhab.conf          solid-pop3d.conf  action目录:
  /etc/fail2ban/action.d
[root@localhost action.d]# cd /etc/fail2ban/action.d
[root@localhost action.d]# ls
abuseipdb.conf                       mail-buffered.conf
apf.conf                             mail.conf
badips.conf                          mail-whois-common.conf
badips.py                            mail-whois.conf
blocklist_de.conf                    mail-whois-lines.conf
bsd-ipfw.conf                        mynetwatchman.conf
cloudflare.conf                      netscaler.conf
complain.conf                        nftables-allports.conf
dshield.conf                         nftables-common.conf  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-636526-1-1.html 上篇帖子: Apache用户认证;域名跳转;Apache访问日志 下篇帖子: php+apache 环境配置(window环境)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表