<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></title> 
<link>http://www.bizeway.net/index.php</link> 
<description><![CDATA[网务通 - 网务公司发展之路]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></copyright>
<item>
<link>http://www.bizeway.net/read.php?</link>
<title><![CDATA[跟ArthurXF探讨大型网站架构——学习篇3]]></title> 
<author>ArthurXF &lt;arthurxf@gmail.com&gt;</author>
<category><![CDATA[网站架构]]></category>
<pubDate>Sun, 05 Aug 2007 16:18:45 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?</guid> 
<description>
<![CDATA[ 
	　　这里我先转贴别人做的一个系统架构，这个架构还是很具有借鉴意义的。<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>服务器的大用户量的承载方案 -------作者：叶金荣 &nbsp;主页:http://www.imysql.cn<br/><br/>一、前言<br/><br/>[Copy to clipboard] [ - ]CODE:<br/>二、编译安装<br/>三、 安装MySQL、memcache<br/>四、 安装Apache、PHP、eAccelerator、php-memcache<br/>五、 安装Squid<br/>六、后记<br/><br/><br/><br/>一、前言<br/><br/>一、前言，准备工作<br/> &nbsp; &nbsp; &nbsp; 当前，LAMP开发模式是WEB开发的首选，如何搭建一个高效、可靠、稳定的WEB服务器一直是个热门主题，本文就是这个主题的一次尝试。<br/>我们采用的架构图如下：<br/><br/> &nbsp; -------- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ---------- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ------------- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --------- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ------------<br/>&#124; 客户端 &#124; ===> &#124;负载均衡器&#124; ===> &#124;反向代理/缓存&#124; ===> &#124;WEB服务器&#124; ===> &#124;数据库服务器&#124;<br/> &nbsp; -------- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ---------- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ------------- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --------- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ------------<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Nginx &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Squid &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Apache,PHP &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MySQL<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; eAccelerator/memcache<br/>准备工作：<br/>服务器： Intel(R) Xeon(TM) CPU 3.00GHz * 2, 2GB mem, SCISC 硬盘<br/>操作系统：CentOs4.4，内核版本2.6.9-22.ELsmp，gcc版本3.4.4<br/>软件：<br/>Apache 2.2.3（能使用MPM模式）<br/>PHP 5.2.0（选用该版本是因为5.2.0的引擎相对更高效）<br/>eAccelerator 0.9.5（加速PHP引擎，同时也可以加密PHP源程序）<br/>memcache 1.2.0（用于高速缓存常用数据）<br/>libevent 1.2a（memcache工作机制所需）<br/>MySQL 5.0.27（选用二进制版本，省去编译工作）<br/>Nginx 0.5.4（用做负载均衡器）<br/>squid-2.6.STABLE6（做反向代理的同时提供专业缓存功能）<br/><br/>二、编译安装<br/>二、编译安装<br/>一、) 安装Nginx<br/>1.) 安装<br/>Nginx发音为[engine x]，是由俄罗斯人Igor Sysoev建立的项目,基于BSD许可。据说他当初是F5的成员之一，英文主页：<a href="http://nginx.net" target="_blank">http://nginx.net</a>。俄罗斯的一些大网站已经使用它超过两年多了，一直表现不凡。<br/>Nginx的编译参数如下：<br/><br/><div class="code">&#91;root@localhost&#93;#./configure --prefix=/usr/local/server/nginx --with-openssl=/usr/include &#92;<br/>--with-pcre=/usr/include/pcre/ --with-http_stub_status_module --without-http_memcached_module &#92;<br/>--without-http_fastcgi_module --without-http_rewrite_module --without-http_map_module &#92;<br/>--without-http_geo_module --without-http_autoindex_module<br/>在这里，需要说明一下，由于Nginx的配置文件中我想用到正则，所以需要 pcre 模块的支持。我已经安装了 pcre 及 pcre-devel 的rpm包，但是 Ngxin 并不能正确找到 .h/.so/.a/.la 文件，因此我稍微变通了一下：<br/><br/>&#91;Copy to clipboard&#93; &#91; - &#93;CODE:<br/>&#91;root@localhost&#93;#mkdir /usr/include/pcre/.libs/<br/>&#91;root@localhost&#93;#cp /usr/lib/libpcre.a /usr/include/pcre/.libs/libpcre.a<br/>&#91;root@localhost&#93;#cp /usr/lib/libpcre.a /usr/include/pcre/.libs/libpcre.la<br/>然后，修改 objs/Makefile 大概在908行的位置上，注释掉以下内容：<br/><br/>./configure --disable-shared<br/>接下来，就可以正常执行 make 及 make install 了。<br/><br/>2.) 修改配置文件 /usr/local/server/nginx/conf/nginx.conf<br/>以下是我的 nginx.conf 内容，仅供参考：<br/><br/>&#91;Copy to clipboard&#93; &#91; - &#93;CODE:<br/>#运行用户<br/>user &nbsp; nobody nobody;<br/>#启动进程<br/>worker_processes &nbsp; 2;<br/>#全局错误日志及PID文件<br/>error_log &nbsp; logs/error.log notice;<br/>pid &nbsp; &nbsp; &nbsp; &nbsp; logs/nginx.pid;<br/>#工作模式及连接数上限<br/>events {<br/>use epoll;<br/>worker_connections &nbsp; &nbsp; &nbsp; 1024;<br/>}<br/>#设定http服务器，利用它的反向代理功能提供负载均衡支持<br/>http {<br/>#设定mime类型<br/>include &nbsp; &nbsp; &nbsp; conf/mime.types;<br/>default_type &nbsp; application/octet-stream;<br/>#设定日志格式<br/>log_format main &nbsp; &nbsp; &nbsp; &nbsp; &#039;$remote_addr - $remote_user &#91;$time_local&#93; &#039;<br/>&#039;&quot;$request&quot; $status $bytes_sent &#039;<br/>&#039;&quot;$http_referer&quot; &quot;$http_user_agent&quot; &#039;<br/>&#039;&quot;$gzip_ratio&quot;&#039;;<br/>log_format download &#039;$remote_addr - $remote_user &#91;$time_local&#93; &#039;<br/>&#039;&quot;$request&quot; $status $bytes_sent &#039;<br/>&#039;&quot;$http_referer&quot; &quot;$http_user_agent&quot; &#039;<br/>&#039;&quot;$http_range&quot; &quot;$sent_http_content_range&quot;&#039;;<br/>#设定请求缓冲<br/>client_header_buffer_size &nbsp; &nbsp; 1k;<br/>large_client_header_buffers &nbsp; 4 4k;<br/>#开启gzip模块<br/>gzip on;<br/>gzip_min_length &nbsp; 1100;<br/>gzip_buffers &nbsp; &nbsp; 4 8k;<br/>gzip_types &nbsp; &nbsp; &nbsp; text/plain;<br/>output_buffers &nbsp; 1 32k;<br/>postpone_output &nbsp; 1460;<br/>#设定access log<br/>access_log &nbsp; logs/access.log &nbsp; main;<br/>client_header_timeout &nbsp; 3m;<br/>client_body_timeout &nbsp; &nbsp; 3m;<br/>send_timeout &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3m;<br/>sendfile &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on;<br/>tcp_nopush &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on;<br/>tcp_nodelay &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on;<br/>keepalive_timeout &nbsp; 65;<br/>#设定负载均衡的服务器列表<br/>upstream mysvr {<br/>#weigth参数表示权值，权值越高被分配到的几率越大<br/>#本机上的Squid开启3128端口<br/>server 192.168.8.1:3128 weight=5;<br/>server 192.168.8.2:80 &nbsp; weight=1;<br/>server 192.168.8.3:80 &nbsp; weight=6;<br/>}<br/>#设定虚拟主机<br/>server {<br/>listen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 80;<br/>server_name &nbsp; &nbsp; 192.168.8.1 &#91;url&#93;www.yejr.com&#91;/url&#93;;<br/>charset gb2312;<br/>#设定本虚拟主机的访问日志<br/>access_log &nbsp; logs/www.yejr.com.access.log &nbsp; main;<br/>#如果访问 /img/*, /js/*, /css/* 资源，则直接取本地文件，不通过squid<br/>#如果这些文件较多，不推荐这种方式，因为通过squid的缓存效果更好<br/>location ~ ^/(img&#124;js&#124;css)/ &nbsp; {<br/>root &nbsp; &nbsp; /data3/Html;<br/>expires 24h;<br/>}<br/>#对 &quot;/&quot; 启用负载均衡<br/>location / {<br/>proxy_pass &nbsp; &nbsp; &nbsp;http://mysvr;<br/>proxy_redirect &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; off;<br/>proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp; Host $host;<br/>proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp; X-Real-IP $remote_addr;<br/>proxy_set_header &nbsp; &nbsp; &nbsp; &nbsp; X-Forwarded-For $proxy_add_x_forwarded_for;<br/>client_max_body_size &nbsp; &nbsp; 10m;<br/>client_body_buffer_size 128k;<br/>proxy_connect_timeout &nbsp; 90;<br/>proxy_send_timeout &nbsp; &nbsp; &nbsp; 90;<br/>proxy_read_timeout &nbsp; &nbsp; &nbsp; 90;<br/>proxy_buffer_size &nbsp; &nbsp; &nbsp; 4k;<br/>proxy_buffers &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4 32k;<br/>proxy_busy_buffers_size 64k;<br/>proxy_temp_file_write_size 64k;<br/>}<br/>#设定查看Nginx状态的地址<br/>location /NginxStatus {<br/>stub_status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on;<br/>access_log &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on;<br/>auth_basic &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;NginxStatus&quot;;<br/>auth_basic_user_file &nbsp; conf/htpasswd;<br/>}<br/>}<br/>}<br/>备注：conf/htpasswd 文件的内容用 apache 提供的 htpasswd 工具来产生即可，内容大致如下：<br/> &nbsp; 3.) 查看 Nginx 运行状态<br/>输入地址 http://192.168.8.1/NginxStatus/，输入验证帐号密码，即可看到类似如下内容：<br/>Active connections: 328<br/>server accepts handled requests<br/>9309 &nbsp; &nbsp; 8982 &nbsp; &nbsp; &nbsp; &nbsp; 28890<br/>Reading: 1 Writing: 3 Waiting: 324<br/><br/>第一行表示目前活跃的连接数<br/>第三行的第三个数字表示Nginx运行到当前时间接受到的总请求数，如果快达到了上限，就需要加大上限值了。<br/>第四行是Nginx的队列状态<br/><br/>三、 安装MySQL、memcache<br/><br/><br/><br/>1.) 安装MySQL，步骤如下：<br/><br/>&#91;Copy to clipboard&#93; &#91; - &#93;CODE:<br/>&#91;root@localhost&#93;#tar zxf mysql-standard-5.0.27-linux-i686.tar.gz -C /usr/local/server<br/>&#91;root@localhost&#93;#mv /usr/local/server/mysql-standard-5.0.27-linux-i686 /usr/local/server/mysql<br/>&#91;root@localhost&#93;#cd /usr/local/server/mysql<br/>&#91;root@localhost&#93;#./scripts/mysql_install_db --basedir=/usr/local/server/mysql &#92;<br/>--datadir=/usr/local/server/mysql/data --user=nobody<br/>&#91;root@localhost&#93;#cp /usr/local/server/mysql/support-files/my-large.cnf &#92;<br/>/usr/local/server/mysql/data/my.cnf<br/>2.) 修改 MySQL 配置，增加部分优化参数，如下：<br/>&#91;root@localhost&#93;#vi /usr/local/server/mysql/data/my.cnf<br/><br/>&#91;Copy to clipboard&#93; &#91; - &#93;CODE:<br/>主要内容如下：<br/>&#91;mysqld&#93;<br/>basedir = /usr/local/server/mysql<br/>datadir = /usr/local/server/mysql/data<br/>user &nbsp; &nbsp; = nobody<br/>port &nbsp; &nbsp; = 3306<br/>socket &nbsp; = /tmp/mysql.sock<br/>wait_timeout &nbsp; &nbsp; = 30<br/>long_query_time=1<br/>#log-queries-not-using-indexes = TRUE<br/>log-slow-queries=/usr/local/server/mysql/slow.log<br/>log-error = /usr/local/server/mysql/error.log<br/>external-locking = FALSE<br/>key_buffer_size = 512M<br/>back_log &nbsp; &nbsp; &nbsp; &nbsp; = 400<br/>table_cache &nbsp; &nbsp; = 512<br/>sort_buffer_size = 2M<br/>join_buffer_size = 4M<br/>read_buffer_size = 2M<br/>read_rnd_buffer_size &nbsp; &nbsp; = 4M<br/>myisam_sort_buffer_size = 64M<br/>thread_cache_size &nbsp; &nbsp; &nbsp; = 32<br/>query_cache_limit &nbsp; &nbsp; &nbsp; = 2M<br/>query_cache_size &nbsp; &nbsp; &nbsp; &nbsp; = 64M<br/>thread_concurrency &nbsp; &nbsp; &nbsp; = 4<br/>thread_stack &nbsp; &nbsp; = 128K<br/>tmp_table_size &nbsp; = 64M<br/>binlog_cache_size &nbsp; &nbsp; &nbsp; = 2M<br/>max_binlog_size = 128M<br/>max_binlog_cache_size &nbsp; = 512M<br/>max_relay_log_size &nbsp; &nbsp; &nbsp; = 128M<br/>bulk_insert_buffer_size = 8M<br/>myisam_repair_threads &nbsp; = 1<br/>skip-bdb<br/>#如果不需要使用innodb就关闭该选项<br/>#skip-innodb<br/>innodb_data_home_dir &nbsp; &nbsp; = /usr/local/server/mysql/data/<br/>innodb_data_file_path &nbsp; = ibdata1:256M;ibdata2:256M:autoextend<br/>innodb_log_group_home_dir &nbsp; &nbsp; &nbsp; = /usr/local/server/mysql/data/<br/>innodb_log_arch_dir &nbsp; &nbsp; = /usr/local/server/mysql/data/<br/>innodb_buffer_pool_size = 512M<br/>innodb_additional_mem_pool_size = 8M<br/>innodb_log_file_size &nbsp; &nbsp; = 128M<br/>innodb_log_buffer_size &nbsp; = 8M<br/>innodb_lock_wait_timeout &nbsp; &nbsp; &nbsp; &nbsp; = 50<br/>innodb_flush_log_at_trx_commit &nbsp; = 2<br/>innodb_file_io_threads &nbsp; = 4<br/>innodb_thread_concurrency &nbsp; &nbsp; &nbsp; = 16<br/>innodb_log_files_in_group &nbsp; &nbsp; &nbsp; = 3<br/>以上配置参数请根据具体的需要稍作修改。运行以下命令即可启动 MySQL 服务器：<br/>/usr/local/server/mysql/bin/mysqld_safe &#92;<br/>--defaults-file=/usr/local/server/mysql/data/my.cnf &amp;<br/><br/>由于 MySQL 不是安装在标准目录下，因此必须要修改 mysqld_safe 中的 my_print_defaults 文件所在位置，才能通过<br/>mysqld_safe 来启动 MySQL 服务器。<br/>3.) memcache + libevent 安装编译安装：<br/><br/>&#91;Copy to clipboard&#93; &#91; - &#93;CODE:<br/>&#91;root@localhost&#93;#cd libevent-1.2a<br/>&#91;root@localhost&#93;#./configure --prefix=/usr/ &amp;&amp; make &amp;&amp; make install<br/>&#91;root@localhost&#93;#cd ../memcached-1.2.0<br/>&#91;root@localhost&#93;#./configure --prefix=/usr/local/server/memcached --with-libevent=/usr/<br/>&#91;root@localhost&#93;#make &amp;&amp; make install<br/>备注：如果 libevent 不是安装在 /usr 目录下，那么需要把 libevent-1.2a.so.1 拷贝/链接到 /usr/lib 中，否则<br/>memcached 无法正常加载。运行以下命令来启动 memcached：<br/>&#91;root@localhost&#93;#/usr/local/server/memcached/bin/memcached &#92;<br/>-l 192.168.8.1 -d -p 10000 -u nobody -m 128<br/><br/>表示用 daemon 的方式启动 memcached，监听在 192.168.8.1 的 10000 端口上，运行用户为 nobody，为其分配<br/>128MB 的内存。<br/><br/>四、 安装Apache、PHP、eAccelerator、php-memcache<br/><br/><br/><br/>四、) 安装Apache、PHP、eAccelerator、php-memcache由于Apache<br/>2下的php静态方式编译十分麻烦，因此在这里采用动态模块(DSO)方式。1.) 安装Apache 2.2.3<br/>&#91;root@localhost&#93;#./configure --prefix=/usr/local/server/apache --disable-userdir --disable-actions &#92;<br/>--disable-negotiation --disable-autoindex --disable-filter --disable-include --disable-status &#92;<br/>--disable-asis --disable-auth --disable-authn-default --disable-authn-file --disable-authz-groupfile &#92;<br/>--disable-authz-host --disable-authz-default --disable-authz-user --disable-userdir &#92;<br/>--enable-expires --enable-module=so</div><br/><br/>备注：在这里，取消了一些不必要的模块，如果你需要用到这些模块，那么请去掉部分参数。<br/>2.) 安装PHP 5.2.0<br/><br/>[Copy to clipboard] [ - ]CODE:<br/>[root@localhost]#./configure --prefix=/usr/local/server/php --with-mysql &#92;<br/>--with-apxs2=/usr/local/server/apache/bin/apxs --with-freetype-dir=/usr/ --with-png-dir=/usr/ &#92;<br/>--with-gd=/usr/ --with-jpeg-dir=/usr/ --with-zlib --enable-magic-quotes --with-iconv &#92;<br/>--without-sqlite --without-pdo-sqlite --with-pdo-mysql --disable-dom --disable-simplexml &#92;<br/>--enable-roxen-zts<br/>[root@localhost]#make && make install<br/>备注：如果不需要gd或者pdo等模块，请自行去掉。<br/>3.) 安装eAccelerator-0.9.5<br/><br/>[Copy to clipboard] [ - ]CODE:<br/>[root@localhost]#cd eAccelerator-0.9.5<br/>[root@localhost]#export PHP_PREFIX=/usr/local/server/php<br/>[root@localhost]#$PHP_PREFIX/bin/phpize<br/>[root@localhost]#./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config<br/>[root@localhost]#make && make install<br/>4.) 安装memcache模块<br/><br/>[Copy to clipboard] [ - ]CODE:<br/>[root@localhost]#cd memcache-2.1.0<br/>[root@localhost]#export PHP_PREFIX=/usr/local/server/php<br/>[root@localhost]#$PHP_PREFIX/bin/phpize<br/>[root@localhost]#./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config<br/>[root@localhost]#make && make install<br/>5.) 修改 php.ini 配置然后修改 php.ini，修改/加入类似以下内容：<br/><br/>[Copy to clipboard] [ - ]CODE:<br/>extension_dir = "/usr/local/server/php/lib/"<br/>extension="eaccelerator.so"<br/>eaccelerator.shm_size="32" &nbsp; &nbsp; &nbsp; ;设定eaccelerator的共享内存为32MB<br/>eaccelerator.cache_dir="/usr/local/server/eaccelerator"<br/>eaccelerator.enable="1"<br/>eaccelerator.optimizer="1"<br/>eaccelerator.check_mtime="1"<br/>eaccelerator.debug="0"<br/>eaccelerator.filter="*.php"<br/>eaccelerator.shm_max="0"<br/>eaccelerator.shm_ttl="0"<br/>eaccelerator.shm_prune_period="3600"<br/>eaccelerator.shm_only="0"<br/>eaccelerator.compress="1"<br/>eaccelerator.compress_level="9"<br/>eaccelerator.log_file = "/usr/local/server/apache/logs/eaccelerator_log"<br/>eaccelerator.allowed_admin_path = "/usr/local/server/apache/htdocs/ea_admin"<br/>extension="memcache.so"<br/><br/>在这里，最好是在apache的配置中增加默认文件类型的cache机制，即利用apache的expires模块，新增类似如下几行：<br/><br/>[Copy to clipboard] [ - ]CODE:<br/>ExpiresActive On<br/>ExpiresByType text/html "access plus 10 minutes"<br/>ExpiresByType text/css "access plus 1 day"<br/>ExpiresByType image/jpg "access 1 month"<br/>ExpiresByType image/gif "access 1 month"<br/>ExpiresByType image/jpg "access 1 month"<br/>ExpiresByType application/x-shockwave-flash "access plus 3 day"<br/>这么设置是由于我的这些静态文件通常很少更新，因此我选择的是"access"规则，如果更新相对比较频繁，可以改用"modification"规则;或者也可以用"access"规则，但是在文件更新的时候，执行一下"touch"命令，把文件的时间刷新一下即可。<br/><br/><br/><br/>五、 安装Squid<br/><br/><br/><br/>五、) 安装Squid<br/>[root@localhost]#./configure --prefix=/usr/local/server/squid --enable-async-io=100 --disable-delay-pools --disable-mem-gen-trace --disable-useragent-log --enable-kill-parent-hack --disable-arp-acl --enable-epoll --disable-ident-lookups --enable-snmp --enable-large-cache-files --with-large-files<br/>[root@localhost]#make && make install<br/><br/>或使用如下安装方法：<br/>[root@localhost]#yum install squid<br/><br/>如果是2.6的内核，才能支持epoll的IO模式，旧版本的内核则只能选择poll或其他模式了;另外，记得带上支持大文件的选项，否则在access<br/>log等文件达到2G的时候就会报错。设定 squid 的配置大概如下内容：<br/>#设定缓存目录为 /var/cache1 和 /var/lib/squid，每次处理缓存大小为128MB，当缓存空间使用达到95%时<br/>#新的内容将取代旧的而不直接添加到目录中，直到空间又下降到90%才停止这一活动<br/>#/var/cache1 最大1024MB，/var/lib/squid 最大 5000MB，都是 16*256 级子目录<br/><br/>[Copy to clipboard] [ - ]CODE:<br/>cache_dir aufs /var/cache1 1024 16 256<br/>cache_dir aufs /var/lib/squid 5000 16 256<br/>cache_mem 128 MB<br/>cache_swap_low 90<br/>cache_swap_high 95<br/>#设置存储策略等<br/>maximum_object_size 4096 KB<br/>minimum_object_size 0 KB<br/>maximum_object_size_in_memory 80 KB<br/>ipcache_size 1024<br/>ipcache_low 90<br/>ipcache_high 95<br/>cache_replacement_policy lru<br/>memory_replacement_policy lru<br/>#设置超时策略<br/>forward_timeout 20 seconds<br/>connect_timeout 15 seconds<br/>read_timeout 3 minutes<br/>request_timeout 1 minutes<br/>persistent_request_timeout 15 seconds<br/>client_lifetime 15 minutes<br/>shutdown_lifetime 5 seconds<br/>negative_ttl 10 seconds<br/>#限制一个ip最大只能有16个连接<br/>acl OverConnLimit maxconn 16<br/>http_access deny OverConnLimit<br/>#限制baidu spider访问<br/>#acl AntiBaidu req_header User-Agent Baiduspider<br/>#http_access deny AntiBaidu<br/>#常规设置<br/>visible_hostname cache.yejr.com<br/>cache_mgr <a href="mailto:webmaster@yejr.com">webmaster@yejr.com</a><br/>client_persistent_connections off<br/>server_persistent_connections on<br/>cache_effective_user nobody<br/>cache_effective_group nobody<br/>tcp_recv_bufsize 65535 bytes<br/>half_closed_clients off<br/>#设定不缓存的规则<br/>hierarchy_stoplist cgi-bin<br/>acl QUERY urlpath_regex cgi-bin<br/>cache deny QUERY<br/>#不要相信ETag 因为有gzip<br/>acl apache rep_header Server ^Apache<br/>broken_vary_encoding allow apache<br/>#设置access log，并且令其格式和apache的格式一样，方便awstats分析<br/>emulate_httpd_log &nbsp; on<br/>logformat apache %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<br/>初始化和启动squid<br/><br/>[Copy to clipboard] [ - ]CODE:<br/>[root@localhost]#/usr/local/server/squid/sbin/squid -z<br/>[root@localhost]#/usr/local/server/squid/sbin/squid<br/>第一条命令是先初始化squid缓存哈希子目录，只需执行一次即可。<br/><br/>六、后记<br/><br/><br/>六、后记一、)想要启用squid所需的改变想要更好的利用squid的cache功能，不是把它启用了就可以的，我们需要做以下几个调整：<br/>1、启用apache的 mod_expires 模块，修改 httpd.conf，加入以下内容：<br/><br/>[Copy to clipboard] [ - ]CODE:<br/>#expiresdefault "modification plus 2 weeks"expiresactive<br/>onexpiresbytype text/html "access plus 10 minutes"expiresbytype<br/>image/gif "modification plus 1 month"expiresbytype image/jpeg "modification<br/>plus 1 month"expiresbytype image/png "modification plus 1<br/>month"expiresbytype text/css "access plus 1 day"expiresbytype<br/>application/x-shockwave-flash "access plus 3 day"<br/>以上配置的作用是规定各种类型文件的cache规则，对那些图片/flash等静态文件总是cache起来，可根据各自的需要做适当调整。<br/>2、修改 php.ini 配置，如下：<br/>session.cache_limiter = nocache<br/>以上配置的作用是默认取消php中的cache功能，避免不正常的cache产生。<br/>3、修改应用程序例如，有一个php程序页面static.php，它存放着某些查询数据库后的结果，并且数据更新并不频繁，于是，我们就可以考虑对其cache。只需在static.php中加入类似如下代码：<br/>header('Cache-Control: max-age=86400<br/>,must-revalidate');header('Pragma:');header('Last-Modified: ' .<br/>gmdate('D, d M Y H:i:s') . ' GMT' );header("Expires: " .gmdate ('D, d M Y<br/>H:i:s', time() + '86400' ). ' GMT');<br/>以上代码的意思是，输出一个http头部信息，让squid知道本页面默认缓存时长为一天。<br/>二、)squidclient简要介绍<br/>*<br/><br/>[Copy to clipboard] [ - ]CODE:<br/>取得squid运行状态信息： squidclient -p 80 mgr:info<br/>*取得squid内存使用情况： squidclient -p 80 mgr:mem<br/>*取得squid已经缓存的列表： squidclient -p 80 mgr:objects. use it carefully,it may crash<br/>*取得squid的磁盘使用情况： squidclient -p 80 mgr:diskd<br/>*强制更新某个url：squidclient -p 80 -m PURGE <a href="http://www.yejr.com/static.php" target="_blank">http://www.yejr.com/static...</a><br/>*更多的请查看：squidclient-h 或者 squidclient -p 80 mgr:</div></div><br/><br/><br/>现在ArthurXF本人正在搞PHP等技术培训，如果想学习的人可以跟我联系。另外培训的招生简章在这个网址，想了解的可以去看看。加我QQ：29011218交流也可。<br/><a href="http://www.bizeway.net/read.php/285.htm" target="_blank">PHP培训招生简章</a><br/>Tags - <a href="tag.php?tag=%E6%9C%8D%E5%8A%A1%E5%99%A8%E3%80%80%E5%A4%A7%E7%94%A8%E6%88%B7%E9%87%8F%E3%80%80%E6%89%BF%E8%BD%BD%E6%96%B9%E6%A1%88" rel="tag">服务器　大用户量　承载方案</a>
]]>
</description>
</item><item>
<link>http://www.bizeway.net/read.php?&amp;guid=0#topreply</link>
<title><![CDATA[[评论] 跟ArthurXF探讨大型网站架构——学习篇3]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?&amp;guid=0#topreply</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>