In this tutorial, we will show you how to install ClamAV on CentOS 7. For those of you who didn’t know, ClamAV is an open-source (GPL) antivirus engine designed for detecting viruses, malware, and other malicious threats on Linux. It’s easy to use and best for Linux-based Web & Mail servers.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you the step-by-step installation of ClamAV on the CentOS 7 server.
Install ClamAV on CentOS 7
Step 1. First, add the EPEL repository to your system.
yum install epel-release yum update
Step 2. Install ClamAV.
Install required ClamAV packages:
yum install clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd
Step 3. Configuration of Clam daemon.
clamd.conf template, in case you don’t have a configuration file yet:
cp /usr/share/clamav/template/clamd.conf /etc/clamd.d/clamd.conf sed -i ‘/^Example/d’ /etc/clamd.d/clamd.conf
Step 4. Configure SELinux for ClamAV.
You had to write this command to get it working with SELinux:
setsebool -P antivirus_can_scan_system 1
Step 4. Enable Freshclam.
For those of you who didn’t know, Freshclam helps with keeping the database of ClamAV up-to-date. First, delete the related “Example” line from
cp /etc/freshclam.conf /etc/freshclam.conf.bak sed -i ‘/^Example/d’ /etc/freshclam.conf
We creating a quick file here. The process should be forking itself and start
freshclam in daemon mode. In this case, we configure it to check 4 times a day for new files:
Add the following piece:
# Run the freshclam as daemon [Unit] Description = freshclam scanner After = network.target [Service] Type = forking ExecStart = /usr/bin/freshclam -d -c 4 Restart = on-failure PrivateTmp = true [Install] WantedBy=multi-user.target
Now enable and start the service:
systemctl enable clam-freshclam.service systemctl start clam-freshclam.service
Next, rename the /usr/lib/systemd/system/[email protected] file:
mv /usr/lib/systemd/system/[email protected] /usr/lib/systemd/system/clamd.service
.include /lib/systemd/system/[email protected]
The next step is changing the
clamd service file
[Unit] Description = clamd scanner daemon After = syslog.target nss-lookup.target network.target [Service] Type = simple ExecStart = /usr/sbin/clamd -c /etc/clamd.d/clamd.conf --nofork=yes Restart = on-failure PrivateTmp = true [Install] WantedBy=multi-user.target
Move into the directory:
Finally, start all services:
systemctl enable clamd.service systemctl enable [email protected] systemctl start clamd.service systemctl start [email protected]
Congratulations! You have successfully installed ClamAV. Thanks for using this tutorial for installing ClamAV on CentOS 7 system. For additional help or useful information, we recommend you check the official ClamAV website.