Contents
1.Synchronize the server time with Japan Standard Time.
Edit chrony.conf
1 2 3 4 5 6 7 8 9 |
# vi /etc/chrony.conf Per line 3. pool 2.centos.pool.ntp.org iburst ↓ server ntp.nict.jp server ntp1.jst.mfeed.ad.jp server ntp2.jst.mfeed.ad.jp Restart chrony |
1 2 3 |
# systemctl restart chronyd.service Enable chrony even after reboot # systemctl enable chronyd.service |
Checking the status (behavior) of chronyd
1 2 3 4 5 6 |
# chronyc sources It will be displayed as shown below. MS Name/IP address Stratum Poll Reach LastRx Last sample =========================================== ^+ ntp1.jst.mfeed.ad.jp 2 9 377 125 -462us[ -462us] +/- 93ms ^* ntp2.jst.mfeed.ad.jp 2 10 377 1019 +140us[ +265us] +/- 97ms |
If you see the "*" mark, synchronization is complete.
2.virus protection
2.1 Clam AntiVirus installation and definition/configuration file settings
①Installing Clam AntiVirus
1 |
# dnf --enablerepo=epel -y install clamav clamav-update clamav-scanner-systemd |
➁Virus definition file update setting
Edit virus definition file update setting file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# vi /etc/freshclam.conf ■Line 8. # Comment or remove the line below. #Example ← Add # to the beginning of the line and comment it out ■Line 75. Insert "#" at the beginning of the line "DatabaseMirror database.clamav.net" and add "DatabaseMirror db.jp.clamav.net". and add "DatabaseMirror db.jp.clamav.net". #DatabaseMirror database.clamav.net DatabaseMirror db.jp.clamav.net ■Per line 151 Add "NotifyClamd /etc/clamd.d/scan.conf". #NotifyClamd /path/to/clamd.conf NotifyClamd /etc/clamd.d/scan.conf |
➂Update virus definition files
1 2 3 4 |
# freshclam ClamAV update process started at Tue Mar 10 10:22:58 2020daily database available for download (remote version: 25746) ・ ・ |
④Edit Clam AntiVirus configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# vi /etc/clamd.d/scan.conf ■Line 8. # Comment or remove the line below. #Example ← Add # to the beginning of the line and comment it out ■Line 14. # Default: disabled LogFile /var/log/clamd.scan ← Uncomment ■Line 77. # Default: disabled PidFile /run/clamd.scan/clamd.pid ← Uncomment ■Line 96. # Path to a local socket file the daemon will listen on. # Default: disabled (must be specified by a user) LocalSocket /run/clamd.scan/clamd.sock ← Uncomment ■Line 219. # Run as another user (clamd must be started by root for this option to work) # Default: don't drop privileges #User clamscan ← Add # to the beginning of the line and comment it out(Make sure it runs with root privileges) |
⑤Start Clam AntiVirus
1 2 3 4 |
# systemctl start clamd@scan ← Start clamd # systemctl enable clamd@scan ← clamd auto-start setting # systemctl is-enabled clamd@scan enabled |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
operation check # systemctl status clamd@scan ● clamd@scan.service - clamd scanner (scan) daemon Loaded: loaded (/usr/lib/systemd/system/clamd@.service; enabled; vendor pres> Active: active (running) since Sun 2020-03-22 20:13:31 JST; 22min ago Docs: man:clamd(8) man:clamd.conf(5) https://www.clamav.net/documents/ Main PID: 19465 (clamd) Tasks: 2 (limit: 26213) Memory: 873.7M CGroup: /system.slice/system-clamd.slice/clamd@scan.service mq19465 /usr/sbin/clamd -c /etc/clamd.d/scan.conf |
2.2 Configure virus scanning and periodic execution
1)Perform virus scanning.
■If the virus is not detected
1 2 3 4 5 6 7 8 9 10 |
# clamscan --infected --remove --recursive ----------- SCAN SUMMARY ----------- Known viruses: 6780306 Engine version: 0.100.2 Scanned directories: 5 Scanned files: 8 Infected files: 0 ←If no virus is detected, the value here is displayed as "0". Data scanned: 0.03 MB Data read: 0.02 MB (ratio 2.00:1) Time: 14.258 sec (0 m 14 s) |
■When a virus is detected
Download a test virus
1 |
# wget http://www.eicar.org/download/eicar.com |
1 2 3 4 5 6 7 8 9 10 11 12 |
# clamscan --infected --remove --recursive /root/eicar.com: Eicar-Test-Signature FOUND ← virus detection /root/eicar.com: Removed. ← virus removal ----------- SCAN SUMMARY ----------- Known viruses: 6780306 Engine version: 0.100.2 Scanned directories: 5 Scanned files: 12 Infected files: 1 ←One virus detected. Data scanned: 0.03 MB Data read: 0.02 MB (ratio 2.00:1) Time: 12.810 sec (0 m 12 s) |
2)Deployment of automatic virus scan execution scripts
Create clamscan.sh with the following contents
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# vi /var/www/system/clamscan.sh #!/bin/bash PATH=/usr/bin:/bin # excludeopt setup excludelist=/var/www/system/clamscan.exclude if [ -s $excludelist ]; then for i in `cat $excludelist` do if [ $(echo "$i"|grep \/$) ]; then i=`echo $i|sed -e 's/^\([^ ]*\)\/$/\1/p' -e d` excludeopt="${excludeopt} --exclude-dir=$i" else excludeopt="${excludeopt} --exclude=$i" fi done fi # signature update freshclam # virus scan clamscan --recursive --remove ${excludeopt} / |
1 |
# chmod 700 clamscan.sh |
Specify scan exclusion directory
1 2 |
# echo "/sys/" >> /var/www/system/clamscan.exclude # echo "/proc/" >> /var/www/system/clamscan.exclude |
3)Set up a regular virus scan.
1 2 |
# crontab -e 0 1 * * * /var/www/system/clamscan.sh > /dev/null 2>&1 |
Run a scan at 1 a.m. every day with the above settings