您的位置:首页 > 运维架构 > 反向代理

[Squid] Squid3.0与2.7的配置差异

2012-06-26 23:55 211 查看

Squid3.0最重要的新特性:

Code converted to C++, with significant internal restructuring and rewrites.

ICAP implementation (RFC 3507 and www.icap-forum.org)

Edge Side Includes (ESI) implementation (www.esi.org)

更多的请参考官方说明

来说说配置方法的不同之处(只说我自己实际使用的)

./configure的配置项

./configure –prefix=/usr/local/squid –with-large-files –enable-useragent-log –enable-referer-log –enable-linux-netfilter –enable-x-accelerator-vary –disable-internal-dns –disable-mempools –with-maxfd=65535

3.0版本去掉了以下选项:

–enable-dlmalloc 不再需要

–enable-epoll 系统会自己选择最优的I/O Loop Method

–enable-truncate 不再需要

–enable-follow-x-forwarded-for 没有此项配置了

增加了以下选项:

–disable-mempools 相当于2.7配置文件里面的memory_pools off,适合内存使用较大的情况,系统会调用free()来清除没用到的缓存内存

–with-maxfd=65535 相当于ulimit -n 65535,2.7配置文件里面的max_filedescriptors 65535

配置文件(squid.conf)差别

在Squid3.0版本的配置文件中,如下主要tag发生了变化

acl 去掉了对src为all的定义,已集成;对protocol的定义简写为proto

http_port 去掉了选项http11和act_as_origin;增加了类型http_status

cache_peer 去掉了选项http11

header_access 删除了此tag,以request_header_access和reply_header_access取代

server_http11 删除了此tag

incoming_rate 删除了此tag

memory_pools 删除了此tag,在./configure的时候实现

max_filedescriptors 删除了此tag,在./configure的时候实现

上面只列出了我自己实际配置Squid时,3.0版本和2.7版本的不同之处,关于更多的大家可以参考官方文档。

参考文档

http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE14-RELEASENOTES.html

Squid3.0配置参考

编译参数:

http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE15.tar.gz

./configure –prefix=/usr/local/squid3 \

-enable-debug-cbdata \

-enable-async-io=240 \

-with-pthreads \

-enable-storeio="aufs,diskd,ufs" \

-enable-removal-policies="heap,lru" \

-enable-icmp \

-enable-delay-pools \

-enable-useragent-log \

-enable-referer-log \

-enable-kill-parent-hack \

-enable-arp-acl \

-enable-default-err-language=Simplify_Chinese \

-enable-err-languages="Simplify_Chinese English" \

-disable-poll \

-disable-wccp \

-disable-wccpv2 \

-disable-ident-lookups \

-disable-internal-dns \

-enable-basic-auth-helpers="NCSA" \

-enable-stacktrace \

-with-large-files \

-disable-mempools \

-with-filedescriptors=65535 \

-enable-ssl \

-enable-x-accelerator-var

make

make install

贴一个我在线上运行的配置供大家参考:)有不足之处欢迎指正。

#accel listen port

http_port 80 accel vhost vport

#accel domain

cache_peer 211.100.72.109 parent 80 0 no-query originserver no-digest name=www

cache_peer_domain www .linuxtone.com .linuxtone.com.cn .linuxtone.net .linuxtone.cn .linuxtone.org

#acl

acl manager proto cache_object

acl localhost src 127.0.0.1/255.255.255.255

acl SSL_ports port 443 563

acl Safe_ports port 80 # http

acl Safe_ports port 8080

acl LanSrc src 211.100.72.0/24

acl LanDst dst 211.100.72.0/24

acl LanDstDM dstdomain .linuxtone.com .linuxtone.com.cn .linuxtone.net .linuxtone.cn .linuxtone.org

acl CONNECT method CONNECT

http_access allow manager localhost

http_access deny manager

http_access deny !Safe_ports

http_access deny CONNECT !SSL_ports

http_access allow LanSrc

http_access allow LanDst

http_access allow LanDstDM

http_access deny all

#base

visible_hostname www-cache2.linuxtone.com

cache_mgr cache@linuxtone.org

cache_effective_user squid

cache_effective_group squid

error_directory /usr/local/squid3/share/errors/Simplify_Chinese

icon_directory /usr/local/squid3/share/icons

mime_table /usr/local/squid3/etc/mime.conf

cache_replacement_policy lru

#cache_dir

