1.安裝fail2ban原因
創(chuàng)新互聯(lián)公司是專業(yè)的防城港網(wǎng)站建設(shè)公司,防城港接單;提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行防城港網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!本人的網(wǎng)站自從搭建好一段時(shí)間后被問(wèn)候了無(wú)數(shù)次,阿里云安全團(tuán)隊(duì)真敬業(yè),夜里都給我發(fā)異常通知短信,感謝?。。。ńo他做個(gè)廣告)
[root@Lnmp logs]# awk '{print $1}' access.log|sort|uniq -c|sort -rn|head -10
18559 121.42.0.38
16353 121.42.0.39
15351 222.186.34.249
15350 222.186.160.94
15341 222.186.21.35
13870 121.42.0.36
13172 121.42.0.17
12393 121.42.0.31
12302 121.42.0.37
11843 121.42.0.30
所以決定安裝fail2ban 來(lái)限制訪問(wèn)。
1.1 軟件介紹
fail2ban是一款實(shí)用軟件,可以監(jiān)視你的日志,然后匹配日志的信息(正則式匹配)執(zhí)行相應(yīng)的屏蔽動(dòng)作。
1.2 安裝環(huán)境
[root@Lnmp logs]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@Lnmp logs]# uname -r
2.6.32-642.6.1.el6.x86_64
2.實(shí)戰(zhàn) fail2ban 搭建
#上傳fail2ban-0.8.14.tar.gz到安裝目錄,解壓安裝
[root@Lnmp tools]# tar xf fail2ban-0.8.14.tar.gz
[root@Lnmp tools]# cd fail2ban-0.8.14
[root@Lnmp fail2ban-0.8.14]# ll
total 236
-rw-rw-r-- 1 root root 46255 Aug 20 2014 ChangeLog
drwxrwxr-x 2 root root 4096 Aug 20 2014 client
drwxrwxr-x 2 root root 4096 Aug 20 2014 common
drwxrwxr-x 4 root root 4096 Aug 20 2014 config
-rw-rw-r-- 1 root root 19296 Aug 20 2014 COPYING
-rw-rw-r-- 1 root root 13329 Aug 20 2014 DEVELOP
drwxrwxr-x 2 root root 4096 Aug 20 2014 doc
-rwxrwxr-x 1 root root 12699 Aug 20 2014 fail2ban-client
-rwxrwxr-x 1 root root 13570 Aug 20 2014 fail2ban-regex
-rwxrwxr-x 1 root root 4502 Aug 20 2014 fail2ban-server
-rwxrwxr-x 1 root root 8242 Aug 20 2014 fail2ban-testcases
-rwxrwxr-x 1 root root 397 Aug 20 2014 fail2ban-testcases-all
drwxrwxr-x 4 root root 4096 Aug 20 2014 files
-rw-rw-r-- 1 root root 18972 Aug 20 2014 FILTERS
-rwxrwxr-x 1 root root 69 Aug 20 2014 kill-server
drwxrwxr-x 2 root root 4096 Aug 20 2014 man
-rw-rw-r-- 1 root root 8268 Aug 20 2014 MANIFEST
-rw-rw-r-- 1 root root 3992 Aug 20 2014 README.md
-rw-rw-r-- 1 root root 4189 Aug 20 2014 README.Solaris
drwxrwxr-x 2 root root 4096 Aug 20 2014 server
-rw-rw-r-- 1 root root 291 Aug 20 2014 setup.cfg
-rwxrwxr-x 1 root root 3337 Aug 20 2014 setup.py
drwxrwxr-x 4 root root 4096 Aug 20 2014 testcases
-rw-rw-r-- 1 root root 1733 Aug 20 2014 THANKS
-rw-rw-r-- 1 root root 1827 Aug 20 2014 TODO
#安裝fail2ban,注:沒(méi)有安裝python,需要先安裝一下
[root@Lnmp fail2ban-0.8.14]#python setup.py install
#檢查啟動(dòng)文件
[root@Lnmp fail2ban-0.8.14]# grep chkconfig ./* -R --color
./files/redhat-initd:# chkconfig: - 92 08
#把啟動(dòng)文件復(fù)制到 /etc/init.d下做開(kāi)機(jī)自啟動(dòng)
[root@Lnmp fail2ban-0.8.14]# cp files/redhat-initd /etc/init.d/fail2ban
[root@Lnmp fail2ban-0.8.14]# chkconfig --add fail2ban
[root@Lnmp fail2ban-0.8.14]# chkconfig --list fail2ban
fail2ban 0:off 1:off 2:off 3:on 4:on 5:on 6:off
#修改配置文件,修改前備份配置文件
[root@Lnmp fail2ban-0.8.14]# cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.conf.ori
[root@Lnmp fail2ban-0.8.14]# ls /etc/fail2ban/
action.d fail2ban.conf fail2ban.d filter.d jail.conf jail.conf.ori jail.d
#定位到94行[ssh-iptables]修改參數(shù)
[root@Lnmp fail2ban-0.8.14]# vi /etc/fail2ban/jail.conf +94
#預(yù)防暴力破解
[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp]
sendmail-whois[name=SSH, dest=wwj@163.com, sender=bob@163.com, sendername="Fail2Ban"]
logpath = /var/log/secure
maxretry = 3 #設(shè)定訪問(wèn)頻率,單位"次"
bantime = 3600 #限制1小時(shí)內(nèi)不能登錄,單位"秒"
findtime = 300 #設(shè)定訪問(wèn)時(shí)間,十分鐘(300s)內(nèi)
#以上表示十分鐘內(nèi),3次輸錯(cuò)登錄密碼,關(guān)禁閉1小時(shí)。
[root@Lnmp fail2ban-0.8.14]# service fail2ban start
Starting fail2ban: [ OK ]
#查看fail2ban規(guī)則是否生效
[root@Lnmp fail2ban-0.8.14]# service fail2ban status
fail2ban-server (pid 6723) is running...
Status
|- Number of jail: 1
`- Jail list: ssh-iptables
#限制用戶頻繁訪問(wèn)網(wǎng)站,禁止非法ip
[root@Lnmp fail2ban-0.8.14]# vi /etc/fail2ban/jail.conf
#按大寫G定位到最后,添加如下代碼
#nginx access control
[access-get-dos]
enables = true
port = http,https
filter = nginx-bansniffer
action = iptables[name=IT300,port=http,portocol=tcp]
sendmail-whois[name=IT300,dest=11223379@qq.com,sender=wwj@163.com]
#訪問(wèn)日志路徑
logpath = /application/nginx/logs/access.log
#限制規(guī)則
findtime = 60 #設(shè)定訪問(wèn)時(shí)間,一分鐘(60s)內(nèi)
maxretry = 30 #設(shè)定訪問(wèn)頻率,單位"次"
bantime = 3600 #限制1小時(shí)內(nèi)不能登錄,單位"秒"
#以上表示1分鐘內(nèi),30次訪問(wèn),關(guān)禁閉1小時(shí)
#創(chuàng)建規(guī)則文件
[root@Lnmp fail2ban-0.8.14]# vi /etc/fail2ban/filter.d/nginx-bansniffer.conf
[Definition]
failregex = <HOST> -.*- .*HTTP/1.* .* .*$
ignoreregex =
#重新啟動(dòng)fail2ban
[root@Lnmp fail2ban-0.8.14]# service fail2ban reload
#查看fail2ban生效的規(guī)則狀態(tài)
[root@Lnmp fail2ban-0.8.14]# service fail2ban status
fail2ban-server (pid 7013) is running...
Status
|- Number of jail: 2
`- Jail list: access-get-dos, ssh-iptables
#查看生效后訪問(wèn)情況,注:訪問(wèn)日志做了切割
[root@Lnmp logs]#awk '{print $1}' 20161101_access_www.log|sort|uniq -c|sort -rn|head -10
11 121.42.0.16
9 198.52.119.97
8 61.158.152.132
6 112.97.63.104
5 42.48.70.245
5 36.57.226.54
5 221.225.2.214
5 180.114.17.26
5 171.105.144.226
5 123.11.115.223
#uniq -c 表示合并相鄰的重復(fù)記錄,并統(tǒng)計(jì)重復(fù)數(shù)
#sort -n 表示按從小到大進(jìn)行排序
#sort -r 表示逆序,即按照從大到小的順序進(jìn)行排序。
#head -10 表示取前10位
總結(jié):自從fail2ban安裝后每天不再接到阿里安全團(tuán)隊(duì)的問(wèn)候短信了,設(shè)置成功。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
分享名稱:實(shí)戰(zhàn)fail2ban安裝-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://aaarwkj.com/article42/ccojhc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、建站公司、面包屑導(dǎo)航、微信小程序、網(wǎng)站策劃、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容