July 2007 Archives

孔大石头...... 我不知写些什么好了

人生是如此的脆弱

操作实例] squid-2.6.STABLE1-20060726之Web加速实做


  2.6相对2.5有了一些改变,大家可以去看:http://www.squid-cache.org/Versions/v2/2.6/

  1. 下载squid2.6 http://www.squid-cache.org/Versions/v2/2.6/squid-2.6.STABLE1-20060726.tar.gz

  2. 安装:

wwwtest137#tar xzvf squid-2.6.STABLE1-20060726.tar.gz
wwwtest137#cd squid-2.6.STABLE1-20060726
wwwtest137#configure --prefix=/usr/local/squid --enable-dlmalloc --with-pthreads --enable-poll --disable-internal-dns --enable-stacktrace --enable-removal-policies="heap,lru" --enable-delay-pools --enable-storeio="aufs,coss,diskd,ufs"
wwwtest137#make
wwwtest137#make install

  安装完成了。
  因为是测试的,所以相关的参数可能并不是比较完善的,但是使用是没有问题的。

  3. 配置:以下是部分关键配置,其他与2.5的相同

#squid.conf
#服务器IP 192.168.1.1
#监听服务器的80端口,透明代理,支持域名和IP的虚拟主机
http_port 192.168.1.1:80 transparent vhost vport

#限制同一IP客户端的最大连接数
acl OverConnLimit maxconn 16
http_access deny OverConnLimit

#防止天涯盗链,转嫁给百度
acl tianya referer_regex -i tianya
http_access deny tianya
deny_info http://www.baidu.com/logs.gif tianya

#防止被人利用为HTTP代理,设置允许访问的IP地址
acl myip dst 192.168.1.1
http_access deny !myip

#防止百度机器人爬死服务器
acl AntiBaidu req_header User-Agent Baiduspider
http_access deny AntiBaidu

#允许本地管理
acl Manager proto cache_object
acl Localhost src 127.0.0.1 192.168.1.1
http_access allow Manager Localhost
http_access deny Manager

#仅仅允许80端口的代理
acl Safe_ports port 80 # http
http_access deny !Safe_ports
http_access allow all

#Squid信息设置
visible_hostname www.test137.com
cache_mgr webmaster@test137.com

#基本设置
cache_effective_user squid
cache_effective_group squid
tcp_recv_bufsize 65535 bytes

#2.5的反向代理加速配置
#httpd_accel_host 127.0.0.1
#httpd_accel_port 80
#httpd_accel_single_host on
#httpd_accel_uses_host_header on
#httpd_accel_with_proxy on
#2.6的反向代理加速配置
#代理到本机的80端口的服务,仅仅做为原始内容服务器
cache_peer 127.0.0.1 parent 80 0 no-query originserver

#错误文档
error_directory /usr/local/squid/share/errors/Simplify_Chinese

#单台使用,不使用该功能
icp_port 0

  4. http服务器配合设置:
http服务器,监听到127.0.0.1的80端口。

  5. 数据走向:
访问者=>192.168.1.1:80=>127.0.0.1:80

  6. 测试:
/usr/local/squid/sbin/squid -z
/usr/local/squid/sbin/squid -NCd1
  好了,现在访问你的服务器看看,已经好了。

  为了测试是否可用,把http服务器给停了,你就可以看到squid2.6的信息了。

  另外,我们设置:
SQUID监听外部IP的80端口
HTTP服务器监听本机127.0.0.1的80端口
这样子不用任何防火墙参与,即可完成web反向代理加速。

Technorati :

squid文件配置说明(中文)[zz]


http_port 8080 设置http代理端口为8080

cache_peer pa.us.ircache.net sibling 3128 3130 login=*:*

cache_peer sj.us.ircache.net sibling 3128 3130 login=*:*

cache_peer * parent 13280 4827 htcp *:*


这几行是使用squid可以和其他几台机器进行协同工作的特性,同几台组成cache_peer。具体设置在后面的优化部分会解释。


cache_peer_domain * .edu.cn设置.edu.cn的域名使用某个cache_peer访问

cache_mem 400 MB设定内存cache的大小为400M

cache_swap_low 80

cache_swap_high 97这两行是设置cache进行替换的闸值。当占用到97%的cache后,cache中的内容将被清空20%。

maximum_object_size 20000 KB 最大对象大小为20M.

maximum_object_size_in_memory 10000 KB 内存中最大的对象大小为10M

ipcache_size 4096 ip对应cache的大小为4096

fqdncache_size 4096 域名全称cache的大小为4096

cache_replacement_policy heap LFUDA cache替换策略

memory_replacement_policy heap LRU 内存替换策略

cache_dir ufs /usr/local/squid/cache 25000 16 256 cache存放的路径大小及具体配置

dns_nameservers * * * * * 内部指定dns服务器

authenticate_program * * 身份认证程序