cache_dir aufs /data/cache1 32768 64 64

cache_dir aufs /data/cache2 32768 64 64

cache_mem 2048 MB

max_open_disk_fds 0

#maximum_object_size 512 KB

#maximum_object_size_in_memory 256 KB

maximum_object_size 20 MB

maximum_object_size_in_memory 8 MB

#keepalived

client_persistent_connections off

server_persistent_connections on

#persistent_request_timeout 60 seconds

#memory_pools on

#memory_pools_limit 64 MB

forwarded_for on

log_icp_queries off

via off

httpd_suppress_version_string off

ie_refresh off

tcp_recv_bufsize 32 KB

#acl webservices rep_header Server -i ^linuxtoneWS ^Apache ^nginx

#broken_vary_encoding allow webservices

#hidden the squid3 header

#reply_header_access Server deny all

#reply_header_access X-Cache deny all

#reply_header_access Warning deny all

#reply_header_access Expires deny all

#reply_header_access Cache-Control deny all

#reply_header_access age deny all

#reply_header_access All deny all

ipcache_size 1024

ipcache_low 90

ipcache_high 95

memory_replacement_policy lru

hosts_file /etc/hosts

request_header_max_size 128 KB

#deny cache

hierarchy_stoplist cgi-bin ? \.php

acl QUERY urlpath_regex cgi-bin\? \.php

acl DIRECT url_regex -i ^http:\/\/www\.linuxtone\.com\/$

acl DIRECT url_regex -i ^http:\/\/photo\.linuxtone\.com\/.*$

acl DIRECT url_regex -i ^http:\/\/www\.linuxtone\.com\/index\.html$

cache deny QUERY

cache deny DIRECT

#request_body_max_size 0 KB

refresh_pattern ^ftp: 60 20% 10080

refresh_pattern ^gopher: 60 0% 1440

refresh_pattern . 0 20% 1440

refresh_pattern -i \.css$ 360 50% 2880 reload-into-ims

refresh_pattern -i \.js$ 1440 50% 2880 reload-into-ims

refresh_pattern -i \.html$ 720 50% 1440 reload-into-ims

refresh_pattern -i \.jpg$ 1440 90% 2880 ignore-reload

refresh_pattern -i \.gif$ 1440 90% 2880 ignore-reload

refresh_pattern -i \.swf$ 1440 90% 2880 ignore-reload

refresh_pattern -i \.jpg$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.png$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.bmp$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.doc$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.ppt$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.xls$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.pdf$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.rar$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.zip$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.txt$ 1440 50% 2880 ignore-reload

quick_abort_min 20 KB

quick_abort_max 20 KB

quick_abort_pct 95

connect_timeout 1 minute

negative_ttl 0 minutes

read_timeout 30 seconds

pconn_timeout 120 seconds

shutdown_lifetime 5 seconds

strip_query_terms off

#snmp

#snmp_port 3401

#acl snmppublic snmp_orgmunity snsimg

#snmp_access allow snmppublic localhost

#snmp_access deny all

icp_port 0

# logfile

emulate_httpd_log on

#logformat combined %{X-Forwarded-For}>h %ui %un [%tl] “%rm %ru HTTP/%rv” %Hs %<st “%{Referer}>h” “%{User-Agent}>h” %Ss:%Sh

#access_log none

#access_log /data/logs/access.log combined

logformat squid %ts.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt

access_log /data/logs/access.log squid

#cache_store_log /var/log/squid3/store.log

cache_store_log /dev/null

cache_log /data/logs/cache.log

logfile_rotate 12

# MISCELLANEOUS

store_objects_per_bucket 15

client_db off

Squid3.0配置参考

编译参数:

http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE15.tar.gz

[color=Blue]./configure –prefix=/usr/local/squid3 \

–enable-debug-cbdata \

–enable-async-io=100 \

–with-pthreads \

–enable-storeio=”aufs,diskd,ufs” \

–enable-removal-policies=”heap,lru” \

–enable-icmp \

–enable-delay-pools \

–enable-useragent-log \

–enable-referer-log \

–enable-kill-parent-hack \

–enable-arp-acl \

–enable-default-err-language=Simplify_Chinese \

–enable-err-languages=”Simplify_Chinese English” \

–disable-poll \

–disable-wccp \

–disable-wccpv2 \

–disable-ident-lookups \

–disable-internal-dns \

–enable-basic-auth-helpers=”NCSA” \

