目錄:
? 一.測試安裝環境
? 二.編譯安裝
? 三.Squid工作模式及原理
n 3.1 SQUID如何工作
u 3.1.1 [傳統代理]
u 3.1.2[透明代理]
u 3.1.3[反向代理]
n 3.2 SQUID工作原理
u 3.2.1 SQUID緩存的存放方式:
u 3.2.2SQUID的查詢方式
u 3.2.3SQUID服務器之間的關係:
u 3.2.4SQUID運作模式
? 四.Squid 配置
n 4.1 主配置文檔配置
n 4.2驗證squid.conf的語法和配置
n 4.3初始化cache目錄
n 4.4前臺啓動squid,查看是否報錯
n 4.5透明代理設置
n 4.6反向代理設置
? 五.Squid語法
? 六.Squid優化
n 6.1 日誌優化
n 6.2目錄優化
n 6.3 Cache優化
n 6.4最大文件描述符數量限制優化
n 6.5 腳本優化優化
u 6.5.1 log腳本:
u 6.5.2squid腳本:
u 6.5.3Cache 腳本:
? 七.腳本用法
n 7.1 log腳本:
n 7.2 squid腳本:
n 7.3 Cache 腳本:
? 八.補充
n 8.1 打補丁
n 8.2 重運行configure
n 8.3 nginx 與squid
? 九.Cachemgr.cgi監控squid運行狀態
n 9.1 Cachemgr.cgi配置過程
n 9.2 生成口令文件
n 9.3 驗證
? 十.錯誤總結
n 10.1 權限問題
n 10.2 不能識別它自己的完整可驗證域名
n 10.3 版本更新問題
n 10.4 Squid無法反向代理多個後臺WEB服務器
n 10.5 在運行一段時間後,Squid變慢了
聲明:
本文檔參考網上很多squid配置文檔結合自己的實際配置寫出來的,主要針對的是squid配置方面。對於其認證和限制方面沒有太多的介紹,請大家則而觀之,一面浪費自己寶貴的時間。有機會的話,我會把認證和限制方面的做部分介紹。
===============================================================================
感慨:
古人云:溫故而知新。此言絕非說說而已,在離開學堂才短短3個月而已,一個簡單的squid竟然困擾了我兩天才把基本的測試頁顯示出來。想當初這只是幾分鐘的事啊!!真是慚愧!!哎。現在趁熱打鐵,趕緊將自己以前忘記的都記下來,這裏有什麼太過簡單的東西,請大家海涵!
===============================================================================
++++++++++++++++++++++++++++++++++++++++++++++++
一.測試安裝環境:
Squid Server IP:
eth0 192.168.77.222
eth1 192.168.7.222
Http Server IP:
eth0 192.168.77.225
Client Ip:
eth0 192.168.7.223
CentOS 內核版本:
[root@rs_200_143 ~]# uname -r
2.6.18-128.el5xen
Squid源代碼包版本號:
http://www.squid-cache.org/Versions/v3/3.1/ squid-3.1.4.tar.gz
squid-3.1.4
安裝目錄:
/usr/local/squid
squid log目錄:
/usr/local/squid/var/logs
+++++++++++++++++++++++++++++++++++++++++++
二.編譯安裝:
[root@song squid-3.1.4]#./configure --prefix=/usr/local/squid \
--enable-gnuregex \
--disable-carp \
--enable-async-io=240 \
--with-pthreads \
--enable-storeio=ufs,aufs,diskd \
--disable-wccp \
–enable-icmp \
--enable-kill-parent-hack \
--enable-cachemgr-hostname=localhost \
--enable-default-err-language=Simplify_Chinese \
--with-maxfd=65535 \
--enable-poll \
--enable-linux-netfilter \
--enable-large-cache-files \
--disable-ident-lookups \
--enable-default-hostsfile=/etc/hosts \
--with-dl \
--with-large-files \
--enable-delay-pools \
--enable-snmp \
--disable-internal-dns \
–enable-underscore\
–enable-arp-acl
[root@song Squid]# make && make install
釋:
–prefix=/usr/local/squid :指定軟件的安裝路徑
–enable-gnuregex :支持GNU正則表達式。
–disable-carp: Cache數組路由協議(CARP)用來轉發丟失的cache到父cache的數組或cluste
–enable-async-io=240等同於同時打開./configure如下三個選項
--with-aufs-threads=N_THREADS
--with-pthreads
--enable-storeio=ufs,aufs
這個主要是設置async模式來運行squid,我的理解是設置用線程來運行squid,如果服務器配置很不錯,有1G以上內存,cpu使用SMP的方式的話可以考慮設成160或者更高。如果服務器比較糟糕就根據實際情況設了。另外此項還另cache文件支持aufs
--disable-wccp用於阻止或分發HTTP請求到一個或多個caches
–enable-icmp :加入icmp支持
–enable-kill-parent-hack :關掉suqid的時候,要不要連同父進程一起關掉
--enable-cachemgr-hostname=localhost:指定cachemgr-hostname值爲localhost
-- enable-snmp :此選項可以讓MRTG使用SNMP協議對服務器的流量狀態進行監測,因此必須選擇此項,使Squid支持SNMP接口。
–disable-ident-lookups :防止系統使用RFC931規定的身份識別方法。
--enable-delay-pools 開啓squid延時池功能
–enable-cahce-digests :加快請求時,檢索緩存內容的速度。
–enable-err-language=”Simplify_Chinese” 和
–enable-default-err-languages=”Simplify_Chinese” :指定出錯是顯示的錯誤頁面爲簡體中文
--with-maxfd=65535指定最大文件描述
–enable-poll :指定使用Poll()函數,提升性能就是啦。
--disable-ident-lookups允許服務器利用客戶端的特殊TCP連接來發現用戶名
–enable-linux-netfilter :可以支持透明代理
--enable-large-cache-files開啓大文件支持,支持2GB以上的文件
--disable-internal-dns使用自己的內部DNS查詢
–enable-underscore :允許解析的URL中出現下劃線,因爲默認squid會認爲帶下劃線的URL地址是非法的,並拒絕訪問該地址
–enable-arp-acl :可以在規則設置中直接通過客戶端的MAC地址進行管理,防止客戶使用IP欺騙。
[root@song Squid]# make && make install
釋:
–prefix=/usr/local/squid :指定軟件的安裝路徑
–enable-gnuregex :由於Squid大量使用字符串處理做各種判斷,加入此項能更好的處理,激活使用GNU正則表達式。
–disable-carp: Cache數組路由協議(CARP)用來轉發丟失的cache到父cache的數組或cluste
–enable-async-io=80 :等同於同時打開./configure如下三個選項
--with-aufs-threads=N_THREADS
--with-pthreads
--enable-storeio=ufs,aufs
這個主要是設置async模式來運行squid,我的理解是設置用線程來運行squid,如果服務器配置很不錯,有1G以上內存,cpu使用SMP的方式的話可以考慮設成160或者更高。如果服務器比較糟糕就根據實際情況設了。另外此項還另cache文件支持aufs
–enable-icmp :加入icmp支持
–enable-kill-parent-hack :關掉suqid的時候,要不要連同父進程一起關掉
–enable-snmp :此選項可以讓MRTG使用SNMP協議對服務器的流量狀態進行監測,因此必須選擇此項,使Squid支持SNMP接口。
–disable-ident-lookups :防止系統使用RFC931規定的身份識別方法。
–enable-cahce-digests :加快請求時,檢索緩存內容的速度。
–enable-arp-acl :可以在規則設置中直接通過客戶端的MAC地址進行管理,防止客戶使用IP欺騙。
–enable-err-language=”Simplify_Chinese” 和
–enable-default-err-languages=”Simplify_Chinese” :指定出錯是顯示的錯誤頁面爲簡體中文
–enable-poll :應啓用Poll()函數而不是select()函數,通常而言poll(輪詢)比select要好,但configure(腳本程序)已知Poll在某 些平臺下失效, 若你認爲你比configure編譯配置腳本程序要聰明的話,可以用這個選項啓用Poll。總之就是用這個可以提升性能就是啦。
–enable-linux-netfilter :可以支持透明代理
–enable-underscore :允許解析的URL中出現下劃先,因爲默認squid會認爲帶下劃線的URL地址是非法的,並拒絕訪問該地址
+++++++++++++++++++++++++++++++++++++++++++
三.Squid工作模式及原理
環境:
Squid:192.168.77.222
Client:192.168.7.223
Server: 192.168.77.223
+++++++++++++++++++++++++++++++
SQUID如何工作
[傳統代理]
1.SQUID被綁定到代理服務器的3128端口。
2. 客戶端瀏覽器被配置使用代理服務器的3128端口。
3.客戶端不需要配置DNS。
4.代理服務器上需要配置代理服務器。
5.客戶端不需要 配置缺省路由。
當我們在客戶端瀏覽器中打開一個web請求,比如“http://www.baidu.com”,這時將陸續發生以下事件:
1. 客戶端使用某一端口(比如1025)連接代理服務器3128端口,請求web頁面“http://www.baidu.com”
2.代理服務器向 DNS請求“www.baidu.com”,得到相應的IP地址192.168.77.223。然後,代理服務器使用某一端口(比如1037)向該IP地址的80端口發 起web連接請求,請求web頁面。
3.收到響應的web頁面後,代理服務器把該數據傳送給客戶端。
4.客戶端瀏覽器顯示該頁面。
從 www.baidu.com的角度看來,連接是在192.168.77.222地1037端口和192.168.77.223的80端口之間建立的。
從client的角度看 來,連接是在192.168.7.223的1025端口和192.168.77.222的3128端口之間建立的。
[透明代理]
透明代理的意思是客戶端根本不需要知道有代理服務器 的存在。
在以上基礎上我們做以下工作:
1.配置透明代理服務器軟件運行在代理服務器的3128端口。
2.配置代理服務器將所有對 80端口的連接重定向到3128端口。
3.配置客戶端瀏覽器直接連解到Internet。
4.在客戶端配置好DNS.
5.配置客 戶端的缺省網關爲192.168.1.1.
當我們在客戶端瀏覽器中打開一個web請求,比如 “http://www.baidu.com”,這時將陸續發生以下事件:
1.客戶端向DNS請求“www.baidu.com”,得到相應的 IP地址192.168.77.223。然後,客戶端使用某一端口(比如1066)向該IP地址的80端口發起web連接請求,請求web頁面。
2.當該請求包 通過透明代理服務器時,被防火牆將該數據包重定向到代理服務器的綁定端口3128。於是,透明
代理服務器用某一端口(比如1088)向 192.168.77.223的80端口發起web連接請求,請求web頁面。
3.收到響應的web頁面後,代理服務器把該數據傳送給客戶端。
4.客戶 端瀏覽器顯示該頁面。
從www.baidu.com的角度看來,連接是在192.168.77.222地1088端口和192.168.77.223的80端口之間建立的。從 client的角度看來,連接是在192.168.7.223的1066端口和192.168.77.223的80端口之間建立的。
以上就是傳統代理服務器和透 明代理服務器的區別所在。
[反向代理]
反向代理是相對於傳統代理而言,是代理web服務器接受客戶端的請求
在此,我們忽略客戶端的設置,假設客戶端是可以直接訪問互聯網
web服務器與客戶端的結構如下:
假設已經將www.baidu.com的域名指向了squid服務器所在的ip,並且在web服務器集羣裏做了dns輪詢。
web server1 -|
web server2 -|- squid 服務器/ INTERNET / - Client
web server3 -|
1.客戶端通過IE向DNS服務器發送訪問www.baidu.com的請求,由客戶所在地的DNS服務器解析www.baidu.com的IP爲192.168.77.223並返回給用戶。
2.客戶收到DNS返回的服務器IP地址,重新向 www.baidu.com指向的IP地址發送訪問請求。
3.squid服務器接收到用戶的請求後,查詢自身緩存中是否有用戶請求內容,有則直接發送給客戶端,如果沒有則通過內部DNS輪詢查詢空閒服務器,並將客戶請求發送到該服務器,在獲取到用戶數據並返回給用戶的同時保留一份在自己本身的緩存當中。在用戶看來,自己訪問的是www.baidu.com這個服務器,實際上真正的WEB服務器爲SQUID緩存後面的服務器或者服務器集羣,通過外部DNS做CNAME轉向,將用戶請求轉發到內部真正的web服務器上去
SQUID工作原理
一、SQUID緩存的存放方式:
每一臺Squid 代理服務器上都有若干顆硬盤,每顆硬盤又分割成多個分區,每一個分區又可建立很多目錄,目錄下才放文件(Squid 把它叫object)。
二、 SQUID的查詢方式:
SQUID通過查詢表的方式來定位某個資源的位置,所查詢的表叫Hash table 和Digest table;Digest table在這裏可以稱之爲摘要或者索引,它記錄了磁盤上每個分區,每個目錄裏存的緩存摘要,Hash table在這裏可以稱之爲目錄或者提綱,它記錄所有的Digest table表信息,SQUID接受到請求後先查詢Hash table,在根據Hash table所指向的Digest table查詢需要的信息。
三、SQUID服務器之間的關係:
SQUID 服務器存在兩種工作關係,一種爲Child、Parent,當child squid server沒有用戶需要的數據時,就象parent server發出請求,並持續等待,直到parent server迴應自己爲止;另外一種爲ibling,當本地SQUID server沒有用戶請求數據時,會向sibling server發出請求,如果sibling server沒有資料則會向上級sibling或者INTERNET發送數據請求
四、SQUID運作模式
1. 當Squid Server沒有資料時,會先向Sibling 的Squid Server 要資料,如果Sibling沒資料,就跳過它直接向Parent 要。
2. 向Parent 要資料,然後一直等,直到Parent 給它資料爲止(Parent 自己有的資料或上Internet 去拿)。
3. 沒有Parent 時,就自己上Internet 去拿。
4. 如果這三者都拿不到資料,才向用戶端回報拿不到資料。
一般而言,把網路上 一層的Squid Server 設成Sibling 是不錯的選擇(例如:一個學校將所在城市網和附近的大學設成Sibling),因爲網路上一層的Squid Server 服務對象較多,其硬件功能較強,離我們比較近,速度也比較快;萬一要不到資料,我們還可以自己上Internet 去拿。那什麼時候設Parent?當您的出口只有一個,或上一層Squid Server 拿不到資料,自己也一定拿不到,只好將上一層Squid Server 設爲Parent。
+++++++++++++++++++++++++++++++++++++++++++
四.Squid 配置:
賦/ usr/local/squid/var/logs/ 777 權限:
[root@song squid]# chmod 777 /usr/local/squid/var/logs/
主配置文檔配置:
/var/local/squid/etc/squid.conf
#acl limit
acl woyoSYS src 192.168.77.0/24
http_access allow woyoSYS
#cache limit
cache_dir ufs /usr/local/squid/var/cache 100 16 256
cache_mem 100 MB
cache_swap_low 90
cache_swap_high 95
cache_access_log /usr/local/squid/var/logs/access.log
cache_log /usr/local/squid/var/logs/cache.log
cache_store_log /usr/local/squid/var/logs/store.log
coredump_dir /usr/local/squid/var/cache
cache_mgr [email protected]
visible_hostname song.domain.com #必須指明自己的主機名,否則squid無法正常啓動
http_port 192.168.7.222:3128 transparent #squid監聽192.168.7.222的3128端口
驗證squid.conf的語法和配置:
[root@song ~]# /usr/local/squid/sbin/squid -k parse
2010/07/06 05:38:15| Processing Configuration File: /usr/local/squid/etc/squid.conf (depth 0)
2010/07/06 05:38:15| Starting Authentication on port 192.168.7.222:3128
2010/07/06 05:38:15| Disabling Authentication on port 192.168.7.222:3128 (interception enabled)
2010/07/06 05:38:15| Disabling IPv6 on port 192.168.7.222:3128 (interception enabled)
初始化cache目錄:
在初次運行squid之前,或者無論何時你增加了新的cache_dir,你必須初始化cache目錄。命令很簡單
[root@song sbin]# ./squid -z
2010/07/05 18:06:36| Creating Swap Directories
前臺啓動squid,查看是否報錯:
[root@song ~]# /usr/local/squid/sbin/squid -N -d1
2010/07/06 05:42:43| Starting Squid Cache version 3.1.4 for i686-pc-linux-gnu...
2010/07/06 05:42:43| Process ID 10240
2010/07/06 05:42:43| With 1024 file descriptors available
2010/07/06 05:42:43| Initializing IP Cache...
2010/07/06 05:42:43| helperOpenServers: Starting 5/5 'dnsserver' processes
2010/07/06 05:42:43| Unlinkd pipe opened on FD 19
2010/07/06 05:42:44| Swap maxSize 102400 + 102400 KB, estimated 15753 objects
2010/07/06 05:42:44| Target number of buckets: 787
2010/07/06 05:42:44| Using 8192 Store buckets
2010/07/06 05:42:44| Max Mem size: 102400 KB
2010/07/06 05:42:44| Max Swap size: 102400 KB
2010/07/06 05:42:44| Version 1 of swap file with LFS support detected...
2010/07/06 05:42:44| Rebuilding storage in /usr/local/squid/var/cache (DIRTY)
2010/07/06 05:42:44| Using Least Load store dir selection
2010/07/06 05:42:44| Set Current Directory to /usr/local/squid/var/cache
2010/07/06 05:42:44| Loaded Icons.
2010/07/06 05:42:44| Accepting intercepted HTTP connections at 192.168.7.222:3128, FD 23.
2010/07/06 05:42:44| HTCP Disabled.
2010/07/06 05:42:44| Squid modules loaded: 0
2010/07/06 05:42:44| Ready to serve requests.
2010/07/06 05:42:44| Done reading /usr/local/squid/var/cache swaplog (1 entries)
2010/07/06 05:42:44| Finished rebuilding storage from disk.
2010/07/06 05:42:44| 1 Entries scanned
2010/07/06 05:42:44| 0 Invalid entries.
2010/07/06 05:42:44| 0 With invalid flags.
2010/07/06 05:42:44| 1 Objects loaded.
2010/07/06 05:42:44| 0 Objects expired.
2010/07/06 05:42:44| 0 Objects cancelled.
2010/07/06 05:42:44| 0 Duplicate URLs purged.
2010/07/06 05:42:44| 0 Swapfile clashes avoided.
2010/07/06 05:42:44| Took 0.10 seconds ( 9.63 objects/sec).
2010/07/06 05:42:44| Beginning Validation Procedure
2010/07/06 05:42:44| Completed Validation Procedure
2010/07/06 05:42:44| Validated 27 Entries
2010/07/06 05:42:44| store_swap_size = 4
2010/07/06 05:42:44| storeLateRelease: released 0 objects
有個下面這句就可以試着啓動squid了
2010/07/06 05:42:44| Ready to serve requests.
透明代理設置:
1.透明代理中一定要把client的網關指向squid,否則無法使正常代理
2.Squid.conf編輯:http_port 192.168.7.222:3128 transparent #支持透明代理
3. # iptables -t nat -A PREROUTING -s 192.168.7.223/32 -p tcp --dport 80 -j REDIRECT --to-port 3128
4. # service iptables save
反向代理設置:
1.Squid.conf編輯:http_port 192.168.7.222:80 vhost vport #支持域名和IP的虛擬主機
2. 實例:
cache_peer 192.168.77.222 parent 81 0 no-query originserver weight=1 name=a
cache_peer 192.168.77.222 parent 82 0 no-query originserver weight=1 name=b
#cache_peer 192.168.77.253 parent 80 0 no-query originserver weight=1 name=c
cache_peer_domain a www.serverA1.com
cache_peer_domain b www.serverA2.com
#cache_peer_domain c www.serverB.com
#以上六行配置,讓 Squid 服務器知道:
#從客戶端過來的請求,如果是 www.serverA1.com,則 Squid 向 ServerA 192.168.77.222 的端口 81發送請求;
#從客戶端過來的請求,如果是 www.serverA2.com,則 Squid 向 ServerA 192.168.77.222 的端口 82發送請求;
#從客戶端過來的請 求,如果是 www.serverB.com,則 Squid 向 ServerA 192.168.77.51 的端口 80發送請求;
+++++++++++++++++++++++++++++++++++++++++++
五.Squid語法:
啓動squid 服務
# /usr/local/squid/sbin/squid -s
停止squid 服務
# /usr/local/squid/sbin/squid -k shutdown
Squid用法幫助信息
# /usr/local/squid/sbin/squid -h
在初次運行squid之前,或者無論何時你增加了新的cache_dir,你必須初始化cache目錄。命令很簡單:
#/usr/local/squid/sbin/squid -z
重配置運行中的squid最好的方法是使用squid -k reconfigure命令:
#/usr/local/squid/sbin/squid -k reconfigure
週期性的滾動日誌文件,以阻止它們變得太大
#/usr/local/squid/sbin/squid -k rotate
在前臺啓動squid,並輸出啓動過程。
#squid/sbin/squid -N -d1
可以根據這個測試命令用來驗證squid.conf的語法和配置
#/usr/local/squid/sbin/squid -k parse
+++++++++++++++++++++++++++++++++++++++++++
六.Squid優化:
1.日誌週期性滾動:
0 4 * * * /usr/local/squid/sbin/squid -k rotate &
2.Log 目錄週期性檢查:
0 4 * * 6 /usr/local/squid/movelog.sh &
3.Cache週期性優化:
0 4 * * * /usr/local/squid/clear_squid_cache.sh gif &
0 4 * * * /usr/local/squid/clear_squid_cache.sh swf &
0 4 * * * /usr/local/squid/clear_squid_cache.sh gif &
4.最大文件描述符數量限制優化:
通常情況下,Squid 默認爲1024個文件描述,一般情況已經夠用。當系同高度繁忙時,肯能會用到4096個或更大。在編譯 Squid 前推薦將描述符更改至,系統限制級別的 2~3倍
-H 設置硬件資源限制.
-S 設置軟件資源限制
-n size:設置內核可以同時打開的文件描述符的最大值.單位:n
查看默認文件描述符數量:
# ulimit -n
1024
臨時修改文件描述符數量
# ulimit –SHn 65536
永久修改文件描述符數量
# vim /usr/include/bits/typesizes.h
#define __FD_SETSIZE 65536
#vi /etc/security/limits.conf
* hard nofile 102400
* soft nofile 102400
# vim /etc/sysctl.conf
fs.file-max=102400
# ulimit -n
6553
5.腳本優化:
log腳本:
# cat /usr/local/squid/movelog.sh
#!/bin/bash
SLOG=`du -sh /usr/local/squid/var/logs/ | awk '{print $1}' | awk -F '.' '{print $1}'`
if [ $SLOG -gt 100 ];then
if [ ! -d /var/log/squid ];then
mkdir /var/log/squid
else
mv /usr/local/squid/var/logs/ /var/log/squid
echo "move squid log to /var/logs" | mail -s [email protected]
fi
else
echo "The size of /usr/local/squid/var/logs/ is `du -sh /usr/local/squid/var/logs/ | awk '{print $1}' | awk -F 'M' '{print $1}'`"
fi
squid腳本:
# cat /usr/local/squid/squid.sh
#!/bin/bash
# this script is for Squid
case "$1" in
start)
/usr/local/squid/sbin/squid –s
sleep 1
if netstat -tnulp | grep squid ;then echo "squid is start" ;else echo "please check it";fi
;;
stop)
/usr/local/squid/sbin/squid -k shutdown
sleep 1
if ! netstat -tnulp | grep squid ;then echo "squid is stop" ;else echo "please check it";fi
;;
status)
if netstat -tnulp | grep squid ;then echo "squid is running" ;else echo "squid is stop";fi
;;
reload)
/usr/local/squid/sbin/squid -k reconfigure
sleep 1
if netstat -tnulp | grep squid ;then echo "squid is reload" ;else echo "please check it";fi
;;
restart)
if netstat -tnulp | grep squid ;then echo "Squid proess is running" ;else
/usr/local/squid/sbin/squid -k shutdown && /usr/local/squid/sbin/squid -s
sleep 1
if netstat -tnulp | grep squid ;then echo "squid is restart" ;else echo "please check it";fi
fi
;;
esac
Cache 腳本:
# cat clear_squid_cache.sh
#!/bin/bash
squidcache_path="/usr/local/squid/var/cache"
squidclient_path="/usr/local/squid/bin/squidclient"
grep -a -r $1 $squidcache_path/* | strings | grep "http:" | awk -F'http:' '{print "http:"$2;}' | grep [a-zA-Z0-9]$ > cache_list.txt
for url in `cat cache_list.txt`; do
$squidclient_path -m PURGE -p 3128 $url
Done
+++++++++++++++++++++++++++++++++++++++++++++++
七.腳本用法:
Cache腳本用法:
清楚所有Flash緩存(擴展名.swf)
# /usr/local/squid/clear_squid_cache.sh swf
Squid.sh腳本用法:
/usr/local/squid/sbin/squid.sh | Squid.sh start | stop | status | restart | reload
+++++++++++++++++++++++++++++++++++++++++++
八. 補充
1. 打補丁
在你運行squid一段時間後,你可能發現需要打源代碼補丁,用以修正bug或者增加試驗性的功能
爲了打補丁-或者有時候叫差別文件-你需要一個叫做"patch"的程序。你的操作系統必須有該程序。如果沒有,你可以從GNU工具集裏下載(http://www.gnu.org/directory/patch.html).
爲了打補丁,你必須把補丁文件存放在系統中某處。然後進入到squid的源代碼目錄,運行如下命令:
#patch < /tmp/patch_file
2. 重運行configure
有時候你可能發現有必要重新運行./configure。例如,假如你調整了內核參數,你必須再次運行./configure以使它能發現新設置
在運行./configure之後,你必須再次編譯和安裝squid。安全起見,建議先運行make clean:
#make clean
以相同的選項重運行./configure,使用如下命令:
#config.status –recheck
3. 假如想讓squid既作cache代理,又作加速器,那麼列出這2個端口:
http_port 80
http_port 3128
這裏囉嗦下,當squid監聽自己的80端口作反向代理是時,client默認訪問的就是自己的80端口,所以在client的IE中訪問時就不用輸入特定的代理端口號。這裏我其實也不知道要表達一個什麼意思,但是我以前在長時間沒有接觸squid時,在這裏暈了。呵呵,如果大俠們沒有在這裏暈過話,不用考慮,直接過!希望新手們能稍稍注意下。呵呵
4.nginx 與squid
Nginx高併發處理能力遠遠大於Squid,因此,在分佈大量的靜態文件的時候,改變原來單獨使用Squid的結構,將Nginx放在Squid之前, 實際的使用效果表明,比獨立使用Squid要好很多,併發能力得以很大提高。
+++++++++++++++++++++++++++++++++++++++++++
九. Cachemgr.cgi監控squid運行狀態
9.1Cachemgr.cgi配置過程
#cp /usr/local/squid/libexec/cachemgr.cgi /var/www/cgi-bin/
修改配置文件/etc/http/conf/http.conf
<Location /cgi-bin/cachemgr.cgi>
AuthType Basic
AuthName "Squidadmin"
AuthUserFile /usr/local/squid/etc/passwd/.htaccess
require valid-user
</Location>
9.2生成口令文件
htpasswd -c /usr/local/squid/etc/passwd/.htaccess squidadmin “創建密碼文件 ”
New passwd:
Re-type new passwd:
Adding password for user squidadmin
9.3驗證
在瀏覽器的地址列中鍵入 http://192.168.7.222(服務器的名稱或IP地址)/cgi-bin/cachemgr.cgi。
+++++++++++++++++++++++++++++++++++++++++++
十.錯誤總結:
1.權限問題:(squid的默認用戶是nobody)
[root@song sbin]# ./squid -k parse
2010/07/05 17:49:19| Processing Configuration File: /usr/local/squid/etc/squid.conf (depth 0)
WARNING: Cannot write log file: /usr/local/squid/var/logs/cache.log
/usr/local/squid/var/logs/cache.log: Permission denied
messages will be sent to 'stderr'.
查看日誌:
[root@song sbin]# tail /var/log/messages
Jul 5 17:52:58 song squid[30354]: Process ID 30354
Jul 5 17:52:58 song squid[30354]: With 1024 file descriptors available
Jul 5 17:52:58 song squid[30354]: Initializing IP Cache...
Jul 5 17:52:58 song squid[30354]: helperOpenServers: Starting 5/5 'dnsserver' processes
Jul 5 17:52:58 song squid[30354]: storeDirWriteCleanLogs: Starting...
Jul 5 17:52:58 song squid[30354]: Finished. Wrote 0 entries.
Jul 5 17:52:58 song squid[30354]: Took 0.00 seconds ( 0.00 entries/sec).
Jul 5 17:52:58 song squid[30354]: Cannot open '/usr/local/squid/var/logs/access.log' for writing. The parent directory must be writeable by the user 'nobody', which is the cache_effective_user set in squid.conf.
Jul 5 17:52:58 song squid[30324]: Squid Parent: child process 30354 exited with status 1
Jul 5 17:52:58 song squid[30324]: Exiting due to repeated, frequent failures
方法:
賦/ usr/local/squid/var/logs/ 777 權限:
[root@song squid]# chmod 777 /usr/local/squid/var/logs/
+++++++++++++++++++++++++++++++++++++++++++
2.不能識別它自己的完整可驗證域名,就會報這個錯
FATAL: Could not determine fully qualified hostname. Please set 'visible_hostname'
visible_hostname my.host.name 192.168.77.225:80: (99) Cannot assign requested address
方法:
編輯squid.conf如下
# vim squid.conf
visible_hostname yourhostname.domain.com
+++++++++++++++++++++++++++++++++++++++++++
3.版本更新問題:
# squid.sh reload
2010/07/06 11:21:57| cache_cf.cc(362) parseOneConfigFile: squid.conf:102 unrecognized: 'httpd_accel_host'
2010/07/06 11:21:57| cache_cf.cc(362) parseOneConfigFile: squid.conf:103 unrecognized: 'httpd_accel_port'
2010/07/06 11:21:57| cache_cf.cc(362) parseOneConfigFile: squid.conf:104 unrecognized: 'httpd_accel_uses_host_header'
2010/07/06 11:21:57| cache_cf.cc(362) parseOneConfigFile: squid.conf:105 unrecognized: 'httpd_accel_with_proxy'
在 squid-2.5中,反向代理所涉及到的關鍵配置指令是:httpd_accel_host,
httpd_accel_port,httpd_accel_single_host,httpd_accel_with_proxy,httpd_accel_uses_host_header。httpd_accel_*這一系列的指令,在Squid-2.6中都已經去掉,取而帶之的 是 cache_peer, cache_peer_domain, cache_peer_access 這三個指令
+++++++++++++++++++++++++++++++++++++++++++
4. Squid無法反向代理多個後臺WEB服務器
在確保自己squid.conf配置文檔沒有錯誤的時候,查看下自己Apache的配置,很有可能是自己的Apache配置問題
5.在運行一段時間後,Squid變慢了
1. 減少cache_mem值
2. 關掉內存池,用該選項:
memory_pools off
3.清掉/usr/local/squid/var/cache中沒用的內用
4.定期執行本文檔中給出的clear_squid_cache.sh腳本
更詳細內容請參考<<Squid中文權威指南>>