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

Squid 代理伺服器快取配置實戰:記憶體與磁碟快取參數調優

編輯:關於伺服器

環境

CentOS 5.3,自編譯 Squid。

核心配置 (/etc/squid/squid.conf)

# 代理埠 (避開 80/8080 衝突)
http_port 8086

# 記憶體快取大小 (伺服器 2GB 記憶體,分配 1GB)
cache_mem 1000 MB

# 磁碟快取目錄與結構
# ufs: 儲存格式
# /var/spool/squid: 快取目錄
# 1000: 最大使用空間 (MB),需 >= cache_mem
# 16: 一級子目錄數
# 256: 二級子目錄數
cache_dir ufs /var/spool/squid 1000 16 256

# 允許所有客戶端存取 (預設拒絕)
http_access allow all

# 可見主機名 (避免啟動警告)
visible_hostname zhhproxy

初始化與啟動

# 建立快取目錄結構
squid -z

# 前台除錯模式 (輸出 Ready to serve requests. 表示就緒)
squid -NCd1

# 正式啟動 (背景精靈進程)
squid

關鍵參數說明

  • cache_mem:熱門物件駐留記憶體,**不包含** 索引、元資料開銷,實際佔用約 1.5-2 倍。
  • cache_dir 第一參數 (大小) 必須 ≥ cache_mem,否則警告 WARNING cache_mem is larger than total disk cache space!。
  • maximum_object_size (預設 4MB) 若需快取大檔案 (ISO、視頻) 需調大:maximum_object_size 1024 MB。
  • refresh_pattern 控制快取更新策略,可依檔案類型差異化設定。

驗證

# 檢視快取統計
squidclient mgr:info
# 或瀏覽器設定代理後訪問 https://cachemgr.example.com/
Copyright © Windows教程網 All Rights Reserved