How to install and configure clamav in Centos/Redhat
ClamAV is an open source (GPL) antivirus engine designed for detecting Trojans, viruses, malware and other malicious threats on Linux. It was initially designed as email scanning gateway on Unix but it has since then evolved as a solution for securing other OS & applications.
Install clamav in centos 7
First we need to install epel repository
[root@centos ~]# yum install epel-release
now install clamav components as below
[root@centos ~]# yum install clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd
Configure clamav
Edit the clamd-scanner package configuration: vi /etc/clamd.d/scan.conf
Comment the example line: #Example
Uncomment the LocalSocket config line to enable it.
LocalSocket /var/run/clamd.scan/clamd.sock
Save and quit the text editor.
Freshclam
To keep the ClamAV database up to date, we need to enable a tool called Freshclam. Therefore, we need to create a backup file from its configuration file.
Edit the configuration file: vi /etc/freshclam.conf
Comment the example line: #Example
otherwise you can use following command
[root@centos ~]# sed -i '/^Example/d' /etc/freshclam.conf
We need to run Freshclam
to update the database manually and to check whether the configuration is successfully set
[root@centos ~]# freshclam
ClamAV update process started at Thu Aug 22 18:01:36 2019
WARNING: Your ClamAV installation is OUTDATED!
WARNING: Local version: 0.101.3 Recommended version: 0.101.4
DON'T PANIC! Read https://www.clamav.net/documents/upgrading-clamav
main.cvd is up to date (version: 58, sigs: 4566249, f-level: 60, builder: sigmgr)
Downloading daily-25543.cdiff [100%]
Downloading daily-25544.cdiff [100%]
Downloading daily-25545.cdiff [100%]
Downloading daily-25546.cdiff [100%]
Downloading daily-25547.cdiff [100%]
Downloading daily-25548.cdiff [100%]
Downloading daily-25549.cdiff [100%]
daily.cld updated (version: 25549, sigs: 1730406, f-level: 63, builder: raynman)
bytecode.cvd is up to date (version: 330, sigs: 94, f-level: 63, builder: neo)
Database updated (6296749 signatures) from database.clamav.net (IP: 104.16.218.84)
We can run freshclam any time we want to make sure the definition databases are up to date, but it would be inconvenient to have to always run it manually. When launched with the -d
argument, freshclam will run in the daemon mode and periodically check for updates throughout the day (every two hours by default).
To keep things clean, we created a service file to run freshclam and registered it with systemd
[root@centos ~]# vim /usr/lib/systemd/system/clam-freshclam.service
Then add following code and save it
[Unit]
Description = freshclam scanner
After = network.target
[Service]
Type = forking
ExecStart = /usr/bin/freshclam -d -c 4
Restart = on-failure
PrivateTmp = true
RestartSec = 20sec
[Install]
WantedBy=multi-user.target