转http://hi.baidu.com/suantop/blog/item/8abac18dbbfde816b21bba2d.html
squid3.0反向代理 apache+squid2008-03-19 16:10apache(81端口)+squid(80端口)(apache和squid跑在同一个机器上面 要实现反向代理 )我将我的外网域名用abc.com代替了
apache简单配置如下:
Listen 81
NameVirtualHost *
<VirtualHost *>
<Directory "/usr/local/www/">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Satisfy all
</Directory>
ServerName www.abc.com
ServerAdmin webadmin@abc.com
DocumentRoot "/usr/local/www/"
DirectoryIndex index.jsp
# ErrorLog "/usr/local/apache/logs/abc-error_log"
# SetEnvIf Remote_Addr "::1" dontlog
# CustomLog "/usr/local/apache/logs/abc-access_log" combined env=!dontlog
</VirtualHost>
此时可以通过lsof -i:81查看谁占用81端口
确保http://www.abc.com:81 访问没有问题得到的是/usr/local/www发布的站点
开始squid的安装配置:
wget http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE2.tar.gz
#useradd squid
#groupadd squid
#tar zxvf squid-3.0.STABLE2.tar.gz
#cd squid-3.0.STABLE2
#./configure --prefix=/usr/local/squid --disable-carp --with-aufs-threads=32 --with-pthreads --enable-storeio='ufs,aufs,coss,null' --enable-disk-io='AIO,Blocking' --enable-removal-policies='heap,lru' --disable-wccp --enable-kill-parent-hack --disable-snmp --disable-poll --disable-select --enable-auth=basic --with-aio --disable-ident-lookup --with-filedescriptors=65536
#make
#make install
可能需要创建一些文件 这些都是配置文件中需要调用的(这个要注意文件的属主和权限)
#cd /usr/local/squid/var/logs/
#touch cache.log
#chmod 755 cache.log
#chown squid:squid cache.log
#touch page_zs_access_log
#chmod 755 page_zs_access_log
#chown squid:squid page_zs_access_log
#cd /usr/local/squid/etc/
# > squid.conf
# vi squid.conf(211.**.**.**为服务器的ip地址)
visible_hostname www.abc.com
http_port 80 vhost vport
cache_mem 512 MB
maximum_object_size_in_memory 2048 KB
memory_replacement_policy lru
cache_dir ufs /tmp 512 16 256
max_open_disk_fds 0
minimum_object_size 0 KB
maximum_object_size 32768 KB
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
access_log /usr/local/squid/var/logs/page_zs_access_log combined
pid_filename /usr/local/squid/var/logs/squid.pid
cache_store_log none
cache_peer 211.**.**.** parent 81 0 no-query no-digest originserver name=www
cache_peer_domain www www.abc.com
cache_peer_access www allow all
http_access allow all
acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
cache deny QUERY
cache_effective_user squid
cache_effective_group squid
#/usr/local/squid/sbin/squid -k parse
可以根据这个测试命令用来验证squid.conf的语法和配置(下面是OK的如果不OK会有相应的提示根据提示来修改配置文件)
2008/03/19 15:29:48| Processing Configuration File: /usr/local/squid/etc/squid.conf (depth 0)
#/usr/local/squid/sbin/squid -z
用来Creating Swap Directories
vi一个squid.sh的启动脚本如下:赋予可执行权限
#!/bin/sh
#
ulimit -HSn 15000
# this script starts and stops Squid
echo 15000 > /proc/sys/fs/file-max
case "$1" in
start)
/usr/local/squid/sbin/squid -s
echo -n ' Squid'
;;
stop)
/usr/local/squid/sbin/squid -k shutdown
;;
esac
#./squid.sh start就可以启动squid了(还有测试命令如:/usr/local/squid/sbin/squid -CNd1参考下)
查看有没有启动可以
#ps fax|grep squid
13750 pts/3 S+ 0:00 \_ grep squid
30474 ? Ss 0:00 /usr/local/squid/sbin/squid -s
30476 ? S 0:01 \_ (squid) -s
则证明OK
通过命令lsof -i:80查看谁占用了80端口
[root@www ~]# more /usr/local/squid/var/logs/page_zs_access_log |grep TCP_MEM_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到内存中,并返回给访问用户
219.147.203.146 - - [19/Mar/2008 14:48:54] "GET http://www.abc.com/images/ckt/chuank_11.gif HTTP/1.1" 200 1100 "http://www.abc.com/post.do?m=show&id=35558" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" TCP_MEM_HIT:NONE
[root@www ~]# more /usr/local/squid/var/logs/page_zs_access_log |grep TCP_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到cache目录中,并返回给访问用户
124.64.41.91 - - [19/Mar/2008 15:49:09] "GET http://www.abc.com/products/big/1647/0803/20080319020212_289.jpg HTTP/1.1" 200 65589 "http://www.abc.com/manager.production.do?p_cid=13" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" TCP_HIT:NONE
[root@www ~]# more /usr/local/squid/var/logs/page_zs_access_log |grep TCP_MISS
该指令可以看到在squid运行过程中,有那些文件没有被squid缓存,而是现重原始服务器获取并返回给访问用户
220.181.38.190 - - [17/Mar/2008:17:23:34 +0800] "GET http://www.abc.com/post.do?pcid=198 HTTP/1.1" 200 25162 "-" "Baiduspider+(+http://www.baidu.com/search/spider.htm)" TCP_MISS:DIRECT
可以查看下命中率及其他相关信息
#/usr/local/squid/bin/squidclient -p 80 -h localhost mgr:info
[root@www ~]# /usr/local/squid/bin/squidclient -p 80 -h localhost mgr:info
HTTP/1.0 200 OK
Server: squid/3.0.STABLE2
Mime-Version: 1.0
Date: Wed, 19 Mar 2008 07:37:22 GMT
Content-Type: text/plain
Expires: Wed, 19 Mar 2008 07:37:22 GMT
Last-Modified: Wed, 19 Mar 2008 07:37:22 GMT
X-Cache: MISS from www.abc.com
Via: 1.0 www.abc.com (squid/3.0.STABLE2)
Connection: close
Squid Object Cache: Version 3.0.STABLE2
Start Time: Wed, 19 Mar 2008 06:47:32 GMT
Current Time: Wed, 19 Mar 2008 07:37:22 GMT
Connection information for squid:
Number of clients accessing cache: 244
Number of HTTP requests received: 30303
Number of ICP messages received: 0
Number of ICP messages sent: 0
Number of queued ICP replies: 0
Number of HTCP messages received: 0
Number of HTCP messages sent: 0
Request failure ratio: 0.00
Average HTTP requests per minute since start: 608.2
Average ICP messages per minute since start: 0.0
Select loop called: 532175 times, 5.617 ms avg
Cache information for squid:
Hits as % of all requests: 5min: 90.3%, 60min: 75.5%
Hits as % of bytes sent: 5min: 31.8%, 60min: 45.4%
Memory hits as % of hit requests: 5min: 6.1%, 60min: 32.8%
Disk hits as % of hit requests: 5min: 0.0%, 60min: 0.1%
Storage Swap size: 35624 KB
Storage Swap capacity: 6.8% used, 93.2% free
Storage Mem size: 37232 KB
Storage Mem capacity: 7.1% used, 92.9% free
Mean Object Size: 21.38 KB
Requests given to unlinkd: 418
Median Service Times (seconds) 5 min 60 min:
HTTP Requests (All): 0.00000 0.00000
Cache Misses: 0.07409 0.00000
Cache Hits: 0.00000 0.00000
Near Hits: 0.00000 0.00000
Not-Modified Replies: 0.00000 0.00000
DNS Lookups: 0.00000 0.00000
ICP Queries: 0.00000 0.00000
Resource usage for squid:
UP Time: 2989.216 seconds
CPU Time: 1.396 seconds
CPU Usage: 0.05%
CPU Usage, 5 minute avg: 0.05%
CPU Usage, 60 minute avg: 0.05%
Process Data Segment Size via sbrk(): 8044 KB
Maximum Resident Size: 0 KB
Page faults with physical i/o: 1
Memory usage for squid via mallinfo():
Total space in arena: 8312 KB
Ordinary blocks: 8283 KB 19 blks
Small blocks: 0 KB 0 blks
Holding blocks: 48028 KB 306 blks
Free Small blocks: 0 KB
Free Ordinary blocks: 28 KB
Total in use: 56311 KB 100%
Total free: 28 KB 0%
Total size: 56340 KB
Memory accounted for:
Total accounted: 44495 KB 79%
memPool accounted: 44495 KB 79%
memPool unaccounted: 11844 KB 21%
memPoolAlloc calls: 5319189
memPoolFree calls: 5198329
File descriptor usage for squid:
Maximum number of file descriptors: 15000
Largest file desc currently in use: 61
Number of file desc currently in use: 37
Files queued for open: 0
Available number of file descriptors: 14963
Reserved number of file descriptors: 100
Store Disk files open: 0
Internal Data Structures:
3412 StoreEntries
3402 StoreEntries with MemObjects
3401 Hot Object Cache Items
1666 on-disk objects
[root@www ~]# /usr/local/squid/bin/squidclient -p 80 -h localhost mgr:info
HTTP/1.0 200 OK
Server: squid/3.0.STABLE2
Mime-Version: 1.0
Date: Wed, 19 Mar 2008 07:45:48 GMT
Content-Type: text/plain
Expires: Wed, 19 Mar 2008 07:45:48 GMT
Last-Modified: Wed, 19 Mar 2008 07:45:48 GMT
X-Cache: MISS from www.abc.com
Via: 1.0 www.abc.com (squid/3.0.STABLE2)
Connection: close
Squid Object Cache: Version 3.0.STABLE2
Start Time: Wed, 19 Mar 2008 06:47:32 GMT
Current Time: Wed, 19 Mar 2008 07:45:48 GMT
Connection information for squid:
Number of clients accessing cache: 173
Number of HTTP requests received: 36309
Number of ICP messages received: 0
Number of ICP messages sent: 0
Number of queued ICP replies: 0
Number of HTCP messages received: 0
Number of HTCP messages sent: 0
Request failure ratio: 0.00
Average HTTP requests per minute since start: 623.2
Average ICP messages per minute since start: 0.0
Select loop called: 633105 times, 5.522 ms avg
Cache information for squid:
Hits as % of all requests: 5min: 87.9%, 60min: 77.5%
Hits as % of bytes sent: 5min: 25.9%, 60min: 42.0%
Memory hits as % of hit requests: 5min: 7.8%, 60min: 27.8%
Disk hits as % of hit requests: 5min: 0.0%, 60min: 0.1%
Storage Swap size: 42468 KB
Storage Swap capacity: 8.1% used, 91.9% free
Storage Mem size: 45360 KB
Storage Mem capacity: 8.7% used, 91.3% free
Mean Object Size: 22.40 KB
Requests given to unlinkd: 513
Median Service Times (seconds) 5 min 60 min:
HTTP Requests (All): 0.00000 0.00000
Cache Misses: 0.08265 0.00091
Cache Hits: 0.00000 0.00000
Near Hits: 0.00000 0.00000
Not-Modified Replies: 0.00000 0.00000
DNS Lookups: 0.00000 0.00000
ICP Queries: 0.00000 0.00000
Resource usage for squid:
UP Time: 3496.007 seconds
CPU Time: 1.644 seconds
CPU Usage: 0.05%
CPU Usage, 5 minute avg: 0.06%
CPU Usage, 60 minute avg: 0.05%
Process Data Segment Size via sbrk(): 8580 KB
Maximum Resident Size: 0 KB
Page faults with physical i/o: 1
Memory usage for squid via mallinfo():
Total space in arena: 8848 KB
Ordinary blocks: 8828 KB 72 blks
Small blocks: 0 KB 0 blks
Holding blocks: 57000 KB 372 blks
Free Small blocks: 0 KB
Free Ordinary blocks: 19 KB
Total in use: 65828 KB 100%
Total free: 19 KB 0%
Total size: 65848 KB
Memory accounted for:
Total accounted: 53423 KB 81%
memPool accounted: 53423 KB 81%
memPool unaccounted: 12424 KB 19%
memPoolAlloc calls: 6293795
memPoolFree calls: 6157879
File descriptor usage for squid:
Maximum number of file descriptors: 15000
Largest file desc currently in use: 155
Number of file desc currently in use: 149
Files queued for open: 0
Available number of file descriptors: 14851
Reserved number of file descriptors: 100
Store Disk files open: 22
Internal Data Structures:
3730 StoreEntries
3720 StoreEntries with MemObjects
3686 Hot Object Cache Items
1896 on-disk objects
自己的服务器是从2.5升级到3.0的所以这个文章想尽量写的完整些 可以还有不到之处 且配置文件很简单 未作优化 希望能帮助到有用的朋友
谢谢 老饭 咪姆の船长
参考:
http://bbs.chinaunix.net/thread-873126-1-1.html
http://bbs.chinaunix.net/thread-1067152-1-1.html
分享到:
相关推荐
通过以上步骤,便成功配置了一个基本的Squid反向代理服务器,实现了实验目的中的要求:对特定域名的请求进行代理,同时支持其他域名直接访问Web服务器。 ### 总结 本文档详细介绍了如何在RHEL5.5和Windows Server 2003...
|客户端|===>|负载均衡器 (Nginx)|===>|反向代理/缓存 (Squid)|===>|WEB服务器 (Apache, PHP)|==> |数据库服务器 (MySQL)| ``` 其中,各组件的作用如下: - **客户端**:发起请求。 - **负载均衡器 (Nginx)**:...
在集群中,Nginx通常作为前端的负载均衡器,通过正向代理策略分发请求到后端的Apache服务器,可以实现高效地处理大量并发请求,提高系统响应速度。 2. **Apache**:Apache是最流行的Web服务器之一,支持多种编程...
而squid则用作反向代理和缓存,进一步提高响应速度。 在开始搭建之前,确保拥有合适的硬件和软件环境。例如,这里使用的是双核Intel Xeon 3.00GHz服务器,2GB内存,CentOS 4.4操作系统,以及一系列预安装的软件版本...
加速器控制(`httpd_accel`)是反向代理的核心,确保Squid与Apache之间的协同工作。 最后,初始化缓存并启动Squid服务: ```bash /s/squid/sbin/squid -z /s/squid/etc/rc.d/squid.sh start ``` 对于Apache的配置,...
本次实验将涵盖 DNS 的安装配置、Squid 2.6 的安装配置以及 Apache Web 服务器的安装配置,并通过 Squid 实现对内网 Web 服务器的反向代理。 #### 实验环境配置 **1. 实验平台** - **RHEL1 (内网 Web 服务器):** ...
proxyServer squid / varnish / apache traffic server / ATS 这篇博文讨论了代理服务器的基本概念,并重点介绍了Squid、Varnish和Apache Traffic Server(ATS)这三种流行的代理缓存服务器软件。下面将详细阐述这些...
在构建高性能、高可用性的Web服务架构中,`LVS(负载均衡服务器)`、`Keepalived`、`Squid`(代理缓存服务器)和`Nginx`(反向代理服务器)是四个非常关键的组件。下面将详细介绍这四个技术及其相互配合的工作原理。 1. *...
nginx默认配置文件里面是没有进行日志转发配置的,这个需要我们自己手动来操作了,当然后端的...同样适用于前端是 Squid 或者其他反向代理的情况。 首先前端的 Nginx 要做转发客户端 IP 的配置: location / { proxy_p
Nginx则擅长处理静态内容和提供反向代理服务,它的特点是资源消耗低、性能高且稳定性好。在流量较大的场景下,通常采用Nginx作为前端服务器,负责静态文件和部分非PHP请求,而Apache则专注于处理PHP逻辑。Nginx与...
当Apache服务器无法应对当前的并发流量,且前端的Squid缓存服务器不能有效解决问题时,可以采用Nginx作为反向代理服务器来分发请求到Apache。Nginx对于动态页面的处理能力强,支持高效的反向代理功能,能够有效提高...
而Nginx和Squid的配合使用,则是为了利用它们各自的优势,例如Nginx的反向代理、静态文件处理能力,以及Squid的缓存机制,共同构建出更强大的Web服务解决方案。 【标签】"nginx apache squid"这三个标签分别代表了...
nginx以其高稳定性、低资源消耗和强大的反向代理功能而著名。 3. **MySQL数据库**:MySQL是一款高效的开源关系型数据库管理系统,常用于存储网站的数据。对于高并发读写需求,可以考虑采用数据库缓存技术,如使用...
在我工作的某个时候,我不得不配置一个有效的 Squid(或另一个反向缓存代理)设置,在 Geoserver 前面缓存动态 WMS-C 查询。 不幸的是,当时我找不到任何好的指南,因此我决定将所需的所有内容都放在一个存储库中...
因此想使用Nginx反向代理apache.整个配置安装过程很简单.在考虑高并发的情况下,在安装前就做了些优化.目前配置能抗住3000以上并发.好像不是特别大哦?呵~~ 但足以~~ 只是还有少量499问题..期待有人跟我讨论解决. 第1...
- squid + Apache + PHP + eAccelerator:通过 squid 作为反向代理,加速静态内容的分发,Apache 处理动态请求,eAccelerator 提供PHP性能优化。 - nginx/Apache + PHP(fastcgi) + eAccelerator:使用 Nginx 或 ...
因此想使用nginx做为反向代理apache.整个配置安装过程很简单.在考虑高并发的情况下,在安装前就做了些优化.目前配置能抗住3000以上并发.好像不是特别大哦?呵~~ 但足以~~ 只是还有少量499问题..期待有人跟我讨论解决 ...
在varnish、squid、apache和nginx这四个选项中,每种都有其独特的特性和适用场景。 首先,Varnish和Squid是专门设计为缓存服务器的。Varnish以其高效的“Visual Page Cache”技术著称,它优化了内存管理,避免了...