RockyLinux8安装ClamAV
1、官网下载rpm包
cd /tmp
wget https://www.clamav.net/downloads/production/clamav-1.4.1.linux.x86_64.rpm
2、安装
rpm -ivh clamav-1.4.1.linux.x86_64.rpm
3、创建目录
#创建病毒数据库和日志目录
mkdir -p /data/clamav/db
mkdir -p /data/clamav/logs
#创建日志文件
touch /data/clamav/logs/clamd.log
touch /data/clamav/logs/freshclam.log
#权限设置
useradd clamav
chown -R clamav:clamav /data/clamav/logs/freshclam.log
chown -R clamav:clamav /data/clamav/db
4、配置文件修改
cd /usr/local/etc
cp clamd.conf.sample clamd.conf
cp freshclam.conf.sample freshclam.conf
vim clamd.conf
#Example 注释掉
#下方内容添加至conf中
LogFile /data/clamav/logs/clamd.log
PidFile /data/clamav/clamd.pid
DatabaseDirectory /data/clamav/db
LogRotate yes
TCPSocket 23310
TCPAddr 0.0.0.0
vim freshclam.conf
#Example 注释掉
#下方内容添加至conf
DatabaseDirectory /data/clamav/db
UpdateLogFile /data/clamav/logs/freshclam.log
PidFile /data/clamav/db/freshclam.pid
LogRotate yes
5、下载病毒库
freshclam
6、启动Clamd服务
vim /etc/systemd/system/clamd.service
[Unit]
Description=Clam AntiVirus Daemon
After=network.target
[Service]
Type=forking
ExecStart=clamd
ExecReload=kill -HUP $MAINPID
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
systemctl enable clamd.service
systemctl start clamd.service
systemctl status clamd.service
7、使用C#客户端连接
<PackageReference Include="nClam" Version="9.0.0" />
var clam = new ClamClient("localhost", 23310)
{
MaxStreamSize = 100 * 1024 * 1024 //100MB
};
var scanResult = await clam.SendAndScanFileAsync(@"D:\text.txt");
Console.WriteLine(scanResult.Result switch
{
ClamScanResults.Clean => "The file is clean!",
ClamScanResults.VirusDetected => $"Virus Found! Virus name: {scanResult.InfectedFiles?.First()?.VirusName}",
ClamScanResults.Error => $"Woah an error occured! Error: {scanResult.RawResult}",
_ => "Unknown result"
});