轉:squid 调试访问控制acl

本文深入探讨了如何使用Squid的调试访问控制ACL功能,包括配置调试选项、解析缓存日志和调整日志详细程度,以及如何通过缓存日志进行调试。此外,文章还介绍了Squid的调试节号和等级分配,帮助读者更好地理解和使用这一功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

squid 调试访问控制acl
2011-05-06 8:59
调试访问控制

假如访问控制不能正确工作,如下是一些有用帮助。编辑squid.conf文件,设置debug_options行如下:

debug_options ALL,1 33,2

然后,重配置squid:

% squid -k reconfigure

现在,对每个客户端请求以及每个响应,squid都写一条消息到cache.log。该消息包含了请求方式,URI,是否请求/响应被允许或拒绝,以及与之匹配的最后ACL的名字。例如:

2003/09/29 20:22:05| The request

GET http://images.slashdot.org:80/topics/topicprivacy.gif is ALLOWED,

because it matched 'localhost'


2003/09/29 20:22:05| The reply for

GET http://images.slashdot.org/topics/topicprivacy.gif is ALLOWED,

because it matched 'all'

知道ACL的名字,并非总能知道相应的http_access行,但也相当接近了。假如必要,可以复制acl行,并给予它们唯一的名字,以便给定的ACL名字仅仅出现在一个http_access规则里。



16.2 通过cache.log进行调试

从13.1章已了解到,cache.log包含了不同的操作消息,squid认为这些消息足够重要,从而告诉了你。我们也将这些作为debug消息考虑。可以使用debug_options指令来控制出现在cache.log里的消息的冗长度。通过增加debug等级,可以见到更详细的消息,有助于理解squid正在做什么。例如:

debug_options ALL,1 11,3 20,3

在squid源代码里的每个debug消息有2个数字特征:1个节和1个等级。节范围从0到100,等级范围从0到10。通常来说,节号对应着源代码的组成成分。换句话说,在单一源文件里的所有消息,有相同的节号。在某些情形下,多个文件使用同一debug节,这意味着某个源文件变得太大,从而被拆分成多个小块。

每个源文件的顶部有一行,用于指示debug节。它看起来如此:

* DEBUG: section 9 File Transfer Protocol (FTP)

我不指望你通过查看源文件来查找节号,所有相关信息定义在表16-1里。



Table 16-1. Debugging section numbers for the debug_options directive

Number Description Source file(s)
0 Client Database client_db.c
1 Startup and Main Loop main.c
2 Unlink Daemon unlinkd.c
3 Configuration File Parsing cache_cf.c
4 Error Generation errorpage.c
5 Socket Functions comm.c
5 Socket Functions comm_select.c
6 Disk I/O Routines disk.c
7 Multicast multicast.c
8 Swap File Bitmap filemap.c
9 File Transfer Protocol (FTP) ftp.c
10 Gopher gopher.c
11 Hypertext Transfer Protocol (HTTP) http.c
12 Internet Cache Protocol icp_v2.c
12 Internet Cache Protocol icp_v3.c
13 High Level Memory Pool Management mem.c
14 IP Cache ipcache.c
15 Neighbor Routines neighbors.c
16 Cache Manager Objects cache_manager.c
17 Request Forwarding forward.c
18 Cache Manager Statistics stat.c
19 Store Memory Primitives stmem.c
20 Storage Manager store.c
20 Storage Manager Client-Side Interface store_client.c
20 Storage Manager Heap-Based Replacement repl/heap/store_heap_replacement.c
20 Storage Manager Logging Functions store_log.c
20 Storage Manager MD5 Cache Keys store_key_md5.c
20 Storage Manager Swapfile Metadata store_swapmeta.c
20 Storage Manager Swapin Functions store_swapin.c
20 Storage Manager Swapout Functions store_swapout.c
20 Store Rebuild Routines store_rebuild.c
21 Misc Functions tools.c
22 Refresh Calculation refresh.c
23 URL Parsing url.c
24 WAIS Relay wais.c
25 MIME Parsing mime.c
26 Secure Sockets Layer Proxy ssl.c
27 Cache Announcer send-announce.c
28 Access Control acl.c
29 Authenticator auth/basic/auth_basic.c
29 Authenticator auth/digest/auth_digest.c
29 Authenticator authenticate.c
29 NTLM Authenticator auth/ntlm/auth_ntlm.c
30 Ident (RFC 1413) ident.c
31 Hypertext Caching Protocol htcp.c
32 Asynchronous Disk I/O fs/aufs/async_io.c
33 Client-Side Routines client_side.c
34 Dnsserver Interface dns.c
35 FQDN Cache fqdncache.c
37 ICMP Routines icmp.c
38 Network Measurement Database net_db.c
39 Cache Array Routing Protocol carp.c
40 Referer Logging referer.c
40 User-Agent Logging useragent.c
41 Event Processing event.c
42 ICMP Pinger Program pinger.c
43 AIOPS fs/aufs/aiops.c
44 Peer Selection Algorithm peer_select.c
45 Callback Data Registry cbdata.c
45 Callback Data Registry leakfinder.c
46 Access Log access_log.c
47 Store COSS Directory Routines fs/coss/store_dir_coss.c
47 Store Directory Routines fs/aufs/store_dir_aufs.c
47 Store Directory Routines fs/diskd/store_dir_diskd.c
47 Store Directory Routines fs/null/store_null.c
47 Store Directory Routines fs/ufs/store_dir_ufs.c
47 Store Directory Routines store_dir.c
48 Persistent Connections pconn.c
49 SNMP Interface snmp_agent.c
49 SNMP Support snmp_core.c
50 Log File Handling logfile.c
51 File Descriptor Functions fd.c
52 URN Parsing urn.c
53 AS Number Handling asn.c
54 Interprocess Communication ipc.c
55 HTTP Header HttpHeader.c
56 HTTP Message Body HttpBody.c
57 HTTP Status-Line HttpStatusLine.c
58 HTTP Reply (Response) HttpReply.c
59 Auto-Growing Memory Buffer with printf MemBuf.c
60 Packer: A Uniform Interface to Store Like Modules Packer.c
61 Redirector redirect.c
62 Generic Histogram StatHist.c
63 Low Level Memory Pool Management MemPool.c
64 HTTP Range Header HttpHdrRange.c
65 HTTP Cache Control Header HttpHdrCc.c
66 HTTP Header Tools HttpHeaderTools.c
67 String String.c
68 HTTP Content-Range Header HttpHdrContRange.c
69 HTTP Header: Extension Field HttpHdrExtField.c
70 Cache Digest CacheDigest.c
71 Store Digest Manager store_digest.c
72 Peer Digest Routines peer_digest.c
73 HTTP Request HttpRequest.c
74 HTTP Message HttpMsg.c
75 WHOIS Protocol whois.c
76 Internal Squid Object handling internal.c
77 Delay Pools delay_pools.c
78 DNS Lookups; interacts with lib/rfc1035.c dns_internal.c
79 Squid-Side DISKD I/O Functions fs/diskd/store_io_diskd.c
79 Storage Manager COSS Interface fs/coss/store_io_coss.c
79 Storage Manager UFS Interface fs/ufs/store_io_ufs.c
80 WCCP Support wccp.c
82 External ACL external_acl.c
83 SSL Accelerator Support ssl_support.c
84 Helper Process Maintenance helper.c


debug等级这样分配:重要消息有较低值,非重要消息有较高值。0等级是非常重要的消息,10等级是相对不紧要的消息。另外,关于等级其实并没有严格的向导或要求。开发者通常自由选择适应的debug等级。

debug_options指令决定哪个消息出现在cache.log,它的语法是:

debug_options section,level section,level ...

默认设置是ALL,1,这意味着squid会将所有等级是0或1的debug消息打印出来。假如希望cache.log里出现更少的debug消息,可设置debug_options为ALL,0。

假如想观察某个组件的其他debug信息,简单的将相应的节号和等级增加到debug_options列表的末端。例如,如下行对FTP服务端代码增加了等级5的debug:

debug_options ALL,1 9,5

如同其他配置指令一样,可以改变debug_options,然后给squid发送重置信号:

% squid -k reconfigure

注意debug_options参数是按顺序处理的,后来的值会覆盖先前的值。假如使用ALL关键字,这点尤其要注意。考虑如下示例:

debug_options 9,5 20,9 4,2 ALL,1

在该情形下,最后的值覆盖了所有先前的设置,因为ALL,1对所有节设置了debug等级为1。

选择合适的debug节号和等级有时非常困难,尤其是对squid新手而言。许多更详细的debug消息仅对squid开发者和熟悉源代码的用户有意义。无经验的squid用户会发现许多debug消息无意义和不可理解。进一步的说,假如squid相对忙的话,你可能对某个特殊请求或事件进行独立debug有困难。假如你能一次用一个请求来测试squid,那么高的debug等级通常更有用。

若以高debug等级来运行squid较长时间,需要特别谨慎。假如squid繁忙,cache.log增长非常快,并可能最终耗尽它的分区的剩余空间。假如这点发生,squid以致命消息退出。另一个关注点是性能可能下降明显。因为有大量的debug消息,squid要耗费许多CPU资源来格式化和打印字符串。将所有debug消息写往cache.log,也浪费了大量的磁盘带宽。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值