如何在CentOS5.4下为PureFTPd集成ClamAV进行病毒扫描
版本 1.0
作者: Falko Timme <ft [at] falkotimme [dot] com>
原文地址:http://www.howtoforge.com/how-to-integrate-clamav-into-pureftpd-for-virus-scanning-on-centos-5.4
最后编辑04/14/2010
这篇教程将教你如何在一台CentOS 5.4系统中为PureFTPd集成ClamAV进行病毒扫描.在配置完成后,无论何时通过PureFTPd上传文件,ClamAV都将检测这个文件是否为有害文件,有则自动删除它。
我已经测试无误,请放心测试!
1 前言备注
首先你应该有一台已经运行了PureFTPd的CentOS5.4服务器,请参考这篇教程Virtual Hosting With PureFTPd And MySQL (Incl. Quota And Bandwidth Management) On CentOS 5.3
(这篇PureFTP的配置教程虽然是在CentOS5.3下进行的,但是同样在CentOS5.4测试无误)。
2 安装ClamAV
CentOS的官方源中并没有ClamAV,因此我们使用其他的源:
rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt cd /tmp wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm rpm -ivh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
然后我们使用下列命令安装ClamAV:
yum install clamav clamd下面我们为clamd创建自启动,并启动clamd:
chkconfig --levels 235 clamd on /usr/bin/freshclam /etc/init.d/clamd start
3 配置PureFTPd
首先我们打开/etc/pure-ftpd/pure-ftpd.conf 并设置CallUploadScript 为yes:
vi /etc/pure-ftpd/pure-ftpd.conf
[...] # If your pure-ftpd has been compiled with pure-uploadscript support, # this will make pure-ftpd write info about new uploads to # /var/run/pure-ftpd.upload.pipe so pure-uploadscript can read it and # spawn a script to handle the upload. CallUploadScript yes [...]
下面我们创建/etc/pure-ftpd/clamav_check.sh脚本文件(这个文件将会在通过PureFTPd上床文件的时候自动调用/usr/bin/clamdscan)…
vi /etc/pure-ftpd/clamav_check.sh #!/bin/sh /usr/bin/clamdscan --remove --quiet --no-summary "$1"
然后赋予它执行权限:
chmod 755 /etc/pure-ftpd/clamav_check.sh
现在我们启动pure-uploadscript程序-它会在上传文件的时候调用我们的/etc/pure-ftpd/clamav_check.sh脚本
pure-uploadscript -B -r /etc/pure-ftpd/clamav_check.sh
当然,如果你不想在每次启动系统的时候手动启动这个程序的话,就设置一下让它自启动–因此我们打开/etc/rc.local…文件
vi /etc/rc.local
在里面添加/usr/sbin/pure-uploadscript -B -r /etc/pure-ftpd/clamav_check.sh
#!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. /usr/sbin/pure-uploadscript -B -r /etc/pure-ftpd/clamav_check.sh touch /var/lock/subsys/local
最后我们重启PureFTPd:
/etc/init.d/pure-ftpd restart
大功告成!现在无论何时当有人试图通过PureFTPd,上传有害文件到你的服务器时,这些有害文件就会被自动删除.
4 相关链接
PureFTPD: http://www.pureftpd.org/
ClamAV: http://www.clamav.net/
CentOS: http://www.centos.org/
