Squid 代理服務器日志管理



簡介:

Squid 服務器日志增長是很快的,如果不做處理的話,可以會由於系統限制單文件大小,而導致 Squid 服務停止,太大的日志文件也不適合分析。

一、日志配置

shell > grep 'log' /etc/squid/squid.conf

cache_access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log
logfile_rotate 7

## 這是 squid.conf 中關於 log 的配置項,分別定義了三個日志文件 access.log cache.log store.log
## logfile_rotate 7 代表保留 6 個歷史日志文件,跟 1 個當前日志文件

## 默認 Squid 是不作日志切割的,系統允許寫多大,那么日志文件就寫多大

shell > squid -k rotate

## 使用 squid -k rotate 來切割日志,切割的日志名按 .0 .1 .2 .3 .... 保存

shell > ls /var/log/squid/*.log*
/var/log/squid/access.log    /var/log/squid/cache.log    /var/log/squid/store.log
/var/log/squid/access.log.0  /var/log/squid/cache.log.0  /var/log/squid/store.log.0

shell > crontab -e
0 3 * * * /usr/sbin/squid -k rotate

## 使用任務計划來定期切割日志

shell > ls /var/log/squid/access.log*
/var/log/squid/access.log    /var/log/squid/access.log.1  /var/log/squid/access.log.3  /var/log/squid/access.log.5
/var/log/squid/access.log.0  /var/log/squid/access.log.2  /var/log/squid/access.log.4  /var/log/squid/access.log.6

shell
> ls /var/log/squid/cache.log* /var/log/squid/cache.log /var/log/squid/cache.log.1 /var/log/squid/cache.log.3 /var/log/squid/cache.log.5 /var/log/squid/cache.log.0 /var/log/squid/cache.log.2 /var/log/squid/cache.log.4 /var/log/squid/cache.log.6
shell
> ls /var/log/squid/store.log* /var/log/squid/store.log /var/log/squid/store.log.1 /var/log/squid/store.log.3 /var/log/squid/store.log.5 /var/log/squid/store.log.0 /var/log/squid/store.log.2 /var/log/squid/store.log.4 /var/log/squid/store.log.6

## 由於參數 logfile_rotate 7 的限定,每個日志文件最多保存 7 個( 自動刪除 )

二、日志分析

/var/log/squid/access.log

## 時間戳          默認以 UTC 1970-01-01 00:00:00 到現在的秒數表示,顯示為毫秒
   響應時間        處理所用時間,毫秒
   客戶端地址      客戶端 IP 地址
   結果碼/狀態碼   結果碼表示 Squid 專有的編碼,如 TCP_HIT 、UDP_DENIED 等,狀態碼是 HTTP 的響應代碼,如 200301404503 等
   傳輸 Size       給客戶端傳輸字節數
   請求方式        HTTP 或 ICP 兩種,HTTP 一般為 GET ,ICP 一般為 ICP_QUERY
   URL             請求的 URL 地址
   客戶端身份      
   對端編碼/對端主機   
   內容類型        HTTP 響應的內容類型
   HTTP 請求頭部
   HTTP 響應頭部

## access.log 結果碼( 部分常見的,更多請常找相關資料 )

TCP_HIT

## 在硬盤中發現有效請求資源並立即回傳給用戶的數據

TCP_MISS

## 沒有被緩存,並回傳給用戶的數據

TCP_MEM_HIT

## 在內存中發現有效的請求資源並立即回傳給用戶的數據

TCP_REFRESH_UNMODIFIED

## 請求資源可能是舊的緩存,發送確認請求到原始服務器,原始服務器返回 304 未修改響應,指示 Squid 的緩存是最新的。並回傳給用戶的數據

TCP_REFRESH_MODIFIED

## 請求資源可能是舊的緩存,發送確認請求到原始服務器,原始服務器返回新的數據,指示這個緩存是舊的,緩存並回傳給用戶的數據

shell > cat /var/log/squid/access.log | grep TCP_HIT

## 被緩存到硬盤並回傳給用戶的數據

shell > cat /var/log/squid/access.log | grep TCP_MEM_HIT

## 被緩存到內存並回傳給用戶的數據

shell > cat /var/log/squid/access.log | grep TCP_MISS

## 沒有被緩存的數據,而是從原始服務器獲取並回傳給用戶的數據

三、緩存命中率

shell > squidclient -h 192.168.1.88 -p 80 mgr:info

HTTP/1.0 200 OK
Server: squid/3.1.10
Mime-Version: 1.0
Date: Wed, 07 Jan 2015 08:09:10 GMT
Content-Type: text/plain
Expires: Wed, 07 Jan 2015 08:09:10 GMT
Last-Modified: Wed, 07 Jan 2015 08:09:10 GMT
X-Cache: MISS from study.localhost.localdomain
X-Cache-Lookup: MISS from study.localhost.localdomain:80
Via: 1.0 study.localhost.localdomain (squid/3.1.10)
Connection: close

Squid Object Cache: Version 3.1.10
Start Time:     Wed, 07 Jan 2015 07:03:04 GMT
Current Time:   Wed, 07 Jan 2015 08:09:10 GMT
Connection information for squid:
        Number of clients accessing cache:      2
        Number of HTTP requests received:       741
        Number of ICP messages received:        0
        Number of ICP messages sent:    0
        Number of queued ICP replies:   0
        Number of HTCP messages received:       0
        Number of HTCP messages sent:   0
        Request failure ratio:   0.00
        Average HTTP requests per minute since start:   11.2
        Average ICP messages per minute since start:    0.0
        Select loop called: 36984 times, 107.235 ms avg
Cache information for squid:
        Hits as % of all requests:      5min: 0.0%, 60min: 86.0%              ## 請求命中率 5分內平均 0.0% ,60分內平均 86.0%
        Hits as % of bytes sent:        5min: 100.0%, 60min: 99.1%            ## 字節命中率
        Memory hits as % of hit requests:       5min: 0.0%, 60min: 0.0%       ## 內存命中率
        Disk hits as % of hit requests: 5min: 0.0%, 60min: 13.5%              ## 磁盤命中率
        Storage Swap size:      31228 KB                                      ## 緩存目錄大小
        Storage Swap capacity:   0.7% used, 99.3% free
        Storage Mem size:       108 KB                                        ## 緩存內存大小
        Storage Mem capacity:    0.0% used, 100.0% free
        Mean Object Size:       255.97 KB
        Requests given to unlinkd:      0
Median Service Times (seconds)  5 min    60 min:
        HTTP Requests (All):   0.00000  0.00463
        Cache Misses:          0.00000  0.04277
        Cache Hits:            0.00000  0.08265
        Near Hits:             0.00000  0.00286
        Not-Modified Replies:  0.00000  0.00000
        DNS Lookups:           0.00000  0.00000
        ICP Queries:           0.00000  0.00000
Resource usage for squid:
        UP Time:        3965.980 seconds
        CPU Time:       4.601 seconds
        CPU Usage:      0.12%
        CPU Usage, 5 minute avg:        0.02%
        CPU Usage, 60 minute avg:       0.12%
        Process Data Segment Size via sbrk(): 3692 KB
        Maximum Resident Size: 79968 KB
        Page faults with physical i/o: 1
Memory accounted for:
        Total accounted:          474 KB   1%
        memPool accounted:        474 KB   1%
        memPool unaccounted:    38133 KB  99%
        memPoolAlloc calls:    225264
        memPoolFree calls:     228120
File descriptor usage for squid:
        Maximum number of file descriptors:   65535
        Largest file desc currently in use:     17
        Number of file desc currently in use:   10
        Files queued for open:                   0
        Available number of file descriptors: 65525
        Reserved number of file descriptors:   100
        Store Disk files open:                   0
Internal Data Structures:
           149 StoreEntries
            27 StoreEntries with MemObjects
            26 Hot Object Cache Items
           122 on-disk objects


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM