前にClam AntiVirus(以下、ClamAV)をCentOS 7へインストールしたことがあったが、Repoforgeが利用できなくなったので、Epelからインストールしてデーモンとして動かすようにする。 まず、以下のコマンドでEpelとClamAVをインストールする。

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

次に、ClamAVの設定を書き換える。

cp /etc/clamd.d/scan.conf{,$(date +%Y%m%d)}
cp /etc/freshclam.conf{,$(date +%Y%m%d)}
sed -e 's/^Example/#Example/g' \
    -e '/^#LogFile /s/^#//g' \
    -e '/^#LogFileMaxSize /s/^#//g' \
    -e '/^#LogTime /s/^#//g' \
    -e '/^#LogRotate /s/^#//g' \
    -e '/^#LocalSocket /s/^#//g' \
    -e '/^#PidFile /s/^#//g' \
    -e '/^#FixStaleSocket /s/^#//g' \
    -e 's/^User clamscan/User root/g' \
    -i  /etc/clamd.d/scan.conf
sed -e 's/^Example/#Example/g' \
    -e '/^#UpdateLogFile /s/^#//g' \
    -e '/^#LogFileMaxSize /s/^#//g' \
    -e '/^#LogTime /s/^#//g' \
    -e '/^#LogRotate /s/^#//g' \
    -e '/^#DatabaseMirror /s/^#//g' \
    -e '/^#NotifyClamd /cNotifyClamd /etc/clamd.d/scan.conf' \
    -i /etc/freshclam.conf
ln -s /etc/clamd.d/scan.conf /etc/clamd.conf

設定ファイル編集後、デーモンを起動させる。

systemctl start clamd@scan
systemctl enable clamd@scan
[root@BS-PUB-CENT7-01 ~]# systemctl status clamd@scan
● clamd@scan.service - Generic clamav scanner daemon
   Loaded: loaded (/usr/lib/systemd/system/clamd@scan.service; enabled; vendor preset: disabled)
   Active: active (running) since 土 2016-12-10 13:53:37 JST; 10s ago
 Main PID: 22494 (clamd)
   CGroup: /system.slice/system-clamd.slice/clamd@scan.service
           mq22494 /usr/sbin/clamd -c /etc/clamd.d/scan.conf --foreground=yes

12月 10 13:53:37 BS-PUB-CENT7-01.blacknon.local clamd[22494]: clamd daemon 0.99.2 (OS: linux-gnu, ARCH: x86_64, CPU: x86_64)
12月 10 13:53:37 BS-PUB-CENT7-01.blacknon.local clamd[22494]: Running as user root (UID 0, GID 0)
12月 10 13:53:37 BS-PUB-CENT7-01.blacknon.local clamd[22494]: Log file size limited to 2097152 bytes.
12月 10 13:53:37 BS-PUB-CENT7-01.blacknon.local clamd[22494]: Reading databases from /var/lib/clamav
12月 10 13:53:37 BS-PUB-CENT7-01.blacknon.local clamd[22494]: Not loading PUA signatures.
12月 10 13:53:37 BS-PUB-CENT7-01.blacknon.local clamd[22494]: Bytecode: Security mode set to "TrustSigned".
12月 10 13:53:38 BS-PUB-CENT7-01.blacknon.local clamd[22494]: LibClamAV Warning: **************************************************
12月 10 13:53:38 BS-PUB-CENT7-01.blacknon.local clamd[22494]: LibClamAV Warning: ***  The virus database is older than 7 days!  ***
12月 10 13:53:38 BS-PUB-CENT7-01.blacknon.local clamd[22494]: LibClamAV Warning: ***   Please update it as soon as possible.    ***
12月 10 13:53:38 BS-PUB-CENT7-01.blacknon.local clamd[22494]: LibClamAV Warning: **************************************************

無事起動ができたら、Virusの定義ファイルを更新して新しくする。

freshclam
[root@BS-PUB-CENT7-01 ~]# freshclam
ClamAV update process started at Sat Dec 10 13:55:04 2016
main.cvd is up to date (version: 57, sigs: 4218790, f-level: 60, builder: amishhammer)
WARNING: getfile: daily-21724.cdiff not found on database.clamav.net (IP: 198.148.78.4)
WARNING: getpatch: Can't download daily-21724.cdiff from database.clamav.net
Trying host database.clamav.net (172.110.204.67)...
nonblock_recv: recv timing out (30 secs)
WARNING: getfile: Error while reading database from database.clamav.net (IP: 172.110.204.67): Operation now in progress
WARNING: getpatch: Can't download daily-21724.cdiff from database.clamav.net
nonblock_recv: recv timing out (30 secs)
WARNING: getfile: Error while reading database from database.clamav.net (IP: 172.110.204.67): Operation now in progress
WARNING: getpatch: Can't download daily-21724.cdiff from database.clamav.net
WARNING: Incremental update failed, trying to download daily.cvd
Downloading daily.cvd [100%]
daily.cvd updated (version: 22760, sigs: 1139889, f-level: 63, builder: neo)
Downloading bytecode-279.cdiff [100%]
Downloading bytecode-280.cdiff [100%]
Downloading bytecode-281.cdiff [100%]
Downloading bytecode-282.cdiff [100%]
Downloading bytecode-283.cdiff [100%]
Downloading bytecode-284.cdiff [100%]
Downloading bytecode-285.cdiff [100%]
bytecode.cld updated (version: 285, sigs: 57, f-level: 63, builder: bbaker)
[LibClamAV] ******************************************************
[LibClamAV] ***      Virus database timestamp in the future!   ***
[LibClamAV] ***  Please check the timezone and clock settings  ***
[LibClamAV] ******************************************************
Database updated (5358736 signatures) from database.clamav.net (IP: 130.59.113.36)

上記コマンドについては、定期的に実行してやるようにcronなどに記述してやるといいだろう。 最後に、ウィルスチェックを実際に行って動作テストをする。

cd /opt
wget https://www.eicar.org/download/eicar.com
clamdscan /opt # --removeオプションを付与してないので削除はされない
[root@BS-PUB-CENT7-01 tmp]# cd /opt/
[root@BS-PUB-CENT7-01 opt]# wget https://www.eicar.org/download/eicar.com
--2016-12-10 14:21:02--  https://www.eicar.org/download/eicar.com
www.eicar.org (www.eicar.org) をDNSに問いあわせています... 213.211.198.62
www.eicar.org (www.eicar.org)|213.211.198.62|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 68 [application/octet-stream]
`eicar.com' に保存中

100%[===================================================================================================================================================================================================>] 68          --.-K/s 時間 0s

2016-12-10 14:21:03 (2.49 MB/s) - `eicar.com' へ保存完了 [68/68]

[root@BS-PUB-CENT7-01 opt]# clamdscan /opt
/opt/eicar.com: Eicar-Test-Signature FOUND

----------- SCAN SUMMARY -----------
Infected files: 1
Time: 0.003 sec (0 m 0 s)
[root@BS-PUB-CENT7-01 opt]# ls -la /opt/
合計 8
drwxr-xr-x.  2 root root   22 12月 10 14:21 .
dr-xr-xr-x. 18 root root 4096 12月  6 04:43 ..
-rw-r--r--.  1 root root   68 12月 10 14:21 eicar.com

これで、無事ClamAVのインストールができた。 あとは、スクリプトなりを作ってcronなどで定期実行してやるといいだろう。


参考