简介:
Clam AntiVirus(ClamAV)是免费而且开放源代码的杀毒软件,软件与病毒码的更新皆由社群免费发布。当前ClamAV主要是使用在由Linux、FreeBSD等Unix-like系统架设的邮件服务器上,提供电子邮件的病毒扫描服务。ClamAV本身是在文字接口下运作,但也有许多图形接口的前端工具(GUI front-end)可用,另外由于其开放源代码的特性,在Windows与Mac OS X平台都有其移植版。
安装依赖:
yum groupinstall "Development Tools" -y yum install openssl openssl-devel libcurl-devel zlib-devel libpng-devel libxml2-devel json-c-devel bzip2-devel pcre2-devel ncurses-devel valgrind check check-devel -y #(可选)希望使用clamav-milter的用户可以安装以下产品 yum install sendmail sendmail-devel
安装clamav:
下载安装包到服务器,下载地址: https://www.clamav.net/downloads .
解压、并进入到目录
tar -zxvf clamav-0.102.2.tar.gz cd clamav-0.102.2
编译、安装
#编译,--prefix=指定安装位置必须是绝对路径形式,我这里是/usr/local/clamav,改成自己的 ./configure --prefix=/usr/local/clamav #Example configure summary output: configure: Summary of detected features follows OS : linux-gnu pthreads : yes (-lpthread) configure: Summary of miscellaneous features check : -lcheck (auto) fanotify : yes fdpassing : 1 IPv6 : yes openssl : /usr libcurl : /usr configure: Summary of optional tools clamdtop : yes (-lncurses ) milter : no (missing libmilter) (disabled) clamsubmit : yes (libjson-c-dev found at /usr, linking=dynamic) clamonacc : yes (auto) configure: Summary of engine performance features release mode: yes llvm : no (disabled) mempool : yes configure: Summary of engine detection features iconv : yes bzip2 : ok zlib : yes (from system) unrar : yes preclass : yes (libjson-c-dev found at /usr, linking=dynamic) pcre : /usr libmspack : yes (Internal) libxml2 : yes, from /usr yara : yes fts : yes (internal, libc's is not LFS compatible)
make -j2 make check #make check output: ============================================================================ Testsuite summary for ClamAV 0.103.0 ============================================================================ # TOTAL: 13 # PASS: 7 # SKIP: 6 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0
确保上面没有问题的情况再下执行
make install
配置:
# 创建存放日志和病毒库的文件夹 mkdir /usr/local/clamav/logs mkdir /usr/local/clamav/db #日志文件 touch /usr/local/clamav/logs/clamd.log touch /usr/local/clamav/logs/freshclam.log # 如是root用户运行那么clamav会强制切换到clamav用户运行 # 也就是说如果是root用户那么clamav用户必须存在 # 如果本来就是以普通用户运行,因为编译时使用了--disable-clamav所以可以不用创建 # shell设置为/sbin/nologin用户不能用于登录所以不会降低系统安全性 groupadd clamav useradd -g clamav -s /sbin/nologin -c "Clam AntiVirus" clamav #把文件夹权限赋给clamav用户 chown -R clamav:clamav /usr/local/clamav/logs chown -R clamav:clamav /usr/local/clamav/db #添加软连接 ln -s /usr/local/clamav/bin/freshclam /usr/bin/freshclam ln -s /usr/local/clamav/bin/clamscan /usr/bin/clamscan
创建自定义配置文件:
cd /usr/local/clamav/etc/ cp clamd.conf.sample clamd.conf cp freshclam.conf.sample freshclam.conf
编缉clamd.conf,需要把第八行的Example给注释掉
# Example LogFile /usr/local/clamav/logs/clamd.log PidFile /usr/local/clamav/logs/clamd.pid DatabaseDirectory /usr/local/clamav/db
编缉freshclam.conf,需要把第八行的Example给注释掉
# Example DatabaseDirectory /usr/local/clamav/db UpdateLogFile /usr/local/clamav/logs/freshclam.log PidFile /usr/local/clamav/logs/freshclam.pid
如果有代理,可以在修改freshclam.conf文件时,修改下以下几项,没有请跳过.
HTTPProxyServer 127.0.0.1 HTTPProxyPort 1082 HTTPProxyUsername myusername HTTPProxyPassword mypass
或者在每次更新数据库时候,运行下以下命令
export ALL_PROXY=socks5://127.0.0.1:1081 && export http_proxy=http://127.0.0.1:1082 && export https_proxy=http://127.0.0.1:1082
更新病毒库:
cd /usr/local/clamav/bin ./freshclam
有代理速度会比较快,没有的话只能慢慢等待了,或者手动下载更新.
手动更新病毒库:
cd /usr/local/clamav/db #下载病毒库升级的三个文件 ,或者手动下载,上传到服务器这个目录中来. wget http://database.clamav.net/main.cvd wget http://database.clamav.net/daily.cvd wget http://database.clamav.net/bytecode.cvd #更改权限 chown clamav:clamav *
命令扫描:
注意:clamav有两个命令:clamdscan、clamscan
clamdscan命令是用yum安装方法才能使用,需要启动clamd服务,执行速度快
clamscan命令通用,如果是源码安装的就使用这个命令。不依赖服务,命令参数较多,执行速度稍慢
常用参数:
--quiet 使用安静模式,仅仅打印出错误信息 -i 仅仅打印被感染的文件 -d<文件> 以指定的文件作为病毒库,一代替默认的/var/clamav目录下的病毒库文件 -l <文件> 指定日志文件,以代替默认的/var/log/clamav/freshclam.log文件 -r 递归扫描,即扫描指定目录下的子目录 --move=<目录> 把感染病毒的文件移动到指定目录 --remove 删除感染病毒的文件
更多参数请看: clamscan --help
例如: 递归扫描/etc 目录
clamscan -r -i /etc/
如果使用freshclam更新数据库报错:
ERROR: Database load killed by signal 9 ERROR: Database test FAILED.
这个报错是因为你主机的内存太小了导致的! 你可是使用手动更新病毒库的办法来解决这个问题!
发表评论