Total Pageviews

Thursday, 7 April 2016

squid的mgr强大功能

squid的mgr可以提供某台正在运行中的squid的实时监控数据,这些数据不仅可以帮助我们分析squid的运行状态和缓存的效果,而且还有很多很多的秘密和玄机藏在里面噢。很多时候觉得squid已经非常优化,查看mgr之后或许会大吃一惊。

mgr的常用命令行:

/usr/local/squid/bin/squidclient -h 127.0.0.1 -p 80 mgr:info

其中-h指定ip地址,-p指定端口,mgr:info是mgr的最常用的指令,指令还有很多,执行:

/usr/local/squid/bin/squidclient -h 127.0.0.1 -p 80 mgr:

这行语句比前一句少了最后的一个info,这样就会打印出可用的指令了,指令太多,我还没有能摸索完……见附件1

记住几个指令:mgr:info mgr:5min mgr:60min,没事做的时候就敲敲。

mgr:info可以说是最常用的了,它提供了一个概述,请求量、命中率、缓存数量等等都包含在内,我就不一条条说了,不懂英文可找翻译。

另外,这些指令有一些是消耗系统资源比较大的,所以请勿在重要场合尝试,免得造成困扰。如果非要尝试,附件2中倒有一堆测试机。

如果无法正常查看mgr,证明是squid配置中关闭了mgr的访问权限,那么需要在squid配置里加上几句话打开权限:

acl adminBoxes src 127.0.0.1
acl manager proto cache_object
http_access allow manager adminBoxes
http_access deny all

我可以发誓,配置这几句话并不会把你的机器变成一台新的测试机,里面有几行可能跟原来配置重叠,这是强调,并且语句前后顺序也不能变。

其中只有一个常要改的东西,就是ip地址,这里配置的是本机,可以增加:

acl adminBoxes src 127.0.0.1 192.168.1.100

可以支持一个网段:

acl adminBoxes src 127.0.0.1 192.168.1.100 192.168.51.0/24

配好之后要记得reload一下squid

squid -k reconfigure




附件1(mgr指令大全)
mem                    Memory Utilization      public
cbdata                 Callback Data Registry Contents public
events                 Event Queue     public
squidaio_counts        Async IO Function Counters      public
config                 Current Squid Configuration     hidden
ipcache                IP Cache Stats and Contents     public
fqdncache              FQDN Cache Stats and Contents   public
idns                   Internal DNS Statistics public
external_acl           External ACL stats      public
http_headers           HTTP Header Statistics  public
menu                   This Cachemanager Menu  public
shutdown               Shut Down the Squid Process     hidden
offline_toggle         Toggle offline_mode setting     hidden
info                   General Runtime Information     public
filedescriptors        Process Filedescriptor Allocation       public
objects                All Cache Objects       public
vm_objects             In-Memory and In-Transit Objects        public
openfd_objects         Objects with Swapout files open public
pending_objects        Objects being retreived from the network        public
client_objects         Objects being sent to clients   public
io                     Server-side network read() size histograms      public
counters               Traffic and Resource Counters   public
peer_select            Peer Selection Algorithms       public
digest_stats           Cache Digest and ICP blob       public
5min                   5 Minute Average of Counters    public
60min                  60 Minute Average of Counters   public
utilization            Cache Utilization       public
histograms             Full Histogram Counts   public
active_requests        Client-side Active Requests     public
storedir               Store Directory Stats   public
store_check_cachable_stats     storeCheckCachable() Stats      public
store_io               Store IO Interface Stats        public
pconn                  Persistent Connection Utilization Histograms    public
refresh                Refresh Algorithm Statistics    public
forward                Request Forwarding Statistics   public
client_list            Cache Client List       public
asndb                  AS Number Database      public

附件2(测试机)
squidclient -h www.youku.com -p 80 mgr:info
squidclient -h www.cctv.com -p 80 mgr:info
squidclient -h www.xinhuanet.com -p 80 mgr:info
squidclient -h www.people.com.cn -p 80 mgr:info
squidclient -h www.kuaiche.com -p 80 mgr:info
squidclient -h www.it168.com -p 80 mgr:info
squidclient -h www.qidian.com -p 80 mgr:info
squidclient -h www.vodone.com -p 80 mgr:info
squidclient -h www.hc360.com -p 80 mgr:info
squidclient -h www.12530.com -p 80 mgr:info
squidclient -h www.verycd.com -p 80 mgr:info
squidclient -h www.9you.com -p 80 mgr:info
squidclient -h www.duowan.com -p 80 mgr:info
squidclient -h www.poco.cn -p 80 mgr:info
squidclient -h www.blogchina.com -p 80 mgr:info

由附件2看来,中国使用squid作前端的网站还是非常多,附件2中有一部分都是CDN来的,机器多维护起来也晕乎晕乎.