squid cache 服务器端的安装,配置

前端之家收集整理的这篇文章主要介绍了squid cache 服务器端的安装,配置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一,什么squid

Squid是一个高性能的代理缓存服务器,可以加快内部网浏览Internet的速度,提高客户机的访问命中率。Squid不仅支持HTTP协议,还支持FTP、gopher、SSL和WAIS等协议。和一般的代理缓存软件不同,Squid用一个单独的、非模块化的、I/O驱动的进程来处理所有的客户端请求。

Squid将数据元缓存在内存中,同时也缓存DNS查寻的结果,除此之外,它还支持非模块化的DNS查询,对失败的请求进行消极缓存。Squid支持SSL,支持访问控制。由于使用了ICP,Squid能够实现重叠的代理阵列,从而最大限度的节约带宽。

Squid能够增强访问控制,提高安全性。可以针对特定的的网站、用户、网络、数据类型实施访问控制等

二,安装squid

http://www.squid-cache.org/Versions/v3/3.1
到上面的链接去下载squid,到目前为止,squid3.1.4是最新的。

  1. tar zxvf squid-3.1.4.tar.gz -/home/zhangy
  2. cd /home/zhangy/squid-3.1.4
  3. ./configure --prefix=/usr/local/squid
  4. make && make install

说明:安装的时候./configure提供很多的参数选择,你可以查看./configure --help来获得,部分如下

--enable-icap-client    Enable the ICAP client.
--enable-ecap           support loadable content adaptation modules
--enable-useragent-log  Enable logging of User-Agent header
--enable-referer-log    Enable logging of Referer header
--disable-wccp          Disable Web Cache Coordination Protocol
像这个参数,安装的时候不加也没关系,可以通过配置来设置,像这样参数加的不好,安装的时候,还会出问题。

加了很多参数,安装报错

coss/StoreFScoss.cc:1:2: error: #error COSS Support is not stable yet in Squid-3. Please do not use.
make[3]: *** [StoreFScoss.lo] Error 1
make[3]: Leaving directory `/home/zhangy/squid-3.1.4/src/fs'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/zhangy/squid-3.1.4/src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/zhangy/squid-3.1.4/src'
make: *** [all-recursive] Error 1

三,配置squid

当你装好后,在usr/local/squid/etc文件夹下面会有些文件,squid.conf是squid的配置文件,会产生一个配置文件的备份文件,如下图

squid安装

squid安装

你可以把原来的配置文件删除掉,重新建个squid.conf,原配置文件有备份,上图中你可以看到squid.conf.default就是备份文件squid.conf.documented这个文件,是3.14总的配置文件,有5000多行,你想的什么配置都能在里面找到。我的配置文件

  1. #
  2. # Recommended minimum configuration:
  3. #
  4. acl manager proto cache_object
  5. acl localhost src 127.0.0.1/32
  6. acl localhost src ::1/128
  7. acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
  8. acl to_localhost dst ::1/128
  9.  
  10. #自带端口设置
  11. acl SSL_ports port 443
  12. #acl Safe_ports port 80 # http
  13. acl Safe_ports port 21 # ftp
  14. acl Safe_ports port 443 # https
  15. acl Safe_ports port 70 # gopher
  16. acl Safe_ports port 210 # wais
  17. acl Safe_ports port 1025-65535 # unregistered ports
  18. acl Safe_ports port 280 # http-mgmt
  19. acl Safe_ports port 488 # gss-http
  20. acl Safe_ports port 591 # filemaker
  21. acl Safe_ports port 777 # multiling http
  22. acl CONNECT method CONNECT
  23.  
  24. # We recommend you to use at least the following line.
  25. hierarchy_stoplist cgi-bin ?
  26.  
  27. # Leave coredumps in the first cache dir
  28. coredump_dir /usr/local/squid/var/cachebak
  29.  
  30. #squid监听9000端口
  31. http_port 9000 accel vhost vport
  32.  
  33. #设置缓存内存值
  34. cache_mem 128 MB
  35.  
  36. #设置内存池
  37. memory_pools_limit 50 MB
  38.  
  39. #装入内存的文件大小
  40. maximum_object_size_in_memory 2048 KB
  41. #允许最小文件请求
  42. minimum_object_size 0 KB
  43. #允许最大文件请求
  44. maximum_object_size 1280 KB
  45.  
  46. #设置缓存目录大小为256MB 一级目录为16个二级目录为256个
  47. memory_replacement_policy lru
  48. cache_dir ufs /usr/local/squid/var/cache 256 16 256
  49. max_open_disk_fds 0
  50.  
  51. #日志的格式
  52. emulate_httpd_log on
  53. logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %>Hs %h" "%{User-Agent}>h" %Ss:%Sh
  54. #下面是关于日志文件的放置目录与文件名!
  55. access_log /usr/local/squid/var/logs/access.log
  56. cache_log /usr/local/squid/var/logs/cache.log
  57. cache_store_log /usr/local/squid/var/logs/cache_store.log
  58. pid_filename /usr/local/squid/var/logs/squid.pid
  59. #反向代理
  60. cache_store_log none
  61. cache_peer 192.168.18.2 parent 80 0 no-query no-digest originserver name=www
  62. #192.168.18.2为web的ip地址,80为web监听端口
  63. cache_peer_domain www localhost
  64. cache_peer_access www allow all
  65. #最大连接数为10
  66. acl OverConnLimit maxconn 10
  67. http_access deny OverConnLimit
  68. #防止百度盗链,给他一个无图标识
  69. acl notallow referer_regex -i baidu
  70. http_access deny notallow
  71. deny_info http://51yip.com/noimage.gif notallow
  72. #允许本地管理
  73. http_access allow Manager Localhost
  74. http_access deny Manager
  75. http_access allow all
  76. #哪些不缓存
  77. acl QUERY urlpath_regex cgi-bin .PHP .cgi
  78. cache deny QUERY
  79. cache_swap_low 90
  80. cache_swap_high 95
  81. #用户组和人员
  82. cache_effective_user zhangy
  83. cache_effective_group users

上面的例子,只是实验用的配置,并且没有真正部署的配置

squid3.1系列官方配置说明 http://www.squid-cache.org/Versions/v3/3.1/cfgman/

squid3.0系列官方配置说明 http://www.squid-cache.org/Versions/v3/3.0/cfgman/

squid2.7系列官方配置说明 http://www.squid-cache.org/Versions/v2/2.7/cfgman/

squid2.6系列官方配置说明 http://www.squid-cache.org/Versions/v2/2.6/cfgman/

四,生成cache目录

利用./squid -z来生成目录

cd /usr/local/squid/sbin

./squid -z

说明:如果配置不出问题的话,生成目录不会有问题,你可以用./squid -k parse来测试配置文件

以下是我遇到的问题

  1. FATAL: Can't parse configuration token: '%>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh'
  2.  
  3. Squid Cache (Version 3.1.4): Terminated abnormally.
  4. cpu Usage: 0.003 seconds = 0.000 user + 0.003 sys
  5. Maximum Resident Size: 12768 KB
  6. Page faults with physical i/o: 1
  7. [zhangy@BlackGhost sbin]# ./squid -z
  8. 2010/06/10 22:14:08| WARNING: the "Hs" formating code is deprecated use the ">Hs" instead
  9. 2010/06/10 22:14:08| WARNING cache_mem is larger than total disk cache space!
  10. 2010/06/10 22:14:08| Creating Swap Directories
  11. 2010/06/10 22:14:08| /usr/local/squid/var/cache exists

五,squid启动

./squid

猜你在找的Redis相关文章