Centos | Clamav | 启动clamd@scan服务

本文详细介绍了如何在Linux系统上安装和配置ClamAV防病毒软件,包括安装必要的组件、设置病毒库更新、配置扫描参数、启动服务以及使用clamscan和clamdscan命令进行病毒扫描。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装

yum install clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd

病毒库默认地址是/var/lib/clamav,可以在/etc/freshclam.conf设置。

配置

  • 配置病毒库更新
vim /etc/freshclam.conf

取消注释

DatabaseDirectory /var/lib/clamav
UpdateLogFile /var/log/freshclam.log
LogFileMaxSize 2M
LogTime yes
PidFile /var/run/freshclam.pid
  • 配置扫描
vim /etc/clamd.d/scan.conf

取消注释

LogFile /var/log/clamd.scan
LogFileMaxSize 2M
LogTime yes
PidFile /run/clamd.scan/clamd.pid
DatabaseDirectory /var/lib/clamav
TCPAddr 0.0.0.0
TCPSocket 3310
  • 创建日志文件,这个日志文件对应clamdscan的扫描任务
touch /var/log/clamd.scan
chown clamscan:clamscan /var/log/clamd.scan

启动服务

  • 自动更新
systemctl start clamav-freshclam.service
systemctl enable clamav-freshclam.service 
systemctl status clamav-freshclam.service

在这里插入图片描述

  • 手动更新
freshclam 

在这里插入图片描述

  • 可以下载数据文件到/var/lib/clamav目录下
wget http://database.clamav.net/main.cvd
wget http://database.clamav.net/daily.cvd
wget http://database.clamav.net/bytecode.cvd
  • 启动clamd@scan扫描服务,服务启动不了的话,可以查看/var/log/clamd.scan
systemctl enable clamd@scan
systemctl start clamd@scan
systemctl status clamd@scan

clamscan命令

clamscan扫描不需要启动clamd服务

  • clamscan -h查看命令