–enable-stacktrace \

–with-large-files \

–disable-mempools \

–with-filedescriptors=65535 \

–enable-ssl \

–enable-x-accelerator-var

make

make install[/color]

贴一个我在线上运行的配置供大家参考:)有不足之处欢迎指正。

#accel listen port

http_port 80 accel vhost vport

#accel domain

cache_peer 211.100.72.109 parent 80 0 no-query originserver no-digest name=www

cache_peer_domain www .linuxtone.com .linuxtone.com.cn .linuxtone.net .linuxtone.cn .linuxtone.org

#acl

acl manager proto cache_object

acl localhost src 127.0.0.1/255.255.255.255

acl SSL_ports port 443 563

acl Safe_ports port 80 # http

acl Safe_ports port 8080

acl LanSrc src 211.100.72.0/24

acl LanDst dst 211.100.72.0/24

acl LanDstDM dstdomain .linuxtone.com .linuxtone.com.cn .linuxtone.net .linuxtone.cn .linuxtone.org

acl CONNECT method CONNECT

http_access allow manager localhost

http_access deny manager

http_access deny !Safe_ports

http_access deny CONNECT !SSL_ports

http_access allow LanSrc

http_access allow LanDst

http_access allow LanDstDM

http_access deny all

#base

visible_hostname www-cache2.linuxtone.com

cache_mgr cache@linuxtone.org

cache_effective_user squid

cache_effective_group squid

error_directory /usr/local/squid3/share/errors/Simplify_Chinese

icon_directory /usr/local/squid3/share/icons

mime_table /usr/local/squid3/etc/mime.conf

cache_replacement_policy lru

#cache_dir

cache_dir aufs /data/cache1 32768 64 64

cache_dir aufs /data/cache2 32768 64 64

cache_mem 2048 MB

max_open_disk_fds 0

#maximum_object_size 512 KB

#maximum_object_size_in_memory 256 KB

maximum_object_size 20 MB

maximum_object_size_in_memory 8 MB

#keepalived

client_persistent_connections off

server_persistent_connections on

#persistent_request_timeout 60 seconds

#memory_pools on

#memory_pools_limit 64 MB

forwarded_for on

log_icp_queries off

via off

httpd_suppress_version_string off

ie_refresh off

tcp_recv_bufsize 32 KB

#acl webservices rep_header Server -i ^linuxtoneWS ^Apache ^nginx

#broken_vary_encoding allow webservices

#hidden the squid3 header

#reply_header_access Server deny all

#reply_header_access X-Cache deny all

#reply_header_access Warning deny all

#reply_header_access Expires deny all

#reply_header_access Cache-Control deny all

#reply_header_access age deny all

#reply_header_access All deny all

ipcache_size 1024

ipcache_low 90

ipcache_high 95

memory_replacement_policy lru

hosts_file /etc/hosts

request_header_max_size 128 KB

#deny cache

hierarchy_stoplist cgi-bin ? \.php

acl QUERY urlpath_regex cgi-bin\? \.php

acl DIRECT url_regex -i ^http:\/\/www\.linuxtone\.com\/$

acl DIRECT url_regex -i ^http:\/\/photo\.linuxtone\.com\/.*$

acl DIRECT url_regex -i ^http:\/\/www\.linuxtone\.com\/index\.html$

cache deny QUERY

cache deny DIRECT

#request_body_max_size 0 KB

refresh_pattern ^ftp: 60 20% 10080

refresh_pattern ^gopher: 60 0% 1440

refresh_pattern . 0 20% 1440

refresh_pattern -i \.css$ 360 50% 2880 reload-into-ims

refresh_pattern -i \.js$ 1440 50% 2880 reload-into-ims

refresh_pattern -i \.html$ 720 50% 1440 reload-into-ims

refresh_pattern -i \.jpg$ 1440 90% 2880 ignore-reload

refresh_pattern -i \.gif$ 1440 90% 2880 ignore-reload

refresh_pattern -i \.swf$ 1440 90% 2880 ignore-reload

refresh_pattern -i \.jpg$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.png$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.bmp$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.doc$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.ppt$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.xls$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.pdf$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.rar$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.zip$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.txt$ 1440 50% 2880 ignore-reload

quick_abort_min 20 KB

quick_abort_max 20 KB

quick_abort_pct 95

connect_timeout 1 minute

negative_ttl 0 minutes

read_timeout 30 seconds

