下载软件包
#官网地址: http://www.clamav.net/downloads
#Linux中下载地址: wget http://www.clamav.net/downloads/production/clamav-0.100.0.tar.gz
#参考文档: https://github.com/vrtadmin/clamav-faq/raw/master/manual/clamdoc.pdf
创建clamav用户和存放病毒库目录
#clamav用户和用户组
groupadd clamav && useradd -g clamav clamav && id clamav
#日志存放目录
mkdir -p /usr/local/clamav/logs
touch /usr/local/clamav/logs/clamd.log
touch /usr/local/clamav/logs/freshclam.log
chown clamav.clamav /usr/local/clamav/logs/clamd.log
chown clamav.clamav /usr/local/clamav/logs/freshclam.log
病毒库存放目录
mkdir -p /usr/local/clamav/updata
chown -R root.clamav /usr/local/clamav/
chown -R clamav.clamav /usr/local/clamav/updata/
touch /usr/local/clamav/logs/freshclam.log
chown clamav:clamav /usr/local/clamav/logs/freshclam.log
解压安装包
tar xf clamav-0.100.0.tar.gz
安装依赖
yum install gcc openssl openssl-devel -y
编译安装
cd clamav-0.100.0/
./configure --prefix=/usr/local/clamav --with-pcre
make && make install
#检查是否安装成功
echo $?
配置clamd.conf
cd /usr/local/clamav/etc
cp clamd.conf.sample clamd.conf
cp freshclam.conf.sample freshclam.conf
vim clamd.conf
#Example 注释掉这一行.添加下面三行:
LogFile /usr/local/clamav/logs/clamd.log
PidFile /usr/local/clamav/updata/clamd.pid
DatabaseDirectory /usr/local/clamav/updata
配置freshclam.conf
#Example 注释掉这一行.添加下面三行:
DatabaseDirectory /usr/local/clamav/updata
UpdateLogFile /usr/local/clamav/logs/freshclam.log
PidFile /usr/local/clamav/updata/freshclam.pid
启动clamav
systemctl start clamav-freshclam.service
systemctl enable clamav-freshclam.service
systemctl status clamav-freshclam.service
更新病毒库
#先停止freshclam
systemctl stop clamav-freshclam.service
#再更新/usr/local/clamav/bin/freshclam (根据网络质量确定更新时长)或者
cd /usr/local/clamav/updata
wget https://db.local.clamav.net/main.cvd
wget https://db.local.clamav.net/daily.cvd
wget https://db.local.clamav.net/bytecode.cvd
更新完成启动
systemctl start clamav-freshclam.service
systemctl status clamav-freshclam.service
说明:如果在手动更新病毒库的时候遇到错误,此时就要删除掉旧的镜像地址文件#rm -f /var/lib/clamav/mirrors.dat,再手动更新一次病毒库。
扫描杀毒
clamdscan:
一般用yum安装才能使用,需要启动clamd服务,执行速度快;
用clamdscan扫描,需要开始服务才能使用。速度快,不用带-r,默认会递归扫描子目录;
clamdscan /usr
clamscan:
通用,不依赖服务,命令参数较多,执行速度稍慢;
用clamscan扫描,不需要开始服务就能使用;
-r 递归扫描子目录
-i 只显示发现的病毒文件
–no-summary 不显示统计信息
扫描参数:
-r/–recursive[=yes/no] 所有文件
–log=FILE/-l FILE 增加扫描报告
–move [路径] 移动病毒文件至..
–remove [路径] 删除病毒文件
–quiet 只输出错误消息
–infected/-i 只输出感染文件
–suppress-ok-results/-o 跳过扫描OK的文件
–bell 扫描到病毒文件发出警报声音
#病毒文件下载测试
wget http://www.eicar.org/download/eicar.com
#扫描所有文件并且显示有问题的文件的扫描结果
/usr/local/clamav/bin/clamscan -r --bell -i /
#只显示找到的病毒信息
/usr/local/clamav/bin/clamscan --no-summary -ri /tmp
#扫描/home
/usr/local/clamav/bin/clamscan --infected --remove --recursive /home
#扫描/home并删除病毒文件
/usr/local/clamav/bin/clamscan --remove /home
定时杀毒
#让服务器每天晚上定时更新和杀毒,保存杀毒日志,crontab文件如下:
1 3 * * * /usr/local/clamav/bin/freshclam --quiet
20 3 * * * /usr/local/clamav/bin/clamscan -r /home --remove -l /var/log/clamscan.log
评论(0)