clamscan -h
                       Clam AntiVirus: Scanner 0.102.4
           By The ClamAV Team: https://www.clamav.net/about.html#credits
           (C) 2020 Cisco Systems, Inc.

    clamscan [options] [file/directory/-]

    --help                -h             Show this help
    --version             -V             Print version number
    --verbose             -v             Be verbose
    --archive-verbose     -a             Show filenames inside scanned archives
    --debug                              Enable libclamav's debug messages
    --quiet                              Only output error messages
    --stdout                             Write to stdout instead of stderr. Does not affect 'debug' messages.
    --no-summary                         Disable summary at end of scanning
    --infected            -i             Only print infected files
    --suppress-ok-results -o             Skip printing OK files
    --bell                               Sound bell on virus detection

    --tempdir=DIRECTORY                  Create temporary files in DIRECTORY
    --leave-temps[=yes/no(*)]            Do not remove temporary files
    --gen-json[=yes/no(*)]               Generate JSON description of scanned file(s). JSON will be printed and also-
                                         dropped to the temp directory if --leave-temps is enabled.
    --database=FILE/DIR   -d FILE/DIR    Load virus database from FILE or load all supported db files from DIR
    --official-db-only[=yes/no(*)]       Only load official signatures
    --log=FILE            -l FILE        Save scan report to FILE
    --recursive[=yes/no(*)]  -r          Scan subdirectories recursively
    --allmatch[=yes/no(*)]   -z          Continue scanning within file after finding a match
    --cross-fs[=yes(*)/no]               Scan files and directories on other filesystems
    --follow-dir-symlinks[=0/1(*)/2]     Follow directory symlinks (0 = never, 1 = direct, 2 = always)
    --follow-file-symlinks[=0/1(*)/2]    Follow file symlinks (0 = never, 1 = direct, 2 = always)
    --file-list=FILE      -f FILE        Scan files from FILE
    --remove[=yes/no(*)]                 Remove infected files. Be careful!
    --move=DIRECTORY                     Move infected files into DIRECTORY
    --copy=DIRECTORY                     Copy infected files into DIRECTORY
    --exclude=REGEX                      Don't scan file names matching REGEX
    --exclude-dir=REGEX                  Don't scan directories matching REGEX
    --include=REGEX                      Only scan file names matching REGEX
    --include-dir=REGEX                  Only scan directories matching REGEX

    --bytecode[=yes(*)/no]               Load bytecode from the database
    --bytecode-unsigned[=yes/no(*)]      Load unsigned bytecode
    --bytecode-timeout=N                 Set bytecode timeout (in milliseconds)
    --statistics[=none(*)/bytecode/pcre] Collect and print execution statistics
    --detect-pua[=yes/no(*)]             Detect Possibly Unwanted Applications
    --exclude-pua=CAT                    Skip PUA sigs of category CAT
    --include-pua=CAT                    Load PUA sigs of category CAT
    --detect-structured[=yes/no(*)]      Detect structured data (SSN, Credit Card)
    --structured-ssn-format=X            SSN format (0=normal,1=stripped,2=both)
    --structured-ssn-count=N             Min SSN count to generate a detect
    --structured-cc-count=N              Min CC count to generate a detect
    --scan-mail[=yes(*)/no]              Scan mail files
    --phishing-sigs[=yes(*)/no]          Enable email signature-based phishing detection
    --phishing-scan-urls[=yes(*)/no]     Enable URL signature-based phishing detection
    --heuristic-alerts[=yes(*)/no]       Heuristic alerts
    --heuristic-scan-precedence[=yes/no(*)] Stop scanning as soon as a heuristic match is found
    --normalize[=yes(*)/no]              Normalize html, script, and text files. Use normalize=no for yara compatibility
    --scan-pe[=yes(*)/no]                Scan PE files
    --scan-elf[=yes(*)/no]               Scan ELF files
    --scan-ole2[=yes(*)/no]              Scan OLE2 containers
    --scan-pdf[=yes(*)/no]               Scan PDF files
    --scan-swf[=yes(*)/no]               Scan SWF files
    --scan-html[=yes(*)/no]              Scan HTML files
    --scan-xmldocs[=yes(*)/no]           Scan xml-based document files
    --scan-hwp3[=yes(*)/no]              Scan HWP3 files
    --scan-archive[=yes(*)/no]           Scan archive files (supported by libclamav)
    --alert-broken[=yes/no(*)]           Alert on broken executable files (PE & ELF)
    --alert-encrypted[=yes/no(*)]        Alert on encrypted archives and documents
    --alert-encrypted-archive[=yes/no(*)] Alert on encrypted archives
    --alert-encrypted-doc[=yes/no(*)]    Alert on encrypted documents
    --alert-macros[=yes/no(*)]           Alert on OLE2 files containing VBA macros
    --alert-exceeds-max[=yes/no(*)]      Alert on files that exceed max file size, max scan size, or max recursion limit
    --alert-phishing-ssl[=yes/no(*)]     Alert on emails containing SSL mismatches in URLs
    --alert-phishing-cloak[=yes/no(*)]   Alert on emails containing cloaked URLs
    --alert-partition-intersection[=yes/no(*)] Alert on raw DMG image files containing partition intersections
    --nocerts                            Disable authenticode certificate chain verification in PE files
    --dumpcerts                          Dump authenticode certificate chain in PE files

    --max-scantime=#n                    Scan time longer than this will be skipped and assumed clean
    --max-filesize=#n                    Files larger than this will be skipped and assumed clean
    --max-scansize=#n                    The maximum amount of data to scan for each container file (**)
    --max-files=#n                       The maximum number of files to scan for each container file (**)
    --max-recursion=#n                   Maximum archive recursion level for container file (**)
    --max-dir-recursion=#n               Maximum directory recursion level
    --max-embeddedpe=#n                  Maximum size file to check for embedded PE
    --max-htmlnormalize=#n               Maximum size of HTML file to normalize
    --max-htmlnotags=#n                  Maximum size of normalized HTML file to scan
    --max-scriptnormalize=#n             Maximum size of script file to normalize
    --max-ziptypercg=#n                  Maximum size zip to type reanalyze
    --max-partitions=#n                  Maximum number of partitions in disk image to be scanned
    --max-iconspe=#n                     Maximum number of icons in PE file to be scanned
    --max-rechwp3=#n                     Maximum recursive calls to HWP3 parsing function
    --pcre-match-limit=#n                Maximum calls to the PCRE match function.
    --pcre-recmatch-limit=#n             Maximum recursive calls to the PCRE match function.
    --pcre-max-filesize=#n               Maximum size file to perform PCRE subsig matching.
    --disable-cache                      Disable caching and cache checks for hash sums of scanned files.

Pass in - as the filename for stdin.

(*) Default scan settings
(**) Certain files (e.g. documents, archives, etc.) may in turn contain other
   files inside. The above options ensure safe processing of this kind of data.

clamdscan命令

需要启动clamd@scan服务

clamdscan -h
                  Clam AntiVirus: Daemon Client 0.102.4
       By The ClamAV Team: https://www.clamav.net/about.html#credits
       (C) 2020 Cisco Systems, Inc.