pconn_timeout 120 seconds

shutdown_lifetime 5 seconds

strip_query_terms off

#snmp

#snmp_port 3401

#acl snmppublic snmp_orgmunity snsimg

#snmp_access allow snmppublic localhost

#snmp_access deny all

icp_port 0

# logfile

emulate_httpd_log on

#logformat combined %{X-Forwarded-For}>h %ui %un [%tl] “%rm %ru HTTP/%rv” %Hs %<st “%{Referer}>h” “%{User-Agent}>h” %Ss:%Sh

#access_log none

#access_log /data/logs/access.log combined

logformat squid %ts.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt

access_log /data/logs/access.log squid

#cache_store_log /var/log/squid3/store.log

cache_store_log /dev/null

cache_log /data/logs/cache.log

logfile_rotate 12

# MISCELLANEOUS

store_objects_per_bucket 15

client_db off

================================================

下载squid 3.0

1.可以用下述命令获得squid

wget http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE13.tar.gz
2.建立squid用户

useradd squid -M -c “Squid user” -d /dev/null -s /sbin/nologin

3. 配制系统环境

在我们的Linux下运行:

# ulimit -n

1024

很显然1024可能无法满足需求,重新设置

# ulimit -HSn 65536

# ulimit -n

65536

需要将ulimit -HSn 65536设置在/etc/rc.d/rc.local中,防止重启后失效, 花费时间来增加这个限制值的大小。否则,squid在高负载时执行性能将很低。

当然你还可以在每一次系统启动后执行上述echo和ulimit命令,或者至少在squid启动之前。假如你使用某个rc.d脚本来启动squid,那是一个放置这些命令的好地方。

临时端口范围

临时端口是TCP/IP栈分配给出去连接的本地端口。换句话说,当squid发起一条连接到另一台服务器,内核给本地socket分配一个端口号。这些本地端口号有特定的范围限制。例如,在FreeBSD上,默认的临时端口范围是1024-5000。

临时端口号的短缺对非常忙的代理服务器(例如每秒数百个连接)来说,会较大的影响性能。这是因为一些TCP连接在它们被关闭时进入TIME_WAIT状态。当连接进入TIME_WATI状态时,临时端口号不能被重用。

你能使用netstat命令来显示有多少个连接进入这个状态:

% netstat -n | grep TIME_WAIT

Proto Recv-Q Send-Q Local Address Foreign Address (state)

tcp4 0 0 192.43.244.42.19583 212.67.202.80.80 TIME_WAIT

tcp4 0 0 192.43.244.42.19597 202.158.66.190.80 TIME_WAIT

tcp4 0 0 192.43.244.42.19600 207.99.19.230.80 TIME_WAIT

tcp4 0 0 192.43.244.42.19601 216.131.72.121.80 TIME_WAIT

tcp4 0 0 192.43.244.42.19602 209.61.183.115.80 TIME_WAIT

tcp4 0 0 192.43.244.42.3128 128.109.131.47.25666 TIME_WAIT

tcp4 0 0 192.43.244.42.3128 128.109.131.47.25795 TIME_WAIT

tcp4 0 0 192.43.244.42.3128 128.182.72.190.1488 TIME_WAIT

tcp4 0 0 192.43.244.42.3128 128.182.72.190.2194 TIME_WAIT

注意这个例子中既有客户端连接又有服务器端的连接。客户端连接有3128作为临时端口号,服务器端连接有80作为远程主机的端口号。临时端口号出现在本地地址栏里。在该例子里,它们是19000秒。

在Linux上,简单的写一对数字到下列指定文件:

# echo “1024 40000″ > /proc/sys/net/ipv4/ip_local_port_range

不要忘记将这些命令加到你的系统启动脚本中,以使机器每一次重启后都生效。

4. 编译安装

tar -zxvf squid-3.0.STABLE13.tar.gz

cd squid-3.0.STABLE13

./configure –prefix=/usr/local/squid3 –enable-dlmalloc –enable-gnuregex –enable-async-io –enable-removal-policies=’heap,lru’ –enable-delay-pools –disable-snmp –enable-storeio=’ufs,aufs,null’ –disable-wccp –enable-kill-parent-hack –disable-select –enable-auth=basic –with-aio –disable-ident-lookup –with-filedescriptors=65536 –enable-err-languages=”Simplify_Chinese” –enable-default-err-languages=”Simplify_Chinese”

make

make install

