mysql squid_Squid基本配置

/etc/squid/squid.conf squid主配置文件

#定义Squid服务的监听的端口。默认:3128

http_port 3128

#定义Squid可以使用的内存数量的理想值,一般为总内存的三分之一。因为实际运行,Squid使用的内存数量肯定远远超过它

cache_mem 8 MB

#指定Squid用来存储交换空间大小及目录结构。

cache_dir ufs /var/spool/squid 100 16 256

#用户端请求的数据的记录完整的路径,包括文件名称及所在的目录。该请求可以来自一般用户的web请求。

cache_access_log /var/log/squid/access.log

#Squid服务器普通信息的日志的完整路径。

cache_log /var/log/squid/cache.log

#指定对象存储记录日志的完整路径,该记录说明哪些对象被存储到对象空间中。

cache_store_log /var/log/squid/store.log

acl all src 0.0.0.0/0.0.0.0

acl manager proto cache_object

acl localhost src 127.0.0.1/255.255.255.255

acl to_localhost dst 127.0.0.0/8

acl SSL_ports port 443 563

acl Safe_ports port 80 # http

acl Safe_ports port 21 # ftp

acl Safe_ports port 443 563 # https, snews

acl Safe_ports port 70 # gopher

acl Safe_ports port 210 # wais

acl Safe_ports port 1025-65535 # unregistered ports

acl Safe_ports port 280 # http-mgmt

acl Safe_ports port 488 # gss-http

acl Safe_ports port 591 # filemaker

acl Safe_ports port 777 # multiling http

acl CONNECT method CONNECT

#对所有来自子网的HTTP请求均不作限制。

http_access allow all

# 禁止来自!Safe_ports的HTTP请求。

http_access deny !Safe_port

# 设置cache管理员的邮件箱地址。

#cache_mgr reason@nou.com.cn

acl

访问权限列表

acl aclname src ipadress/netmask

类型:

src dst srcdomain dstdomain time port protocol method browser uer

src 指明源地址

src aclname src ipadress/netmask

dst 指明目标地址

src aclname dst ipadress/netmask

srcdomain 指明客户的源地址

src aclname srcdomain domain

dstdomain 指明请求服务器的域名

src aclname dstdomain domain

time 指明访问时间

acl aclname time [day-abbrevs] [h1:m1-h2:m2][hh:mm-hh:mm]

post 指定访问端口

acl aclname port [1~1024]

method 指定的请求方法

acl aclname method get post...

visible_hostname squid

#/etc/init.d/squid start

#/etc/init.d/squid stop

优化squid配置

squid.conf相关解释:

#取消对代理阵列的支持

icp_port 0

#对日志文件和pid文件位置进行设置

cache_store_log none

cache_access_log /var/log/squid/access.log

cache_log /var/log/squid/cache.log

emulate_httpd_log on

pid_filename /var/run/squid.pid

#设置运行时的用户和组权限

cache_effective_user squid

cache_effective_group squid

#设置管理信息

visible_hostname proxy.yxtc.edu.cn

cache_mgr bye2000@yxtc.edu.cn

#设置监听地址和端口

http_port 3128

tcp_incoming_address x.x.x.x

udp_incoming_address x.x.x.x

#见下面补充说明

cache_mem 32 MB

cache_dir /cache 6000 14 256

#设置cache对象超时时间

reference_age 3 months

#访问控制设置

acl mynet src 192.168.1.0/255.255.255.0

acl all src 0.0.0.0/0.0.0.0

http_access allow mynet

http_access deny all

#透明代理设置

httpd_accel_host virtual

httpd_accel_port 80

httpd_accel_with_proxy on

httpd_accel_uses_host_header on

#swap 性能微调

half_closed_clients off

cache_swap_high 100%

cache_swap_low 80%

maximum_object_size 1024 KB

#见补充说明

refresh_pattern -i .html 1440 90% 129600 reload-into-ims

refresh_pattern -i .shtml 1440 90% 129600 reload-into-ims

refresh_pattern -i .hml 1440 90% 129600 reload-into-ims

refresh_pattern -i .gif 1440 90% 129600 reload-into-ims

refresh_pattern -i .swf 1440 90% 129600 reload-into-ims

refresh_pattern -i .jpg 1440 90% 129600 reload-into-ims

refresh_pattern -i .png 1440 90% 129600 reload-into-ims

refresh_pattern -i .bmp 1440 90% 129600 reload-into-ims

refresh_pattern -i .js 1440 90% 129600 reload-into-ims

补充说明:

1.cache_mem 32 MB

注意:cache_mem并不是squid所能使用内存的大小,而是squid用户hot object的物理内存的大小,所以这个值可以小一些。

