squid常用命令集

根据手册及一些文章收集整理并亲自测试了一些常用的squid命令

1、测试配置文件

/usr/local/squid/sbin/squid -k parse

  2、初始化cache目录

# /usr/local/squid/sbin/squid -zX
也可以不加X,X可以看到初始化过程

  3、在终端窗口里测试squid

一旦你已经初始化cache目录,就可以在终端窗口里运行squid,将日志记录到标准错误。这样,你能轻易的定位任何错误或问题,并且确认squid是否成功启动。使用-N选项来保持squid在前台运行,-d1选项在标准错误里显示1级别的调试信息。


# /usr/local/squid/sbin/squid -N -d1
2013/07/17 05:52:03| Starting Squid Cache version 2.7.STABLE9 for x86_64-unknown-linux-gnu...
2013/07/17 05:52:03| Process ID 13897
2013/07/17 05:52:03| With 1024 file descriptors available
2013/07/17 05:52:03| Using epoll for the IO loop
2013/07/17 05:52:03| Performing DNS Tests...
2013/07/17 05:52:03| Successful DNS name lookup tests...
2013/07/17 05:52:03| helperOpenServers: Starting 5 'dnsserver' processes
2013/07/17 05:52:03| User-Agent logging is disabled.
2013/07/17 05:52:03| Referer logging is disabled.
2013/07/17 05:52:03| logfileOpen: opening log /usr/local/squid/var/logs/access.log
2013/07/17 05:52:03| Unlinkd pipe opened on FD 15
2013/07/17 05:52:03| Swap maxSize 102400 + 8192 KB, estimated 8507 objects
2013/07/17 05:52:03| Target number of buckets: 425
2013/07/17 05:52:03| Using 8192 Store buckets
2013/07/17 05:52:03| Max Mem  size: 8192 KB
2013/07/17 05:52:03| Max Swap size: 102400 KB
2013/07/17 05:52:03| logfileOpen: opening log /usr/local/squid/var/logs/store.log
2013/07/17 05:52:03| Rebuilding storage in /usr/local/squid/var/cache (DIRTY)
2013/07/17 05:52:03| Using Least Load store dir selection
2013/07/17 05:52:03| Set Current Directory to /usr/local/squid/var/cache
2013/07/17 05:52:03| Loaded Icons.
2013/07/17 05:52:03| Accepting proxy HTTP connections at 0.0.0.0, port 80, FD 16.
2013/07/17 05:52:03| Accepting ICP messages at 0.0.0.0, port 3130, FD 17.
2013/07/17 05:52:03| Accepting SNMP messages on port 3401, FD 18.
2013/07/17 05:52:03| WCCP Disabled.
2013/07/17 05:52:03| Pinger socket opened on FD 19
2013/07/17 05:52:03| Ready to serve requests.
2013/07/17 05:52:03| Done scanning /usr/local/squid/var/cache (0 entries)
2013/07/17 05:52:03| Finished rebuilding storage from disk.
2013/07/17 05:52:03|         0 Entries scanned
2013/07/17 05:52:03|         0 Invalid entries.
2013/07/17 05:52:03|         0 With invalid flags.
2013/07/17 05:52:03|         0 Objects loaded.
2013/07/17 05:52:03|         0 Objects expired.
2013/07/17 05:52:03|         0 Objects cancelled.
2013/07/17 05:52:03|         0 Duplicate URLs purged.
2013/07/17 05:52:03|         0 Swapfile clashes avoided.
2013/07/17 05:52:03|   Took 0.3 seconds (   0.0 objects/sec).
2013/07/17 05:52:03| Beginning Validation Procedure
2013/07/17 05:52:03|   Completed Validation Procedure
2013/07/17 05:52:03|   Validated 0 Entries
2013/07/17 05:52:03|   store_swap_size = 0k
2013/07/17 05:52:04| storeLateRelease: released 0 objects
如果有到 ready to server reques,恭喜,启动成功。
然后 ctrl + c,停止squid,并以后台运行的方式启动它。

 4、启动squid作为后台进程运行

/usr/local/squid/sbin/squid -s

 5、停止squid服务

/usr/local/squid/sbin/squid -k shutdown

6、重引导修改过的squid.conf配置文件

/usr/local/squid/sbin/squid -k reconfigure
这个估计用的时候比较多,当你发现你的配置有不尽你意的时候,可以随时修改squid.conf,然后别忘记对你的 squid.conf排错,然后再执行此指令,即可让squid重新按照你的 squid.conf 来运行。
7、squid添加到系统启动项
/usr/local/squid/sbin/squid -s
8、查看运行信息
/usr/local/squid/bin/squidclient -h 127.0.0.1 -p 80 mgr:info
9、分割日志
20 0 * * * /usr/local/squid/sbin/squid -k rotate
10、清楚缓存
/usr/local/squid/bin/squidclient -h 192.168.10.10 -p 80 -m PURGE http://192.168.10.10/code.jpeg
11、查看你的日志文档
more /usr/local/squid/var/logs/access.log | grep TCP_MEM_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到内存中,并返回给访问用户
more /usr/local/squid/var/logs/access.log | grep TCP_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到cache目录中,并返回给访问用户
more /usr/local/squid/var/logs/access.log | grep TCP_MISS
该指令可以看到在squid运行过程中,有那些文件没有被squid缓存,而是现重原始服务器获取并返回给访问用户
12、相关命令

squid运行状态信息:

/usr/local/squid/bin/squidclient -h 192.168.10.10 -p 80 mgr:info
/usr/local/squid/bin/squidclient -h 192.168.10.10 -p 80 mgr:5min

squid内存使用情况:

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

squid缓存信息列表:

/usr/local/squid/bin/squidclient -h 192.168.10.10 -p 80 mgr:objects (use it carefully,it may crash)

squid磁盘使用情况:

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

强制更新某个url:

/usr/local/squid/bin/squidclient -h 192.168.10.10 -p 80 -m PURGE http://www.hnhack.com/
     
     
     
     


你可能感兴趣的:(squid常用命令)