后面每一参数,对有对应的意思。这里就不在解释,网上有很多。

其实squid最重要的就一个squid.conf的配制问题。

在/usr/local/squid3/etc/squid.conf

参照下面的示例来理解配置文件

visible_hostname squid1.ihompy.com

#设定squid的主机名,如无此项squid将无法启动

http_port 80 accel vhost vport

#设定squid为accel加速模式,vhost必须要加.否则将无法将主机头转发至后端服务器,访问时就会出现无法找到主机头的错误

cache_peer www.contentchina.com parent 80 0 no-query originserver name=contentchina

cache_peer bbs.contentchina.com parent 80 0 no-query originserver name=bbs

cache_peer www.ihompy.com parent 80 0 no-query originserver name=ihompy

#定义不同的父节点,将节点设为no-query以及originserver说明这些节点是实际服务器

cache_peer_domain contentchina www.contentchina.com

cache_peer_domain bbs bbs.contentchina.com

cache_peer_domain ihompy www.ihompy.com

#设定不同域名转发到不同的cache_peer上,如果没有这项.不同域名的域名可能被分发到同一台服务器上.

acl all src 0.0.0.0/0.0.0.0

http_access allow all

#允许所有客户端访问

cache_log /var/log/squid/cache.log

#记录日志

#***********ACL存取控制*************

acl QueryString url_regex \.php?

#***********缓冲存取控制*************

no_cache deny QueryString

#不对符合QueryString的ACL内容进行缓冲

#***********性能优化配置*************

maximum_object_size 320010 KB

#大于此容量的对象将不会被保存在磁盘上,默认大小是4M,如果squid服务器用于缓冲flash等大型文件,建议将此值变大.否则过大的文件在下次重启后将需要重新获取

maximum_object_size_in_memory 100 KB

#最大位于内存中的对象的大小,默认大小是8K,如果服务器内存很大.可以适当提高此值的大小,建议根据网站的80%图片的大小来定.或者根据WEB服务器实际存取文件中最常访问的文件大小来定制

#***********其他可选配置*************

dns_nameservers 10.0.0.1 192.172.0.4

#配置DNS服务器地址.获取后端时将从此dns获取IP地址

cache_mgr code_tin@msn.com

#在错误日志中出现的webmaster地址.

Squid 3.0与2.6一样.相较2.5的accel模式下配置要简单许多

只要设置不同的后端,cache_peer parent originserver

就可以进行反向代理

而不再需要httpd_accel系列参数的配置.

配置squid时最好制定内部dns,或者修改/etc/hosts文件

否则squid可能会回环访问其自身而出现问题.

自己的配置过程:

http_port 80 选项 http_port 指定squid监听HTTP请求的端口,一般都设置成80端口,这样使用户感觉不到反向代理的存在,就像访问真正

的WEB服务器一样。

我配置的是:http_port 80 accel vhost vport

cache_mem 128 MB 共享内存大小(squid在提供服务的时候所使用的内存)

maximum_object_size_in_memory 512 KB 最大缓存文件大小,超过此值则不缓存

memory_replacement_policy lru 替换机制 (lru叫做 最近不常用的单元 unit一般就是常说的object 也就是当cache中的内容比如内存或硬盘达到上限时的 那么就需要进行数据的换进和换出工作)

cache_dir null /tmp cache_dir存储cache内容也就是object的物理存放点 

cache_dir ufs /tmp1 10000 16 256 (/tmp size L1 L2)

100G其中1层目录16个 并且每个1层目录下又有256个2层目录[或者说子目录]

#磁盘缓存的类型和目录,大小,一二级目录的设置,这里磁盘缓存大小是10G

ufs是一种文件存储方式 因为os一般都是从内存获取数据 那么内存的东西必须最后写的硬盘上~

sync 同步的时候用的ufs 那么squid也是一样

ufs一般是同时写入内存和硬盘

注意:size是按照M为单位的也就这个目录中最大存储容量的上限

max_open_disk_fds 0

minimum_object_size 0 KB

maximum_object_size 4096 KB

logformat squid %ts.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt

设置access_log中日志存储的格式~

access_log /usr/local/squid3/var/logs/access.log squid

access_log为客户端请求的日志 

cache_log /usr/local/squid3/var/logs/cache.log

为squid自身的运行日志 

pid_filename /usr/local/squid3/var/logs/squid.pid

此三项是设置PID和日志文件位置