2.cache_dir /cache 6000 14 256

对于第一级子目录和第二级子目录的计算方法,可以参考笔者以前的文章《用LINUX架设代理服务器(上)(中)(下)》;

3.refresh_pattern -i .html 1440 90% 129600 reload-into-ims等

这几句其实是强行控制对象的超时时间,这违反了http协议的精神,但是在带宽较窄的场合,可以提高明显系统相应时间。

4.注意/cache目录及日志文件的权限,其所有用户和所有组必须为squid;

5.可以采用rpm包的脚本/etc/rc.d/init.d/squid控制squid,也可以采用squid命令控制,具体可以参考squid –h

一个squid配置文件的注释

# NETWORK OPTIONS(有关的网络选项)

# -----------------------------------------------------------------------------

http_port 3128 #代理端口

icp_port 3130 #icp端口

# OPTIONS WHICH AFFECT THE NEIGHBOR SelectION ALGORITHM(作用于邻居选择算法的有关选项)

#-----------------------------------------------------------------------------

#禁止缓存

hierarchy_stoplist cgi-bin ?

hierarchy_stoplist -i ^https:\\ ?

acl QUERY urlpath_regex -i cgi-bin \? \.asp \.php \.jsp \.cgi

acl denyssl urlpath_regex -i ^https:\\

no_cache deny QUERY

no_cache deny denyssl

#上面几个就是说遇到URL中有包含cgi-bin和以https:\\开头的都不要缓存,

#还有asp、cgi、php等动态脚本也不要缓存,

#因为这些脚本通常都是动态更新的,这样数据不同步。

#还有https://开通的不缓存是因为一般我们进行电子商务交易,

#例如银行付款等都是采用这个的,如果把信用卡号什么缓存那不是很危险。

# OPTIONS WHICH AFFECT THE CACHE SIZE(定义cache大小的选项)

# -----------------------------------------------------------------------------

cache_mem 8 MB #额外使用内存量,可根据你的系统内存在设定,一般为实际内存的1/3

cache_swap_low 90 #最低缓存百分比

cache_swap_high 95 ##最高缓存百分比,就是上面那个额外内存的使用百分比

maximum_object_size 4096 KB #单个文件最大缓存大小,超过这个大小将不缓存

maximum_object_size_in_memory 8 KB #在内存中单个文件最大缓存大小,超过这个大小将不缓存到内存中

#有DNS正反解所得到的IP存在缓存区的大小,这样可以加快解析速度

ipcache_size 1024

ipcache_low 90

ipcache_high 95

fqdncache_size 1024

# LOGFILE PATHNAMES AND CACHE DIRECTORIES(定义日志文件的路径及cache的目录)

# -----------------------------------------------------------------------------

#  ; ; ; ; ; ;

#  那个 aufs 只有在编译的时候加入 --enable-async-io 那个选项才有支持,

#  至于目录所在地与所占用的磁盘大小则请视您的主机情况而定,

#  而后面 dir1, dir2 则是两个次目录的大小,通常 16 256 或 64 64 皆可,

#  一般来说,数字最好是 16 的倍数,据说性能会比较好啦!

cache_dir aufs /Cache1 100 16 256

cache_dir aufs /Cache2 100 16 256

#日志存放位置

cache_access_log /usr/local/squid/var/logs/access.log

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

# TAG: cache_store_log

cache_store_log /usr/local/squid/var/logs/store.log

# TAG: pid_filename

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

# OPTIONS FOR EXTERNAL SUPPORT PROGRAMS(外部支持程序选项)

# -----------------------------------------------------------------------------

#用代理登陆匿名ftp服务选项

# TAG: ftp_user

ftp_user Squid@ #用户名

ftp_passive on #被动模式

#认证

#auth_param basic children 5

#auth_param basic realm Squid proxy-caching web server

#auth_param basic credentialsttl 2 hours

#auth_param basic casesensitive off

# OPTIONS FOR TUNING THE CACHE(调整cache的选项)

# -----------------------------------------------------------------------------

# TAG: refresh_pattern Cache更新时间设置

#; ; ; ; ;

refresh_pattern ^ftp: 1440 20% 10080

refresh_pattern ^gopher: 1440 0% 1440

refresh_pattern . 0 20% 4320

#上面第一行如果网址开头是 ftp 的话,那么在一天(1440分钟)后,

#如果proxy 再次取用这个档案时,则 cache 内的数据会被更新!

# TIMEOUTS (超时)

# -----------------------------------------------------------------------------

#连接到其他机器的最大尝试时间

connect_timeout 1 minute

#连接到上层代理的超时时间

peer_connect_timeout 30 seconds

#返回超时

request_timeout 2 minutes

#持续连接时间

persistent_request_timeout 1 minute

# ACCESS CONTROLS(访问控制)

# -----------------------------------------------------------------------------

# TAG: acl

#Examples:

#acl myexample dst_as 1241

#acl password proxy_auth REQUIRED

#acl fileupload req_mime_type -i ^multipart/form-data$

#acl javascript rep_mime_type -i ^application/x-javascript$

#

#Recommended minimum configuration:

acl all src 0.0.0.0/0.0.0.0

acl manager proto cache_object

acl localhost src 127.0.0.1/255.255.255.255

acl to_localhost dst 127.0.0.0/8

acl SSL_ports port 443 563

acl Safe_ports port 80 # http

acl Safe_ports port 21 # ftp

acl Safe_ports port 443 563 # https, snews

acl Safe_ports port 70 # gopher

acl Safe_ports port 210 # wais

acl Safe_ports port 1025-65535 # unregistered ports

acl Safe_ports port 280 # http-mgmt

acl Safe_ports port 488 # gss-http

acl Safe_ports port 591 # filemaker

acl Safe_ports port 777 # multiling http

acl CONNECT method CONNECT

acl inside src 192.168.1.0/24 #内部网IP段

acl localmac arp "/usr/local/squid/localmac" #mac地址文件

# TAG: http_access

http_access allow inside #允许inside规则通过

http_access allow localmac #允许localmac里面有登记的mac地址通过

#

#Recommended minimum configuration:

#

# Only allow cachemgr access from localhost

http_access allow manager localhost

http_access deny manager

# Deny requests to unknown ports

http_access deny !Safe_ports

# Deny CONNECT to other than SSL ports

http_access deny CONNECT !SSL_ports

#

#http_access deny to_localhost

#

# And finally deny all other access to this proxy

http_access deny all

# TAG: http_reply_access

http_reply_access allow all

# TAG: icp_access

#icp_access allow all

# TAG: cache_peer_access

# ADMINISTRATIVE PARAMETERS(管理参数)

# -----------------------------------------------------------------------------

# TAG: cache_mgr

cache_mgr webmaster@localhost #管理员信箱

# TAG: cache_effective_user

cache_effective_user squid #运行squid时的用户

cache_effective_group squid #运行squid时的组

# TAG: visible_hostname

visible_hostname ProxyServer #代理服务器名称

# OPTIONS FOR THE CACHE REGISTRATION SERVICE(cache注册服务选项)

# -----------------------------------------------------------------------------

# HTTPD-ACCELERATOR OPTIONS(HTTPD加速选项)

# -----------------------------------------------------------------------------

#设定透明代理

httpd_accel_host ProxyServer #主机名

httpd_accel_port 80 #透明代理端口

httpd_accel_with_proxy on

httpd_accel_uses_host_header on

# MISCELLANEOUS(杂项)

# -----------------------------------------------------------------------------

# TAG: logfile_rotate

#squid会定期的将日志文件更名并打包。

#比如正在使用的日志文件为access.log,squid会将其更名并打包为 access.log.1.gz;

#过了一定时间后,squid又会将access.log.1.gz更名为access.log.2.gz

#并将当前的日志文件更名并打包为access.log.1.gz,以此循环。

#logfile_rotate指定的数字即为打包并备份的文件的数量,当达到这一数目时,

#squid将删除最老的备份文件。默认值为1 0。如果想手动来进行这些操作,

#可以用logfile_rotate 0来取消自动操作。

logfile_rotate 4

# TAG: forwarded_for on|off

#关闭此项将在访问某些论坛时显示的IP是unknown,

#如果打开则显示的是你client的内网IP

forwarded_for off

#图标文件目录

# icon_directory /usr/local/squid/share/icons

#错误提示文件目录

# error_directory /usr/local/squid/share/errors/Simplify_Chinese

# TAG: snmp_port

# Squid can now serve statistics and status information via SNMP.

# By default it listens to port 3401 on the machine. If you don''t

# wish to use SNMP, set this to "0".

#

#Default:

# snmp_port 3401

# TAG: snmp_access

# Allowing or denying access to the SNMP port.

#

# All access to the agent is denied by default.

# usage:

#

# snmp_access allow|deny [!]aclname ...

#

#Example:

# snmp_access allow snmppublic localhost

# snmp_access deny all

#

#Default:

# snmp_access deny all

# DELAY POOL PARAMETERS (all require DELAY_POOLS compilation option)(延时池参数)

# -----------------------------------------------------------------------------

# TAG: coredump_dir

#当squid突然挂掉的时候,或者突然出现什么故障的时候,将squid在内存中的资料写到硬盘中

coredump_dir /usr/local/squid/var/cache

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值