authenticate_children 32 身份认证程序启动的进程数目

request_body_max_size 5 MB 最大请求的body大小

reply_body_max_size 20 MB 最大回应的body大小

acl all src 0.0.0.0/0.0.0.0

acl dorm proxy_auth 192.168.0.0/255.255.0.0 REQUIRED

acl bjpu proxy_auth 202.112.64.0/255.255.240.0 REQUIRED

acl bjpu2 proxy_auth 211.71.80.0/255.255.240.0 REQUIRED


访问控制列表


acl banned_sites

http_access deny banned_sites

deny_info ERR_BANNED_SITE banned_sites


禁止访问违禁站点的设置


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 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_access allow dorm

http_access allow bjpu

http_access allow bjpu2

http_access allow manager localhost

http_access deny manager

http_access deny !Safe_ports

http_access deny CONNECT !SSL_ports

http_access deny all


允许http访问


icp_access allow *允许cache_peer使用ICP协议访问

proxy_auth_realm BJPU proxy-caching web server 验证框提示的banner

cache_mgr liukange@netease.com cache管理员的电子邮件地址

cache_effective_user *

cache_effective_group * 执行cache程序的用户uid和gid

visible_hostname cnproxy.bjpu.edu.cn cache服务的机器名

memory_pools on 内存池设置为打开。

memory_pools_limit 50 MB 内存池的大小


Socks5代理的安装


出国代理上选用的socks5代理软件是NEC公司制作的软件。它实际上是一个商业版软件。但是根据它的license文件所述,在非商业用途上使用这个软件是免费的。在

RFC-1928对socks5如何运行做了详细的描述。这个标准就是NEC公司的"Ying-Da Lee"和HP及IBM公司制定的。在相应的测试中,NEC公司的这个socks5代理软件的性

能是较好的。虽然它有一些安全上的漏洞,但是使用freebsd的ports方式安装,将会自动对源代码打补丁,修正安全隐患。


在/usr/ports/net/socks5下执行make;make install就能安装好该程序。相应的文件将被安装在下列目录:


socks5可执行文件被放在/usr/local/bin

socks5.conf文件被放在/usr/local/etc下


bugtraq上曾经提到socks5的密码验证部分有安全隐患,因此没有使用该功能。


Socks5代理的配置

Socks5代理的配置文件是socks5.conf,内容如下:


set SOCKS5_MAXCHILD 8000

permit - - 192.168. - (1024,65535) -

permit - - 202.112.64.0/255.255.240.0 - (1024,65535) -

permit - - 211.71.80.0/255.255.240.0 - (1024,65535) -


限制工大可以使用该socks5代理,限制目标端口为1024-65535。设置最多可以有8000个进程运行。


配置文件的切换


为了避免带宽的浪费,出国代理设置为夜间取消最大下载对象限制。这是是使用crontab来做到的。每天夜间23:30将配置文件切换为没有最大下载对象限制的。每天上午7:30切换回有最大下载对象限制的。

啥JB东西........

|

tongpu# portaudit -Fda
fetch: http://www.FreeBSD.org/ports/auditfile.tbz: No address record
Couldn't fetch database.
Old database restored.
portaudit: Download failed.


tongpu# dig www.freebsd.org

; <<>> DiG 9.3.3 <<>> www.freebsd.org
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 14048
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 0

;; QUESTION SECTION:
;www.freebsd.org. IN A

;; AUTHORITY SECTION:
. 3600000 IN NS A.ROOT-SERVERS.NET.
. 3600000 IN NS B.ROOT-SERVERS.NET.
. 3600000 IN NS C.ROOT-SERVERS.NET.
. 3600000 IN NS D.ROOT-SERVERS.NET.
. 3600000 IN NS E.ROOT-SERVERS.NET.
. 3600000 IN NS F.ROOT-SERVERS.NET.
. 3600000 IN NS G.ROOT-SERVERS.NET.
. 3600000 IN NS H.ROOT-SERVERS.NET.
. 3600000 IN NS I.ROOT-SERVERS.NET.
. 3600000 IN NS J.ROOT-SERVERS.NET.
. 3600000 IN NS K.ROOT-SERVERS.NET.
. 3600000 IN NS L.ROOT-SERVERS.NET.
. 3600000 IN NS M.ROOT-SERVERS.NET.

;; Query time: 4 msec
;; SERVER: 202.96.209.5#53(202.96.209.5)
;; WHEN: Sat Jul 7 21:44:11 2007
;; MSG SIZE rcvd: 244

tongpu# ping www.freebsd.org
ping: cannot resolve www.freebsd.org: No address associated with name

tongpu69.147.83.33# cat /etc/resolv.conf
nameserver 202.96.209.5
nameserver 202.96.209.133

About this Archive

This page is an archive of entries from July 2007 listed from newest to oldest.

May 2007 is the previous archive.

August 2007 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.1