cache_store_log none 不记录store.log 我配置的是可以允许

visible_hostname wqgcool.wqgcool.net

wqgcool.wqgcool.net 只是标签 有利于检查是否你的那台设备在提供服务!

cache_peer newtest.haishang.com parent 80 0 no-query round-robin max-conn=32 originserver

acl all src 0.0.0.0/0.0.0.0 */3.0后默认是全部允许了。

故配置成:acl all src

给/usr/local/squid3/var/logs 等权限

chmod -R 777 /usr/local/squid3/var

chmod -R 777 /usr/local/squid3/var/logs

chown squid:squid -R /usr/local/squid3/var/logs

接下来

acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe

cache deny QUERY

这个squid.conf我没找到。

cache_effective_user squid

cache_effective_group squid

这两个我没有配置,如配置的话,squid启动一会儿就会关闭。

没启用的话,进程里会显示nobody身份启动的。反正不影响工作。

可以用ps auxwww | grep squid 查看进程

5.测试配置是否正确

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

出现ERROR:

WARNING: Cannot write log file: /usr/local/squid3/var/logs/cache.log

/usr/local/squid3/var/logs/cache.log: Permission denied

messages will be sent to ‘stderr’.

2008/03/13 12:53:09| Creating Swap Directories

FATAL: Failed to make swap directory /usr/local/squid3/var/cache: (13) Permission denied

/usr/local/squid2/sbin/squid -z 

Create swap directories 是创建SWAP目录的! 也就是cache_dir 中的目录

启动squid

/usr/local/squid3/sbin/squid -Nd1

ps aux |grep squid 查看是否启动

squid 常用命令

Squid安装设试命令:

很明显权限不对,修改后测试通过!

1,初始化你在 squid.conf 里配置的 cache 目录

#/usr/local/squid/sbin/squid -z //初始化缓存空间

如果有错误提示,请检查你的 cache目录的权限。

2,对你的squid.conf 排错,即验证 squid.conf 的 语法和配置。

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

如果squid.conf 有语法或配置错误,这里会返回提示你,如果没有返回,恭喜,可以尝试启动squid。

3,在前台启动squid,并输出启动过程。

#/usr/local/squid/sbin/squid -N -d1

如果有到 ready to server reques,恭喜,启动成功。

然后 ctrl + c,停止squid,并以后台运行的方式启动它。

4,启动squid在后台运行。

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

这时候可以 ps -A 来查看系统进程,可以看到俩个 squid 进程。

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./usr/local/squid/sbin/squid -k rotate 轮循日志

8,把squid添加到系统启动项

编辑 /etc/rc.d/rc.local

添加如下行: /usr/local/squid/sbin/squid -s

利用Runc脚本……..

再来点其他的。

1,修改cache 缓存目录的权限。

#chown -R squid:squid /data/cache

我的cache缓存目录是 /data/cache,squid执行用户和用户组是 squid,squid。

2,修改squid 日志目录的权限

#chown -R squid:squid /usr/local/squid/var/logs

这一步并不是适合每一个使用squid的用户.意为让squid有权限在该目录进行写操作 。

例如生成 access.log cache.log store.log

3,查看你的日志文档。

#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缓存,而是现重原始服务器获取并返回给访问用户。

关于 TCP_XXXX 等参数及代表的信息,请参看《squid中文权威指南》13.2.1 章节。

当然,本例中的蓝色文字是可以修改为其他的参数,例如你的域名 www.xxxx.com ,同样可以看到access.log里关于该域名的行。

二.squid命中率分析

squid/bin/squidclient -p 80 mgr:info

squid/bin/squidclient -p 80 mgr:5min

可以看到详细的性能情况,其中PORT是你的proxy的端口,5min可以是60min

取得squid运行状态信息: squidclient -p 80 mgr:info

*取得squid内存使用情况: squidclient -p 80 mgr:mem

*取得squid已经缓存的列表: squidclient -p 80 mgrbjects. use it carefully,it may crash

*取得squid的磁盘使用情况: squidclient -p 80 mgr:diskd

*强制更新某个url:squidclient -p 80 -m PURGE http://www.yejr.com/static.php
*更多的请查看:squidclient-h 或者 squidclient -p 80 mgr:

查命中率:

/usr/local/squid/bin/squidclient -h111.222.111.111 -p80 mgr:info

/usr/local/squid/bin/squidclient -h具体的IP -p80 mgr:info
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: