• 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 -C /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.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/80.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 25616256
    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 %<st "%{referer}="">h""%{User-Agent}>h" %Ss:%Sh
    54
    55 #下面是关于日志文件的放置目录与文件名!
    56 access_log /usr/local/squid/var/logs/access.log
    57 cache_log /usr/local/squid/var/logs/cache.log
    58 cache_store_log /usr/local/squid/var/logs/cache_store.log
    59 pid_filename /usr/local/squid/var/logs/squid.pid
    60
    61 #反向代理
    62 cache_store_log none
    63 cache_peer 192.168.18.2 parent 800 no-query no-digest originserver name=www
    64 #192.168.18.2为web的ip地址,80为web监听端口
    65 cache_peer_domain www localhost
    66 cache_peer_access www allow all
    67
    68 #最大连接数为10
    69 acl OverConnLimit maxconn 10
    70 http_access deny OverConnLimit
    71
    72 #防止百度盗链,给他一个无图标识
    73 acl notallow referer_regex -i baidu
    74 http_access deny notallow
    75 deny_info http://51yip.com/noimage.gif notallow
    76
    77 #允许本地管理
    78 http_access allow Manager Localhost
    79 http_access deny Manager
    80 http_access allow all
    81
    82 #哪些不缓存
    83 acl QUERY urlpath_regex cgi-bin .php .cgi
    84 cache deny QUERY
    85
    86 cache_swap_low 90
    87 cache_swap_high 95
    88
    89 #用户组和人员
    90 cache_effective_user zhangy
    91 cache_effective_group users
    92 </st>
    复制代码

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

    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: '%&gt;a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %&lt;st "%{Referer}&gt;h" "%{User-Agent}&gt;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/1022:14:08| WARNING: the "Hs" formating code is deprecated use the ">Hs" instead
    9 2010/06/1022:14:08| WARNING cache_mem is larger than total disk cache space!
    10 2010/06/1022:14:08| Creating Swap Directories
    11 2010/06/1022:14:08| /usr/local/squid/var/cache exists
    复制代码

    五,squid启动

    ./squid

  • 相关阅读:
    js Grid 列表插件
    Pagination 分页插件
    Textarea 富文本编辑器插件
    Accordion 手风琴 折叠菜单插件(2)
    AutoComplete 自动完成插件
    Draggable 拖放插件
    过渡特效插件
    Select下拉列表选择插件(包含下拉选择图片,下拉grid等)
    Sliding Panels 滑动门插件
    把图片转化为16进制信息的方式
  • 原文地址:https://www.cnblogs.com/tonykan/p/3515593.html
Copyright © 2020-2023  润新知