clamdscan [options] [file/directory/-]

--help              -h             Show this help
--version           -V             Print version number and exit
--verbose           -v             Be verbose
--quiet                            Be quiet, only output error messages
--stdout                           Write to stdout instead of stderr. Does not affect 'debug' messages.
                                   (this help is always written to stdout)
--log=FILE          -l FILE        Save scan report in FILE
--file-list=FILE    -f FILE        Scan files from FILE
--remove                           Remove infected files. Be careful!
--move=DIRECTORY                   Move infected files into DIRECTORY
--copy=DIRECTORY                   Copy infected files into DIRECTORY
--config-file=FILE                 Read configuration from FILE.
--allmatch            -z           Continue scanning within file after finding a match.
--multiscan           -m           Force MULTISCAN mode
--infected            -i           Only print infected files
--no-summary                       Disable summary at end of scanning
--reload                           Request clamd to reload virus database
--fdpass                           Pass filedescriptor to clamd (useful if clamd is running as a different user)
--stream                           Force streaming files to clamd (for debugging and unit testing)

扫描

  • 递归扫描,clamscan的扫描结果不带时间戳
clamscan –ri /home
  • 递归扫描根目录,不输出summary,并将结果存储在/etc/clamscan.log
clamscan –ri --no-summary /home  -l /etc/clamscan.log
  • clamdscan /home
    在这里插入图片描述

  • clamdscan /home对应日志

在这里插入图片描述

### 在 CentOS 上安装和配置 ClamAV ClamAV 是一款开源的杀毒软件,适用于多种 Linux 发行版,包括 CentOS。以下是关于如何在 CentOS 系统上安装和配置 ClamAV 的详细说明。 #### 1. 安装 EPEL 仓库 ClamAV 并未包含在 CentOS 默认的仓库中,因此需要先安装 EPEL(Extra Packages for Enterprise Linux)仓库。 ```bash sudo yum install epel-release -y ``` 此命令将安装 EPEL 仓库,从而允许访问更多软件包[^1]。 #### 2. 安装 ClamAV 及其组件 使用以下命令安装 ClamAV 及其相关组件: ```bash sudo yum clean all sudo yum install clamav clamav-update clamav-server clamav-scanner-systemd clamav-server-systemd -y ``` 这些组件包括病毒扫描器、更新工具以及系统服务支持[^4]。 #### 3. 更新病毒库 为了确保 ClamAV 能够检测最新的威胁,必须定期更新病毒库。可以使用以下命令手动更新病毒库: ```bash sudo freshclam ``` 如果需要自动更新病毒库,可以通过配置定时任务实现。例如,编辑 `crontab` 文件以每天凌晨 3 点执行更新任务: ```bash crontab -e ``` 添加以下内容: ```cron 0 3 * * * /usr/bin/freshclam --quiet ``` #### 4. 配置 ClamAV 服务 ClamAV 提供了守护进程服务,用于后台运行并提供扫描功能。需要对配置文件进行调整,并启用服务。 - 编辑配置文件 `/etc/clamd.d/scan.conf`: ```bash sudo sed -i 's/#LocalSocket/LocalSocket/g' /etc/clamd.d/scan.conf ``` 此操作启用了本地套接字支持,以便其他程序能够与 ClamAV 守护进程通信[^4]。 - 启用并启动 ClamAV 服务: ```bash sudo systemctl enable clamd@scan sudo systemctl start clamd@scan sudo systemctl status clamd@scan ``` #### 5. 测试 ClamAV 为了验证 ClamAV 是否正常工作,可以扫描一个测试文件。ClamAV 提供了一个名为 EICAR 的标准测试文件,用于验证杀毒软件的功能。 ```bash curl -O https://www.eicar.org/download/eicar.com sudo clamscan eicar.com ``` 如果 ClamAV 正常工作,输出应显示该文件为恶意文件[^3]。 #### 6. 定时扫描任务 为了定期扫描系统中的文件,可以创建一个定时任务。例如,每天凌晨 16 点扫描根目录 `/` 并记录日志: ```bash crontab -e ``` 添加以下内容: ```cron 16 3 * * * /usr/bin/clamscan -r / --remove -l /var/log/clamscan.log ``` --- ### 注意事项 - 如果系统中已存在旧版本的 ClamAV,请先卸载再重新安装以避免冲突。 - 确保服务器防火墙规则允许 ClamAV 所需的网络连接,尤其是当需要从外部下载病毒库更新时[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值