Archive for 十二月 5th, 2005


squid反向代理

只说明几个关键的配置:


打开squid.conf


#squid服务器用80端口作为访问端口
http_port 80
#要代理的http服务器ip/域名
httpd_accel_host localhost
#如果是虚拟主机
httpd_accel_host virtual test.mydomain.com
#代理http服务器端口
httpd_accel_port 80


squid.conf sample:
http_port 80
icp_port 0
acl ALL_QUERY urlpath_regex [.]*
http_access allow ALL_QUERY
cache_mem 16 MB
cache_dir ufs /tmp 256 16 256
log_icp_queries off
buffered_logs on
emulate_httpd_log on
redirect_rewrites_host_header off
half_closed_clients off
acl all src 0.0.0.0/0.0.0.0
http_access allow all
cache_mgr admin
httpd_accel_host www.cruelyouth.com
httpd_accel_port 80
visible_hostname cache1
cache_effective_user squid_user

squid基本安装运行

1、下载一个可编译的稳定版本,目前版本应为2.5
ftp://www.squid-cache.org/pub/squid-2/STABLE/


2、安装squid-2.5.STABLE5.tar.gz
        % tar xzf squid-2.5.STABLE5.tar.gz
        % cd squid-2.5.STABLE5
        % ./configure –prefix=/usr/local/squid
        % make
        % make install


附configure options


  –prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local/squid]
  –enable-dlmalloc[=LIB] Compile & use the malloc package by Doug Lea
  –enable-gnuregex       Compile GNUregex
  –enable-splaytree      Use SPLAY trees to store ACL lists
  –enable-xmalloc-debug  Do some simple malloc debugging
  –enable-xmalloc-debug-trace
                          Detailed trace of memory allocations
  –enable-xmalloc-statistics
                          Show malloc statistics in status page
  –enable-carp           Enable CARP support
  –enable-async-io       Do ASYNC disk I/O using threads
  –enable-icmp           Enable ICMP pinging
  –enable-delay-pools    Enable delay pools to limit bandwith usage
  –enable-mem-gen-trace  Do trace of memory stuff
  –enable-useragent-log  Enable logging of User-Agent header
  –enable-kill-parent-hack
                          Kill parent on shutdown
  –enable-snmp           Enable SNMP monitoring
  –enable-cachemgr-hostname[=hostname]
                          Make cachemgr.cgi default to this host
  –enable-arp-acl        Enable use of ARP ACL lists (ether address)
  –enable-htpc           Enable HTCP protocol
  –enable-forw-via-db    Enable Forw/Via database
  –enable-cache-digests  Use Cache Digests
                          see http://www.squid-cache.org/Doc/FAQ/FAQ-16.html
  –enable-err-language=lang
                          Select language for Error pages (see errors dir)


3、现在squid安装在/usr/local/squid下
要启动需编辑etc/squid.conf文件
cache_effective_user=squid
cache_effective_group=squid
然后将/usr/local/squid/var/logs目录分配给squid用户
        % chown squid.squid -R /usr/local/squid/var/logs


4、创建swap空间
        % /usr/local/squid/sbin/squid -z

5、检查配置
       % /usr/local/squid/sbin/squid -k parse
如果没有任何提示则表明配置无误。


6、启动
调试模式:
       % /usr/local/squid/sbin/squid -NCd1
服务模式
       % /usr/local/squid/sbin/squid


7、关闭
       % /usr/local/squid/sbin/squid -k shutdown


附录,squid 命令参数


-a

Specify an alternate port number for incoming HTTP requests. Useful for testing a configuration file on a non-standard port.


-d

Debugging level for “stderr” messages. If you use this option, then debugging messages up to the specified level will also be written to stderr.


-f

Specify an alternate squid.conf file instead of the pathname compiled into the executable.


-h

Prints the usage and help message.


-k reconfigure

Sends a HUP signal, which causes Squid to re-read its configuration files.


-k rotate

Sends an USR1 signal, which causes Squid to rotate its log files. Note, if logfile_rotate is set to zero, Squid still closes and re-opens all log files.


-k shutdown

Sends a TERM signal, which causes Squid to wait briefly for current connections to finish and then exit. The amount of time to wait is specified with shutdown_lifetime.


-k interrupt

Sends an INT signal, which causes Squid to shutdown immediately, without waiting for current connections.


-k kill

Sends a KILL signal, which causes the Squid process to exit immediately, without closing any connections or log files. Use this only as a last resort.


-k debug

Sends an USR2 signal, which causes Squid to generate full debugging messages until the next USR2 signal is recieved. Obviously very useful for debugging problems.


-k check

Sends a “ZERO” signal to the Squid process. This simply checks whether or not the process is actually running.


-s

Send debugging (level 0 only) message to syslog.


-u

Specify an alternate port number for ICP messages. Useful for testing a configuration file on a non-standard port.


-v

Prints the Squid version.


-z

Creates disk swap directories. You must use this option when installing Squid for the first time, or when you add or modify the cache_dir configuration.


-D

Do not make initial DNS tests. Normally, Squid looks up some well-known DNS hostnames to ensure that your DNS name resolution service is working properly.


-F

If the swap.state logs are clean, then the cache is rebuilt in the “foreground” before any requests are served. This will decrease the time required to rebuild the cache, but HTTP requests will not be satisified during this time.


-N

Do not automatically become a background daemon process.


-R

Do not set the SO_REUSEADDR option on sockets.


-V

Enable virtual host support for the httpd-accelerator mode. This is identical to writing httpd_accel_host virtual in the config file.


-X

Enable full debugging while parsing the config file.


-Y

Return ICP_OP_MISS_NOFETCH instead of ICP_OP_MISS while the swap.state file is being read. If your cache has mostly child caches which use ICP, this will allow your cache to rebuild faster.



原文参考:http://www.squid-cache.org/Doc/FAQ/FAQ.html

Powered by WordPress. Theme: Motion by 85ideas.