一、yum安装安装后自动生成服务文件,启动服务后,可使用clamdscan命令扫描,速度快;启动服务后,会实时监控扫描链接,安全性高,但是对服务器性能有一定影响。
首先需要安装一些依赖:yum install clamav clamav-server clamav-data clamav-update clamav-filesystem clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd pcre* gcc zlib zlib-devel libssl-devel libssl openssl -y
安装完成后,病毒库默认地址是/var/lib/clamav
二、源码编译安装步骤
1)下载安装包;
2)创建clamav用户和存放病毒库路径;
3)解压安装包;
4)安装依赖;
5)编译安装;
6)配置clamav;
7)启动clamav;
8)更新病毒库;
9)扫描杀毒;
10)定时杀毒。
三、详细部署
1、安装包下载
`cd /usr/local/`
`https://www.clamav.net/downloads 下载网址`
`wget https://www.clamav.net/downloads/production/clamav-0.101.5.tar.gz (使用该版本,因为版本过新编译安装时会缺少文件会报错,版本太旧无法更新病毒库)`
2、创建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/update`
`chown -R root:clamav /usr/local/clamav/`
`chown -R clamav:clamav /usr/local/clamav/update`
3、解压安装包,安装依赖,编译安装
`#解压`
`tar zvxf clamav-0.101.5.tar.gz`
`cd clamav-0.101.5/`
`#安装依赖`
`yum install gcc* openssl openssl-devel -y`
`#编译安装`
`cd /usr/local/clamav-0.101.5`
`./configure --prefix=/usr/local/clamav --with-pcre`
`make && make install`
4、配置clamav
`cd /usr/local/clamav/etc`
`cp clamd.conf.sample clamd.conf`
`cp freshclam.conf.sample freshclam.conf`
`vim clamd.conf`
`#注销Example 一行`
`#Example`
`#添加配置项`
`LogFile /usr/local/clamav/logs/clamd.**log**`
`PidFile /usr/local/clamav/update/clamd.pid`
`DatabaseDirectory /usr/local/clamav/update`
`cd /usr/local/clamav/etc`
`vim freshclam.conf`
`#注销Example 一行`
`#Example`
`#添加配置项`
`DatabaseDirectory /usr/local/clamav/update`
`UpdateLogFile /usr/local/clamav/logs/freshclam.**log**`
`PidFile /usr/local/clamav/update/clamd.pid`
5、启动clamav
`chown -R clamav:clamav /usr/local/clamav`
`systemctl start clamav-freshclam.service`
`systemctl enable clamav-freshclam.service`
`systemctl status clamav-freshclam.service`
6、更新病毒库
`#停止freshclam`
`systemctl stop clamav-freshclam.service`
`#更新,耗时根据网络质量而定`
`/usr/local/clamav/bin/freshclam`
`#手动下载病毒库到存储目录,更新(若上步更新成功,忽略这步手动更新)`
`cd /usr/local/clamav/update/`
`wget http://database.clamav.net/main.cvd`
`wget http://database.clamav.net/daily.cvd`
`wget http://database.clamav.net/bytecode.cvd`
`#更新完成后,病毒库存放路径下生成四个病毒库文件;`
`cd /usr/local/clamav/update/`
`bytecode.cvd daily.cvd main.cvd mirrors.dat`
`#再次启动freshclam`
`systemctl start clamav-freshclam.service`
`#为扫描操作可执行文件创建软连接,可以直接用clamscan和freshclam命令执行`
`ln -s /usr/local/clamav/bin/clamscan /usr/local/sbin/clamscan`
`ln -s /usr/local/clamav/bin/freshclam /usr/local/sbin/freshclam`
7、注意问题
`若手动更新病毒库报错,需要进入病毒库存放路径,删除旧的镜像地址文件,重新手动更新;`
`rm -f /usr/local/clamav/update/mirrors.dat`
`或者删除所有病毒库文件,重新更新`
`rm -rf /usr/local/clamav/update/*`
8、扫描命令
`#扫描指定home目录,并且显示扫描过程和结果`
`clamscan -r /home`
`#从根目录下开始,扫描所有文件并且只显示有问题的文件,发现病毒文件发出警报声音`
`clamscan -r --bell -i /`
`#不显示统计信息,只显示找到的病毒文件,且将病毒文件移动到/tmp路径下;`
`clamscan --no-summary -ri /tmp`
`#扫描home路径以及其路径下所有子目录,只输出被感染文件,且将病毒文件、被感染文件直接删除;`
`clamscan --infected --**remove**` `--recursive /home`
9、定时扫描
`#在/usr/local/clamav/logs/目录下创建定时扫描脚本`
`vim clamav.sh`
`/usr/local/clamav/bin/clamscan -r --bell -i / >/usr/local/clamav/logs/"$(date +%F_%A)".**log**`
`#在/usr/local/clamav/logs/目录下创建定时更新病毒库脚本`
`vim freshclam.sh`
`systemctl stop clamav-freshclam.service`
`/usr/local/clamav/bin/freshclam --quiet`
`systemctl start clamav-freshclam.service`
`#创建定时任务`
`#定时病毒扫描,以及病毒库更新`
`0 1 * * * sh /usr/local/clamav/logs/freshclam.sh`
`30 1 * * * sh /usr/local/clamav/logs/clamav.sh`
10、参数说明1
`$ clamscan //不加参数的使用:扫描当前目录下的文件`
`$ clamscan -V //查看clamAV的版本`
`$ clamscan -r //递归扫描子文件夹`
`$ clamscan -i //仅仅显示被感染的文件`
`$ clamscan -o //跳过显示状态ok的文件`
`$ clamscan --**remove**` `//检测到有病毒时,直接删除`
`$ clamscan --no-summary //不显示统计信息`
`$ clamscan -l scan.**log**` `//将扫描日志写入scan.log文件`
11、参数说明2
`r/–recursive[=yes/no] 递归扫描子目录,所有文件;`
`i 只显示发现的病毒文件;`
`–no-summary 不显示统计信息;`
`–**log**=**FILE**/ -l **FILE**` `增加扫描报告,即输出扫描日志到指定文件;`
`–move [路径] 移动病毒文件到指定路径;`
`–**remove**` `[路径] 删除指定路径下的病毒文件;`
`–quiet 只输出错误信息;`
`–infected/-i 只输出被感染文件;`
`–suppress-ok-results/-o 跳过扫描OK的文件;`
`–bell 扫描到病毒文件发出警报声音;`
`–unzip(unrar) 解压压缩文件执行扫描;`