高性能web应用的基本系统结构:
a)       基本结构:
负载均衡=>反向代理=>静态内容缓存=>静态内容=>动态应用加速=>动态应用=>数据缓存=>数据存储=>分布式应用
b)       负载均衡:负载均衡(Load Balance)建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽、增加吞吐量、加强网络数据处理能力、提高网络的灵活性和可用性,避免了网络关键部位出现单点失效。
i.              负载均衡有两方面的含义:
1.       首先,大量的并发访问或数据流量分担到多台节点设备上分别处理,减少用户等待响应的时间;
2.       其次,单个重负载的运算分担到多台节点设备上做并行处理,每个节点设备处理结束后,将结果汇总,返回给用户,系统处理能力得到大幅度提高。
ii.              常见的负载均衡方法:
1.       DNS轮询:适合静态内容的简单均衡机制;
2.       智能DNS:在广域网中,对适合分布的静态内容可以做到智能判断用户来源,提供最近的Cache分发服务器方便用户就近高速访问;
3.       反向代理:将外部请求转发给内部的多台服务器,从而达到负载均衡的目的;同时可以将负载均衡和高速缓存结合在一起,提高性能;随着并发连接数量的增加,代理服务器本身的负载也变得非常大,最后反向代理服务器本身会成为服务的瓶颈。
4.       四层交换:
5.       内容交换(七层交换/URL交换):
a)       在HTTP请求和报头中有很多对负载均衡有用的信息。可以从这些信息中获知客户端所请求的URL和网页,负载均衡设备就可以将 所有的图像请求引导到一个图像服务器,或者根据URL的数据库查询内容调用CGI程序,将请求引导到一个专用的高性能数据库服务器。
b)       可以根据HTTP报头的cookie字段来使用Web内容交换技术改善对特定客户的服务;
c)       如果能从HTTP请求中找到一些规律,还可以充分利用它作出各种决策;
d)       除了TCP连接表的问题外,如何查找合适的HTTP报头信息以及作出负载平衡决策的过程,是影响Web内容交换技术性能的重要 问题。如果Web服务器已经为图像服务、SSL对话、数据库事务服务之类的特殊功能进行了优化,那么采用这个层次的流量控制将可以提高网络的性能。
c)       反向代理:(并入负载均衡一节)
d)       静态内容缓存:通常与反向代理合并在一起,提供静态内容(HTML页面,图片,js脚本,css文件等等)缓存。
e)       静态内容:CMS、Blog、Wiki等静态化应用。
f)       动态应用加速:利用Apache的MPM模式或者Zend、eAccelarator等加速引擎为动态应用加速。
g)       动态应用:网站核心功能SNS、交友、互动等等。
h)       数据缓存:memcached。
i)       数据存储:内存、磁盘文件或者数据库。
j)       分布式应用:分布式文件存储、数据库集群。
三、系统方案:整体方案采用开源产品,平台选用RHEL4up3(32bit/64bit)
a)       整体结构:
负载均衡=>反向代理=>静态内容缓存=>静态内容=>动态应用加速=>动态应用=>数据缓存=>数据存储=>分布式应用
NginX=>Squid=>Apache=>eAccelerator=>PHP=>memcached=>MySQL=>MogileFS/ICE
b)       平台:
i.              服务器: Intel(R) Xeon(TM) CPU 3.00GHz * 2, 2GB mem, SCISC 硬盘
ii.              操作系统:Linux RHEL 4 up3,内核版本2.6.9-22.ELsmp,gcc版本3.4.4
iii.              软件:
1.       Apache 2.2.3(使用MPM模式)
2.       PHP 5.2.0(5.2.0的引擎更高效)
3.       eAccelerator 0.9.5(加速PHP引擎,同时也可以加密PHP源程序)
4.       memcached 1.2.0(用于高速缓存常用数据)
5.       libevent 1.2a(memcached工作机制所需)
6.       MySQL 5.0.27(选用二进制版本,省去编译工作,有条件时用源码编译)
7.       Nginx 0.5.4(用做负载均衡器)
8.       squid-2.6.STABLE6(做反向代理的同时提供静态缓存功能)
c)       安装过程:
i.              安装Nginx:Nginx发音为[engine x],是由俄罗 斯人Igor Sysoev建立的项目,基于BSD许可。据说他当初是F5的成员之一,英文主页:http://nginx.net。俄罗斯的一些大网站 已经使用它超过两年多了,一直表现不凡。Nginx的编译参数如下:
1.        [root@localhost]#./configure –prefix=/usr/local/server/nginx –with-openssl=/usr/include \
–with-pcre=/usr/include/pcre/ –with-http_stub_status_module –without-http_memcached_module \
–without-http_fastcgi_module –without-http_rewrite_module –without-http_map_module \
–without-http_geo_module –without-http_autoindex_module
2.       在这里,需要说明一下,由于Nginx的配置文件中用到正则,所以需要 pcre 模块的支持。需要事先安装 pcre 及  pcre-devel 的rpm包,但是 Ngxin 并不能正确找到 .h/.so/.a/.la 文件,因此稍微变通了一下:
[root@localhost]#mkdir /usr/include/pcre/.libs/
[root@localhost]#cp /usr/lib/libpcre.a /usr/include/pcre/.libs/libpcre.a
[root@localhost]#cp /usr/lib/libpcre.a /usr/include/pcre/.libs/libpcre.la
3.       然后,修改 objs/Makefile 大概在908行的位置上,注释掉以下内容:
./configure –disable-shared
4.       接下来,就可以正常执行 make 及 make install 了。
ii.              修改NginX配置文件 /usr/local/server/nginx/conf/nginx.conf
以下的 nginx.conf 内容,仅供参考:
1.        #运行用户
2.        user nobody nobody;
3.
4.        #启动进程
5.        worker_processes 2;
6.
7.        #全局错误日志及PID文件
8.        error_log logs/error.log notice;
9.        pid        logs/nginx.pid;
10.
11.     #工作模式及连接数上限
12.     events {
13.             use epoll;
14.             worker_connections      1024;
15.     }
16.
17.     #设定http服务器,利用它的反向代理功能提供负载均衡支持
18.     http {
19.             #设定mime类型
20.             include       conf/mime.types;
21.             default_type application/octet-stream;
22.
23.             #设定日志格式
24.             log_format main         ’$remote_addr - $remote_user [$time_local] ’
25.                                                     ’”$request” $status $bytes_sent ’
26.                                                     ’”$http_referer” ”$http_user_agent” ’
27.                                                     ’”$gzip_ratio”‘;
28.
29.             log_format download ’$remote_addr - $remote_user [$time_local] ’
30.                                                     ’”$request” $status $bytes_sent ’
31.                                                     ’”$http_referer” ”$http_user_agent” ’
32.                                                     ’”$http_range” ”$sent_http_content_range”‘;
33.
34.             #设定请求缓冲
35.             client_header_buffer_size    1k;
36.             large_client_header_buffers 4 4k;
37.
38.             #开启gzip模块
39.             gzip on;
40.             gzip_min_length 1100;
41.             gzip_buffers     4 8k;
42.             gzip_types       text/plain;
43.
44.             output_buffers   1 32k;
45.             postpone_output 1460;
46.
47.             #设定access log
48.             access_log logs/access.log main;
49.
50.             client_header_timeout 3m;
51.             client_body_timeout    3m;
52.             send_timeout           3m;
53.
54.             sendfile                on;
55.             tcp_nopush              on;
56.             tcp_nodelay             on;
57.
58.             keepalive_timeout 65;
59.
60.             #设定负载均衡的服务器列表
61.             upstream mysvr {
62.                     #weigth参数表示权值,权值越高被分配到的几率越大
63.                     #本机上的Squid开启3128端口
64.                     server 192.168.8.1:3128 weight=5;
65.                     server 192.168.8.2:80   weight=1;
66.                     server 192.168.8.3:80   weight=6;
67.             }
68.
69.             #设定虚拟主机
70.             server {
71.                     listen          80;
72.                     server_name     192.168.8.1 www.yejr.com;
73.
74.                     charset gb2312;
75.
76.                     #设定本虚拟主机的访问日志
77.                     access_log logs/www.yejr.com.access.log main;
78.
79.                     #如果访问 /img/*, /js/*, /css/* 资源,则直接取本地文件,不通过squid
80.                     #如果这些文件较多,不推荐这种方式,因为通过squid的缓存效果更好
81.                     location ~ ^/(img|js|css)/ {
82.                             root    /data3/Html;
83.                             expires 24h;
84.                     }
85.
86.                     #对 ”/” 启用负载均衡
87.                     location / {
88.                             proxy_pass      http://mysvr;
89.
90.                             proxy_redirect          off;
91.                             proxy_set_header        Host $host;
92.                             proxy_set_header        X-Real-IP $remote_addr;
93.                             proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
94.                             client_max_body_size    10m;
95.                             client_body_buffer_size 128k;
96.                             proxy_connect_timeout   90;
97.                             proxy_send_timeout      90;
98.                             proxy_read_timeout      90;
99.                             proxy_buffer_size       4k;
100.                         proxy_buffers           4 32k;
101.                         proxy_busy_buffers_size 64k;
102.                         proxy_temp_file_write_size 64k;
103.                 }
104.
105.                 #设定查看Nginx状态的地址
106.                 location /NginxStatus {
107.                         stub_status             on;
108.                         access_log              on;
109.                         auth_basic              ”NginxStatus”;
110.                         auth_basic_user_file conf/htpasswd;
111.                 }
112.         }
113. }
iii.              运行以下命令检测配置文件是否无误:
/usr/local/server/nginx/sbin/nginx –t
1.        执行以下命令开始运行Nginx:
usr/local/server/nginx/sbin/nginx
2.        备注:conf/htpasswd 文件的内容用 apache 提供的 htpasswd 工具来产生即可,内容大致如下:
#帐号 yejr,密码 123456
yejr:qLYyJ0ZRLAId2
3.       查看 Nginx 运行状态
输入地址 http://192.168.8.1/NginxStatus/,输入验证帐号密码,即可看到类似如下内容:
Active connections: 328
server accepts handled requests
9309 8982 28890
Reading: 1 Writing: 3 Waiting: 324
第一行表示目前活跃的连接数
第三行的第三个数字表示Nginx运行到当前时间接受到的总请求数,如果快达到了上限,就需要加大上限值了。
第四行看不懂 sad.gif
iv.              安装MySQL,步骤如下:
1.        [root@localhost]#tar zxf mysql-standard-5.0.27-linux-i686.tar.gz -C /usr/local/server
2.        [root@localhost]#mv /usr/local/server/mysql-standard-5.0.27-linux-i686 /usr/local/server/mysql
3.        [root@localhost]#cd /usr/local/server/mysql
4.        [root@localhost]#./scripts/mysql_install_db –basedir=/usr/local/server/mysql \
5.                     –datadir=/usr/local/server/mysql/data –user=nobody
6.        [root@localhost]#cp /usr/local/server/mysql/support-files/my-large.cnf \
7.        /usr/local/server/mysql/data/my.cnf
v.              修改 MySQL 配置,增加部分优化参数
1.        [root@localhost]#vi /usr/local/server/mysql/data/my.cnf
2.        [mysqld]
3.        basedir = /usr/local/server/mysql
4.        datadir = /usr/local/server/mysql/data
5.        user    = nobody
6.        port    = 3306
7.        socket = /tmp/mysql.sock
8.
9.        wait_timeout    = 30
10.
11.     long_query_time=1
12.     #log-queries-not-using-indexes = TRUE
13.     log-slow-queries=/usr/local/server/mysql/slow.log
14.     log-error = /usr/local/server/mysql/error.log
15.     external-locking = FALSE
16.
17.     key_buffer_size = 512M
18.     back_log        = 400
19.     table_cache     = 512
20.     sort_buffer_size = 2M
21.     join_buffer_size = 4M
22.     read_buffer_size = 2M
23.     read_rnd_buffer_size    = 4M
24.     myisam_sort_buffer_size = 64M
25.     thread_cache_size       = 32
26.     query_cache_limit       = 2M
27.     query_cache_size        = 64M
28.
29.     thread_concurrency      = 4
30.     thread_stack    = 128K
31.     tmp_table_size = 64M
32.     binlog_cache_size       = 2M
33.     max_binlog_size = 128M
34.     max_binlog_cache_size   = 512M
35.     max_relay_log_size      = 128M
36.     bulk_insert_buffer_size = 8M
37.     myisam_repair_threads   = 1
38.
39.     skip-bdb
40.
41.     #如果不需要使用innodb就关闭该选项
42.     #skip-innodb
43.
44.     innodb_data_home_dir    = /usr/local/server/mysql/data/
45.     innodb_data_file_path   = ibdata1:256M;ibdata2:256M:autoextend
46.     innodb_log_group_home_dir       = /usr/local/server/mysql/data/
47.     innodb_log_arch_dir     = /usr/local/server/mysql/data/
48.     innodb_buffer_pool_size = 512M
49.     innodb_additional_mem_pool_size = 8M
50.     innodb_log_file_size    = 128M
51.     innodb_log_buffer_size = 8M
52.     innodb_lock_wait_timeout        = 50
53.     innodb_flush_log_at_trx_commit = 2
54.     innodb_file_io_threads = 4
55.     innodb_thread_concurrency       = 16
56.     innodb_log_files_in_group       = 3
vi.              启动 MySQL 服务器
/usr/local/server/mysql/bin/mysqld_safe \
–defaults-file=/usr/local/server/mysql/data/my.cnf &
vii.              由于 MySQL 不是安装在标准目录下,因此必须要修改  mysqld_safe 中的 my_print_defaults 文件所在位置,才能通过 mysqld_safe 来启动 MySQL 服务器。
viii.              memcache + libevent 安装
1.        [root@localhost]#cd libevent-1.2a
2.        [root@localhost]#./configure –prefix=/usr/ && make && make install
3.        [root@localhost]#cd ../memcached-1.2.0
4.        [root@localhost]#./configure –prefix=/usr/local/server/memcached –with-libevent=/usr/
5.        [root@localhost]#make && make install
6.        备注:如果 libevent 不是安装在 /usr 目录下,那么需要把 libevent-1.2a.so.1 拷贝/链接到 /usr/lib 中,否则 memcached 无法正常加载。
ix.              运行以下命令来启动 memcached:
1.        [root@localhost]#/usr/local/server/memcached/bin/memcached \
-l 192.168.8.1 -d -p 10000 -u nobody -m 128
2.        表示用 daemon 的方式启动 memcached,监听在 192.168.8.1 的 10000 端口上,运行用户为 nobody,为其分配 128MB 的内存。
x.              安装Apache、PHP、eAccelerator、php-memcache,由于Apache 2下的php静态方式编译十分麻烦,因此在这里采用动态模块(DSO)方式。
xi.              安装Apache 2.2.3
1.        [root@localhost]#./configure –prefix=/usr/local/server/apache –disable-userdir –disable-actions \
2.        –disable-negotiation –disable-autoindex –disable-filter –disable-include –disable-status \
3.        –disable-asis –disable-auth –disable-authn-default –disable-authn-file –disable-authz-groupfile \
4.        –disable-authz-host –disable-authz-default –disable-authz-user –disable-userdir \
5.        –enable-expires –enable-module=so
6.        备注:在这里,取消了一些不必要的模块,如果你需要用到这些模块,那么请去掉部分参数。
xii.              安装PHP 5.2.0
1.        [root@localhost]#./configure –prefix=/usr/local/server/php –with-mysql \
2.        –with-apxs2=/usr/local/server/apache/bin/apxs –with-freetype-dir=/usr/ –with-png-dir=/usr/ \
3.        –with-gd=/usr/ –with-jpeg-dir=/usr/ –with-zlib –enable-magic-quotes –with-iconv \
4.        –without-sqlite –without-pdo-sqlite –with-pdo-mysql –disable-dom –disable-simplexml \
5.        –enable-roxen-zts
6.        [root@localhost]#make && make install
7.        备注:如果不需要gd或者pdo等模块,请自行去掉。
xiii.              安装eAccelerator-0.9.5
1.        [root@localhost]#cd eAccelerator-0.9.5
2.        [root@localhost]#export PHP_PREFIX=/usr/local/server/php
3.        [root@localhost]#$PHP_PREFIX/bin/phpize
4.        [root@localhost]#./configure –enable-eaccelerator=shared –with-php-config=$PHP_PREFIX/bin/php-config
5.        [root@localhost]#make && make install
xiv.              4.) 安装memcache模块
1.        [root@localhost]#cd memcache-2.1.0
2.        [root@localhost]#export PHP_PREFIX=/usr/local/server/php
3.        [root@localhost]#$PHP_PREFIX/bin/phpize
4.        [root@localhost]#./configure –enable-eaccelerator=shared –with-php-config=$PHP_PREFIX/bin/php-config
5.        [root@localhost]#make && make install
xv.              5.) 修改 php.ini 配置,然后修改 php.ini,修改/加入类似以下内容:
1.        extension_dir = ”/usr/local/server/php/lib/”
2.
3.        extension=”eaccelerator.so”
4.        eaccelerator.shm_size=”32″      ;设定eaccelerator的共享内存为32MB
5.        eaccelerator.cache_dir=”/usr/local/server/eaccelerator”
6.        eaccelerator.enable=”1″
7.        eaccelerator.optimizer=”1″
8.        eaccelerator.check_mtime=”1″
9.        eaccelerator.debug=”0″
10.     eaccelerator.filter=”*.php”
11.     eaccelerator.shm_max=”0″
12.     eaccelerator.shm_ttl=”0″
13.     eaccelerator.shm_prune_period=”3600″
14.     eaccelerator.shm_only=”0″
15.     eaccelerator.compress=”1″
16.     eaccelerator.compress_level=”9″
17.     eaccelerator.log_file = ”/usr/local/server/apache/logs/eaccelerator_log”
18.     eaccelerator.allowed_admin_path = ”/usr/local/server/apache/htdocs/ea_admin”
19.
20.     extension=”memcache.so”
21.     在这里,最好是在apache的配置中增加默认文件类型的cache机制,即利用apache的expires模块,新增类似如下几行:
22.     ExpiresActive On
23.     ExpiresByType text/html ”access plus 10 minutes”
24.     ExpiresByType text/css ”access plus 1 day”
25.     ExpiresByType image/jpg ”access 1 month”
26.     ExpiresByType image/gif ”access 1 month”
27.     ExpiresByType image/jpg ”access 1 month”
28.     ExpiresByType application/x-shockwave-flash ”access plus 3 day”
29.     这么设置是由于我的这些静态文件通常很少更新,因此我选择的是”access”规则,如果更新相对比较频繁,可以改用 “modification”规则;或者也可以用”access”规则,但是在文件更新的时候,执行一下”touch”命令,把文件的时间刷新一下即可。
xvi.              安装Squid
1.        [root@localhost]#./configure –prefix=/usr/local/server/squid –enable-async-io=100 –disable-delay-pools \
2.        –disable-mem-gen-trace –disable-useragent-log –enable-kill-parent-hack –disable-arp-acl \
3.        –enable-epoll –disable-ident-lookups –enable-snmp –enable-large-cache-files –with-large-files
4.        [root@localhost]#make && make install
5.        如果是2.6的内核,才能支持epoll的IO模式,旧版本的内核则只能选择poll或其他模式了;另外,记得带上支持大文件的选项,否则在access log等文件达到2G的时候就会报错。
xvii.              设定 squid 的配置大概如下内容:
1.        #设定缓存目录为 /var/cache1 和 /var/lib/squid,每次处理缓存大小为128MB,当缓存空间使用达到95%时
2.        #新的内容将取代旧的而不直接添加到目录中,直到空间又下降到90%才停止这一活动
3.        #/var/cache1 最大1024MB,/var/lib/squid 最大 5000MB,都是 16*256 级子目录
4.        cache_dir aufs /var/cache1 1024 16 256
5.        cache_dir aufs /var/lib/squid 5000 16 256
6.        cache_mem 128 MB
7.        cache_swap_low 90
8.        cache_swap_high 95
9.
10.     #设置存储策略等
11.     maximum_object_size 4096 KB
12.     minimum_object_size 0 KB
13.     maximum_object_size_in_memory 80 KB
14.     ipcache_size 1024
15.     ipcache_low 90
16.     ipcache_high 95
17.
18.     cache_replacement_policy lru
19.     memory_replacement_policy lru
20.
21.     #设置超时策略
22.     forward_timeout 20 seconds
23.     connect_timeout 15 seconds
24.     read_timeout 3 minutes
25.     request_timeout 1 minutes
26.     persistent_request_timeout 15 seconds
27.     client_lifetime 15 minutes
28.     shutdown_lifetime 5 seconds
29.     negative_ttl 10 seconds
30.
31.     #限制一个ip最大只能有16个连接
32.     acl OverConnLimit maxconn 16
33.     http_access deny OverConnLimit
34.
35.     #限制baidu spider访问
36.     #acl AntiBaidu req_header User-Agent Baiduspider
37.     #http_access deny AntiBaidu
38.
39.     #常规设置
40.     visible_hostname cache.yejr.com
41.     cache_mgr webmaster@yejr.com
42.     client_persistent_connections off
43.     server_persistent_connections on
44.
45.     cache_effective_user nobody
46.     cache_effective_group nobody
47.     tcp_recv_bufsize 65535 bytes
48.
49.     half_closed_clients off
50.
51.     #设定不缓存的规则
52.     hierarchy_stoplist cgi-bin
53.     acl QUERY urlpath_regex cgi-bin
54.     cache deny QUERY
55.
56.     #不要相信ETag 因为有gzip
57.     acl apache rep_header Server ^Apache
58.     broken_vary_encoding allow apache
59.
60.     #设置access log,并且令其格式和apache的格式一样,方便awstats分析
61.     emulate_httpd_log   on
62.     logformat apache %>a %ui %un [%tl] ”%rm %ru HTTP/%rv” %Hs %h” ”%{User-Agent}>h”
63.     access_log /usr/local/server/squid/var/logs/access.log apache
64.     cache_store_log none
65.
66.     #设置默认刷新规则
67.     refresh_pattern -i ^ftp:       1440    20% 10080
68.     refresh_pattern -i ^gopher:    1440    0% 1440
69.     refresh_pattern .       0   20% 4320
70.
71.     #设定访问规则
72.     acl all src 0.0.0.0/0.0.0.0
73.     acl manager proto cache_object
74.     acl localhost src 127.0.0.1/255.255.255.255 192.168.8.0/255.255.255.0
75.     acl to_localhost dst 127.0.0.0/8
76.     acl SSL_ports port 443
77.     acl Safe_ports port 80      # http
78.     acl Safe_ports port 443     # https
79.     acl CONNECT method CONNECT
80.
81.     http_access allow manager localhost
82.     http_access deny manager
83.     http_access deny !Safe_ports
84.     http_access deny CONNECT !SSL_ports
85.     icp_access allow all
86.     http_reply_access allow all
87.     http_access allow Safe_ports all
88.     http_access deny all
89.
90.     coredump_dir /usr/local/server/squid/var/cache
91.
92.     #设定icp规则,icp用于实现squid的cache共享
93.     icp_port 3030
94.     udp_incoming_address 192.168.8.83
95.     log_icp_queries on
96.
97.     #设定反向代理
98.     http_port 192.168.8.84:80 vhost vport
99.     cache_peer 192.168.8.84 parent 8080 0 no-query originserver name=web84
100. cache_peer_domain web84 www.yejr.com
101. cache_peer_domain web84 192.168.8.84
102.
103. #设定squid sibling(同级协作squid)
104. cache_peer 192.168.8.83 sibling 80 3030 proxy-only
105.
106. #设定snmp端口
107. snmp_port 3401
xviii.              初始化和启动squid
1.        [root@localhost]#/usr/local/server/squid/sbin/squid -z
2.        [root@localhost]#/usr/local/server/squid/sbin/squid
3.        第一条命令是先初始化squid缓存哈希子目录,只需执行一次即可。
xix.              启用squid所需的改变:想要更好的利用squid的cache功能,不是把它启用了就可以的,我们需要做以下几个调整:
1.        启用apache的 mod_expires 模块,修改 httpd.conf,加入以下内容:
a)        #expiresdefault ”modification plus 2 weeks”
b)        expiresactive on
c)        expiresbytype text/html ”access plus 10 minutes”
d)        expiresbytype image/gif ”modification plus 1 month”
e)        expiresbytype image/jpeg ”modification plus 1 month”
f)        expiresbytype image/png ”modification plus 1 month”
g)        expiresbytype text/css ”access plus 1 day”
h)        expiresbytype application/x-shockwave-flash ”access plus 3 day”
2.        以上配置的作用是规定各种类型文件的cache规则,对那些图片/flash等静态文件总是cache起来,可根据各自的需要做适当调整。
3.        修改 php.ini 配置,如下:
a)        session.cache_limiter = nocache
b)        以上配置的作用是默认取消php中的cache功能,避免不正常的cache产生。
4.        修改应用程序
a)        例如,有一个php程序页面
b)        static.php,它存放着某些查询数据库后的结果,并且数据更新并不频繁,于是,我们就可以考虑对其cache。只需在static.php中加入类似如下代码:
c)
d)        header(‘Cache-Control: max-age=86400 ,must-revalidate’);
e)        header(‘Pragma:’);
f)        header(‘Last-Modified: ’ . gmdate(‘D, d M Y H:i:s’) . ’ GMT’ wink.gif;
g)        header(“Expires: ” .gmdate (‘D, d M Y H:i:s’, time() + ’86400′ wink.gif. ’ GMT’);
h)
i)        以上代码的意思是,输出一个http头部信息,让squid知道本页面默认缓存时长为一天。
xx.              squidclient简要介绍
1.        *取得squid运行状态信息: squidclient -p 80 mgr:info
2.        *取得squid内存使用情况: squidclient -p 80 mgr:mem
3.        *取得squid已经缓存的列表: squidclient -p 80 mgrshocked.gifbjects. use it carefully, it may crash
4.        *取得squid的磁盘使用情况: squidclient -p 80 mgr:diskd
5.        *强制更新某个url: squidclient -p 80 -m PURGE http://www.yejr.com/static.php
6.        *更多的请查看:squidclient -h 或者 squidclient -p 80 mgr: