squidclient 使用方法

一.  squidclient 的使用

查看帮助

1squidclient -h
2squidclient -p 80 mgr:
3  
4-h host      Retrieve URL from cache on hostname.  Default is localhost.
5-l host      Specify a local IP address to bind to.  Default is none.
6-p port      Port number of cache.  Default is 3128.
7-U user      WWW authentication username
8-W password  WWW authentication password

基本使用:

1squidclient -p 80 mgr:info # squid 的运行统计信息
2squidclient -p 80 mgr:mem  # 内存使用情况
3squidclient -p 80 mgr:diskd #硬盘缓存使用情况
4squidclient -p 80 mgr:objects #已经缓存的列表
5squidclient -p 80 mgr:io  #IO 情况

 

二. cacahemgr.cgi 程序
squidclient 得到的信息都可以运行 Squid 提供的 CGI 程序 cachemgr.cgi 获得:

将cachemgr.conf 拷到 Apache 的 cgi-bin 目录,也可是其他支持CGI的WEB 服务器

1.squid.conf 中有关 cachemgr.cgi 的配置

1acl localhost src 127.0.0.1/255.255.255.255
2acl manager proto cache_object
3http_access allow manager localhost #只允许localhost
4http_access deny manager
5#cachemgr_passwd unixvip all
6cachemgr_passwd unixvip info stats/objects

访问 http://ip/cgi-bin/cachecgi.cgi 时 Manager name: 就是 manager  Password: 就是 unixvip
因为 squid不是运行在3128端口,还要修改cachemgr.conf 文件,cachemgr.cgi 运行时会读取这个文件
cachemgr.conf 只有一行,hostanme:port 形式,例如:

1localhost:80

启动 Apache ,输入 http://ip/cgi-bin/cachecgi.cgi 登录即可获得 Squid 的各种状态信息。

注: Squid.conf 中进行了上面的配置,squidclient 应该增加 -U manager -W unixvip 参数

三.使用 squidclient 删除缓存对象
(参考Squid 权威指南)

(1) 缓新缓存
刷新缓存,在uri前面使用-r选项,如果 refresh_pattern指令里设置了ignore-reload选项,则不能刷新缓存,而只能采用
删除缓存的办法。

1#squidclient -r http://www.unixvip.com/test >/dev/null
2  
3#squidclient -r "http://www.unixvip.cn/"

(2) 删除缓存
使用 squid 独有的 PURGE 请求. (squidclient -m PURGE 选项),例如,清除某个URL缓存

1squidclient -p 80 -m PURGE http://www.unixvip.com/test

(2) 删除一组对象,<<squid权威指南>>提供的方法:

#awk '{print $7}' /usr/local/squid/var/logs/access.log \
| grep www.example.com \
| xargs -n 1 squidclient -m PURGE

它所进行的操作是:
1) 使用 awk 取出 access.log 中第7 个域(实际上是 访问的url记录).
2) 使用grep 过虑出某个域名的记录。
3) 传递给 squidclient -m PURGE 命令执行

(3) 删除所有缓存对像
方法1
# echo '' > /usr/local/squid/var/cache/swap.state # 放一个单字节进去

方法2:
停止Squid ,重命名旧缓存目录 ->新建一个空缓存目录 -> squid -z -> 删除旧缓存目录

Squid 的一些状态信息
#squidclient -U manager -W test -p 80 mgr:info

Connection information for squid:
Number of clients accessing cache:      2 #访问客户端数量
Number of HTTP requests received:       2 #收到http 请求数量
Number of ICP messages received:        0 #收到ICP 请求数量
Number of ICP messages sent:    0         #发送ICP 请求数量
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:   0.2  # 平均每分钟 http 请求数量
Average ICP messages per minute since start:    0.0  # 平均每分钟 ICP 请求数量
Select loop called: 524 times, 975.494 ms avg
Cache information for squid:
Request Hit Ratios:     5min: 0.0%, 60min: 0.0%   #5分钟/60分钟 请求命中率
Byte Hit Ratios:        5min: -0.0%, 60min: -0.0% #5分钟/60分钟 命中率,以 Byte 计算
Request Memory Hit Ratios:      5min: 0.0%, 60min: 0.0% # 内存中请求命中率
Request Disk Hit Ratios:        5min: 0.0%, 60min: 0.0% # 磁盘请求命中率
Storage Swap size:      200 KB  #cache对象占用硬盘的存储空间
Storage Mem size:       116 KB  #cache对象占用内存的存储空间
Mean Object Size:       7.69 KB
Requests given to unlinkd:      0
Median Service Times (seconds)  5 min    60 min:
HTTP Requests (All):   0.00000  0.00721
Cache Misses:          0.00000  0.00721
Cache Hits:            0.00000  0.00000
Near Hits:             0.00000  0.00000
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:        511.159 seconds
CPU Time:       0.155 seconds
CPU Usage:      0.03%
CPU Usage, 5 minute avg:        0.00%  # 5 分钟内平均CPU使用率
CPU Usage, 60 minute avg:       0.03%  # 60 分钟内平均CPU使用率
Process Data Segment Size via sbrk(): 2108 KB
Maximum Resident Size: 0 KB
Page faults with physical i/o: 0
Memory usage for squid via mallinfo():
Total space in arena:    2108 KB
Ordinary blocks:         2068 KB      5 blks
Small blocks:               0 KB      0 blks
Holding blocks:         15628 KB      3 blks
Free Small blocks:          0 KB
Free Ordinary blocks:      39 KB
Total in use:           17696 KB 100%
Total free:                39 KB 0%
Total size:             17736 KB
Memory accounted for:
Total accounted:          225 KB
memPoolAlloc calls: 2785
memPoolFree calls: 1551
File descriptor usage for squid:
Maximum number of file descriptors:   65536 #能使用的最大文件描述符
Largest file desc currently in use:     21
Number of file desc currently in use:   19
Files queued for open:                   0
Available number of file descriptors: 65517
Reserved number of file descriptors:   100
Store Disk files open:                   0
IO loop method:                     epoll
Internal Data Structures:
55 StoreEntries
29 StoreEntries with MemObjects
28 Hot Object Cache Items
26 on-disk objects

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值