clamav流程圖
一鍵安裝
搭建clamav
雳灵,并監(jiān)聽clamd服務(wù),發(fā)布對(duì)外調(diào)用接口
#!/bin/bash
## Date: 2018-09-25
## Author Browser
## Describtion Install clamav
## Version: 1.0
ADDRESS=ip addr | grep "inet" | grep -v "inet6" | grep -v "127.0.0.1" | awk -F '[ /]+' '{print $3}'
###dependence
yum -y install wget unzip zip gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel llvm-devel libxml2 libxml2-devel libcurl-devel
###download and compiling
wget https://www.clamav.net/downloads/production/clamav-0.100.1.tar.gz
tar -zxvf clamav-0.100.1.tar.gz
cd clamav-0.100.1
./configure --prefix=/opt/clamav
make && make install
###configure
cp /opt/clamav/etc/clamd.conf.sample /opt/clamav/etc/clamd.conf
cp /opt/clamav/etc/freshclam.conf.sample /opt/clamav/etc/freshclam.conf
### Setting
groupadd clamav
useradd clamav -g clamav -s /sbin/nologin
mkdir -p /opt/clamav/logs
mkdir -p /opt/clamav/share/clamav
mkdir -p /opt/clamav/worktmp
touch /opt/clamav/logs/freshclam.log
touch /opt/clamav/logs/clamd.log
chown -R clamav:clamav /opt/clamav
###freshclam.conf
sed -i 's/^Example/\#Example/g' /opt/clamav/etc/freshclam.conf
sed -i 's/^#DatabaseDirectory\ \/var\/lib\/clamav/DatabaseDirectory\ \/opt\/clamav\/share\/clamav/g' /opt/clamav/etc/freshclam.conf
sed -i 's/^#UpdataLogFile\ \/var\/log\/freshclam\.log/UpdateLogFile\ \/opt\/clamav\/logs\/freshclam\.log/g' /opt/clamav/etc/freshclam.conf
sed -i 's/^#PidFile\ \/var\/run\/freshclam\.pid/PidFile\ \/opt\/clamav\/worktmp\/freshclam\.pid/g' /opt/clamav/etc/freshclam.conf
###clamd.conf
sed -i 's/^Example/\#Example/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#LogFile\ \/tmp\/clamd\.log/LogFile\ \/opt\/clamav\/logs\/clamd\.log/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#PidFile\ \/var\/run\/clamd.pid/PidFile\ \/opt\/clamav\/worktmp\/clamd.pid/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#DatabaseDirectory\ \/var\/lib\/clamav/DatabaseDirectory\ \/opt\/clamav\/share\/clamav/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#LocalSocket\ \/tmp\/clamd.socket/LocalSocket\ \/opt\/clamav\/worktmp\/clamd.socket/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#TCPSocket\ 3310/TCPSocket\ 3310/g' /opt/clamav/etc/clamd.conf
sed -i "s/^#TCPAddr\ 127\.0\.0\.1/TCPAddr\ $ADDRESS/g" /opt/clamav/etc/clamd.conf
sed -i 's/^#LogFileMaxSize\ 2M/LogFileMaxSize\ 100M/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#LogVerbose\ yes/LogVerbose\ yes/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#LogRotate\ yes/LogRotate\ yes/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#ExtendedDetectionInfo\ yes/ExtendedDetectionInfo\ yes/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#FixStaleSocket\ yes/FixStaleSocket\ yes/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#MaxConnectionQueueLength\ 30/MaxConnectionQueueLength\ 500/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#MaxThreads\ 20/MaxThreads\ 50/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#ReadTimeout\ 300/ReadTimeout\ 300/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#CommandReadTimeout\ 5/CommandReadTimeout\ 5/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#SendBufTimeout\ 200/SendBufTimeout\ 200/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#MaxQueue\ 200/MaxQueue\ 500/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#MaxScanSize\ 150M/MaxScanSize\ 150M/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#MaxFileSize\ 30M/MaxFileSize\ 150M/g' /opt/clamav/etc/clamd.conf
sed -i 's/^#StreamMaxLength\ 10M/StreamMaxLength\ 150M/g' /opt/clamav/etc/clamd.conf
###update virus_data
/opt/clamav/bin/freshclam
#如果首次更新失敗缨称,可以直接從官網(wǎng)下載病毒庫
#cd /opt/clamav/share/clamav
#wget http://database.clamav.net/main.cvd
#wget http://database.clamav.net/daily.cvd
#wget http://database.clamav.net/bytecode.cvd
###start the service
systemctl enable clamav-daemon.service
systemctl start clamav-daemon.service
systemctl enable clamav-freshclam.service
systemctl start clamav-freshclam.service
###soft connection
ln -s /opt/clamav/bin/clamscan /usr/local/bin/clamscan
ln -s /opt/clamav/bin/freshclam /usr/local/bin/freshclam
ln -s /opt/clamav/bin/clamdscan /usr/local/bin/clamdscan
### 添加定時(shí)掃描任務(wù)
mkdir -p /tmp/virus
echo '0 1 * * * /opt/clamav/bin/clamscan -r -i --move=/tmp/virus / >/dev/null 2>&1' >>/etc/crontab
接口調(diào)用亚茬,參數(shù)配置
cat /opt/clamav/etc/clamd.conf | grep -v "^[#|$]" | grep -v "^$"
LogFile /opt/clamav/logs/clamd.log
LogFileMaxSize 100M
LogVerbose yes
LogRotate yes
ExtendedDetectionInfo yes
PidFile /opt/clamav/worktmp/clamd.pid
DatabaseDirectory /opt/clamav/share/clamav
LocalSocket /opt/clamav/worktmp/clamd.socket
FixStaleSocket yes
TCPSocket 3310
TCPAddr 192.168.204.11
MaxConnectionQueueLength 500
StreamMaxLength 150M
MaxThreads 50
ReadTimeout 300
MaxQueue 100
MaxScanSize 150M
MaxFileSize 150M