Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

CentOS 6 快速構建企業級 Web 代理伺服器:Squid + ClamAV + ICAP 完整部署指南

編輯:Linux 教學

前言

企業級 Web Proxy 不僅能透過快取加速瀏覽、節省頻寬,更能整合防毒掃描、URL 過濾、存取控制,保障內網安全。本文以 CentOS 6 為基礎,逐步部署 Squid(代理核心)+ ClamAV(防毒引擎)+ C-ICAP(ICAP 服務)+ SquidClamav(ICAP 防毒模組) 完整鏈路。

架構總覽

  • Squid:監聽 3128 埠,處理 HTTP/HTTPS 代理與快取。
  • C-ICAP:運行於 1344 埠,提供 ICAP 協定介面供 Squid 呼叫外部掃描服務。
  • SquidClamav:C-ICAP 模組,接收 Squid 轉發的內容,調用 ClamAV 掃描。
  • ClamAV:防毒引擎,含 clamd(守護進程)與 freshclam(病毒碼自動更新)。

1. 基礎環境與 Squid 安裝

# 最小安裝 CentOS 6 後
yum install -y squid
chkconfig squid on

修改 /etc/squid/squid.conf

  • 啟用磁碟快取:取消註解 cache_dir ufs /var/spool/squid 1000 16 256(建議 1000MB 以上)。
  • 於檔案末尾加入 ICAP 整合配置:
icap_enable on
icap_send_client_ip on
icap_send_client_username on
icap_client_username_encode off
icap_client_username_header X-Authenticated-User
icap_preview_enable on
icap_preview_size 2048
icap_service service_req reqmod_precache bypass=1 icap://127.0.0.1:1344/squidclamav
adaptation_access service_req allow all
icap_service service_resp respmod_precache bypass=1 icap://127.0.0.1:1344/squidclamav
adaptation_access service_resp allow all

2. ClamAV 安裝與配置 (需 EPEL)

rpm -ivh https://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
yum install -y clamav clamav-db clamd
chkconfig clamd on

編輯 /etc/clamd.conf

  • 刪除首行 Example 使服務可啟動。
  • 依需求調整 MaxFileSize(預設 25MB)、MaxScanSize(預設 100MB)、掃描目標類型(ScanPE/ScanELF/ScanPDF)。

病毒碼自動更新 /etc/freshclam.conf

  • 同樣刪除 Example 行。
  • 啟用 Google Safe Browsing:SafeBrowsing yes。
  • 以 Daemon 模式每天更新 2 次:freshclam -d -c 2,加入 /etc/rc.local 開機自啟。

3. C-ICAP 來源碼編譯安裝

wget https://sourceforge.net/projects/c-icap/files/c-icap/0.5.x/c_icap-0.5.2.tar.gz
tar zxvf c_icap-0.5.2.tar.gz && cd c_icap-0.5.2
./configure --prefix=/usr/local && make && make install
  • 編輯 /usr/local/etc/c-icap.conf:設定 ServerLog /var/log/icapserver.log、確認 ModulesDir/ServicesDir 指向 /usr/local/lib/c_icap。
  • 開機自啟:echo "/usr/local/bin/c-icap" >> /etc/rc.local。

4. SquidClamav 來源碼編譯安裝


wget https://sourceforge.net/projects/squidclamav/files/squidclamav/6.x/squidclamav-6.16.tar.gz
tar zxvf squidclamav-6.16.tar.gz && cd squidclamav-6.16
./configure --with-c-icap=/usr/local --with-clamd=/usr/local/sbin/clamd && make && make install
  • 驗證 /usr/local/lib/c_icap 下出現 squidclamav.la、squidclamav.so。
  • 編輯 /etc/squidclamav.conf:設定 redirect https://your.domain/cgi-bin/clwarn.cgi(需部署警告頁面)。
  • 將原始碼附帶的 cgi-bin/clwarn.cgi 部署至 Web 伺服器。

5. 防火牆與測試

# 開放 3128 埠
iptables -I INPUT -p tcp --dport 3128 -j ACCEPT
service iptables save

瀏覽器設定

HTTP Proxy:Proxy 伺服器 IP,Port:3128。驗證瀏覽正常、快取生效(查看 /var/log/squid/access.log)。

防毒測試 (EICAR 測試檔)

  1. 建立測試檔:echo 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > eicar.com。
  2. 上傳至測試 Web 伺服器,透過 Proxy 下載。
  3. 查看 /var/log/icapserver.log 應出現:
DEBUG squidclamav_end_of_data_handler: received from Clamd: stream: Eicar-Test-Signature FOUND
DEBUG squidclamav_end_of_data_handler: Virus redirection: https://your.domain/cgi-bin/clwarn.cgi?url=...

6. 進階擴充建議

  • 安全 DNS:整合 Norton DNS / OpenDNS 封鎖惡意域名與成人內容。
  • URL 過濾:部署 SquidGuard 搭配黑名單(如 shallalist),依使用者群組管控存取權限。
  • HTTPS 檢測:配置 Squid SSL-Bump 解密檢測加密流量(需憑證管理)。
  • 商業替代方案:若開源方案無法滿足合規/效能需求,可評估 SmoothWall、Blue Coat 等商用產品。

維運關鍵日誌

服務日誌路徑用途
Squid/var/log/squid/access.log存取記錄、快取命中率分析
C-ICAP/var/log/icapserver.logICAP 交互、掃描結果、病毒攔截
ClamAV/var/log/clamav/clamd.log掃描引擎狀態、病毒碼更新
Copyright © Windows教程網 All Rights Reserved