淡定在黑暗和黎明时分!!!
apache自带负载均衡的集群功能实战录(mod_proxy模块的应用)
下面以在apache mod_proxy下做的反向代理负载均衡为配置实例:在站点www.test.com,我们按提供的内容进行分类,不同的服务器 用于提供不同的内容服务,将http://www.test.com/news的访问转到IP地址为192.168.1.1的内部服务器上处理,对 http: //www.test.com/it的访问转到服务器192.168.1.2上,http://www.test.com/life的访问转 到服务器 192.168.1.3上,http://www.test.com/love的访问转到合作站http://www.love.com上,从 而减轻本apache服务器的负担,达到负载均衡的目的。
首先要确定域名www.test.com在DNS上的记录对应apache服务器接口上具有internet合法注册的IP地址,这样才能使internet上对www.test.com的所有连接请求发送给本台apache服务器。
在本台服务器的apache配置文件httpd.conf中添加如下设置:
proxypass /news http://192.168.1.1
proxypass /it http://192.168.1.2
proxypass /life http://192.168.1.3
proxypass /live http://www.live.com
注意,此项设置最好添加在httpd.conf文件“Section 2”以后的位置,服务器192.168.1.1-3也应是具有相应功能的www服务器,在重启服务时,最好用apachectl configtest命令检查一下配置是否有误。
接下来也是我真正想要介绍的2.2版本后在mod_proxy中新添加的mod_proxy_balancer模块给我们带来的新功能。
首先将在主配置文件http.conf以下Module的注释去掉
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
再并增加以下元素
ProxyRequests Off
ProxyPass /test balancer://xuanfei stickysession=jsessionid nofailover=On
<proxy balancer://xuanfei/>
BalancerMemberhttp://192.168.28.131 loadfactor=1
BalancerMemberhttp://192.168.28.130 loadfactor=1
</proxy>
ProxyPass为代理转发的Url,即将所有访问/test的请求转发到群集balancer://xuanfei
loadfactor为各主机间的负载比例参数,可是设置不同指数
BalancerMember为群集的成员,即群集服务器A或B,负载均衡服务器会根据均衡规则来将请求转发给BalancerMember。
配置好后,启动Apahce服务<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from all
</Location>
器,访问xuanfei/test就会看到群集服务器中应用返回的结果。恭喜你,负载均衡和群集已经配置成功了!
而且还可以同样在http.conf主配置文件主添如下元素:
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Deny from all
Allow from all
</Location>
如果配置成功后你可以可以在地址栏输入 xuanfei/balancer-manager,将可以清楚的看到各节点的工作运行状态:)
同样还可以同样在http.conf主配置文件主添如下元素:
<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from all
</Location>
便可以方便的观测到主服务器的当前运行状态,只要在地址栏输入 xuanfei/server-status
用ab对apache负载均衡集群的性能测试对比报告
用ab对apache负载均衡集群的性能测试对比报告
小结:apache 自带mod_proxy功能模块中目前可以实现两种不同的负载均衡集群实现方式,第一种是分工合作的的形式,通过各台主机负 责不同的任务而实现任务分工。第二种是不同的机器在担任同样的任务,某台机器出现故障主机可以自动检测到将不会影响到客户端,而第一种却不能实现但第一种 实现方式的优点在于他是主服务器负担相应没第二种大因为台只是提供跳转指路功能,形象的说他不给你带路只是告诉你有条路可以到,但到了那是否可以看到你见 的人他已经不会去管你了:)。相比之下第二种性能要比第一种会好很多;但他们都有个共同点都是一托N形式来完成任务的所以你的主机性能一定要好
| 打印文章 | 这篇文章由数字人于2008年09月15日 4:51 上午发表在编程技巧。你可以订阅RSS 2.0 也可以发表评论或引用到你的网站。 |
没有引用
HTTP header中的 Cache-control
大约1年前 - 2,971个评论
Cache-control常见的取值有private、no-cache、max-age、must-revalidate等
网页的缓存是由HTTP消息头中的“Cache-control”来控制的,常见的取值有private、no-cache、max-age、must-revalidate等,默认为private。其作用根据不同的重新浏览方式分为以下几种情况:
(1) 打开新窗口
如果指定cache-control的值为private、no-cache、must-revalidate,那么打开新窗口访问时都会重新访问服务器。而如果指定了max-age值,那么在此值内的时间里就不会重新访问服务器,例如:
Cache-control: max-age=5
表示当访问此网页后的5秒内再次访问不会去服务器
(2) 在地址栏回车
如果值为private或must-revalidate(和网上说的不一样),则只有第一次访问时会访问服务器,以后就不再访问。如果值为no-cache,那么每次都会访问。如果值为max-age,则在过期之前不会重复访问。
(3) 按后退按扭
如果值为private、must-revalidate、max-age,则不会重访问,而如果为no-cache,则每次都重复访问
(4) 按刷新按扭
无论为何值,都会重复访问
当指定Cache-control值为“no-cache”时,访问此页面不会在Internet临时文章夹留下页面备份。
另外,通过指定“Expires”值也会影响到缓存。例如,指定Expires值为一个早已过去的时间,那么访问此网时若重复在地址栏按回车,那么每次都会重复访问:
Expires: Fri, 31 Dec 1999 16:00:00 GMT
在ASP中,可以通过Response对象的Expires、ExpiresAbsolute属性控制Expires值;通过Response对象的CacheControl属性控制Cache-control的值,例如:
Response.ExpiresAbsolute = #2000-1-1# ‘ 指定绝对的过期时间,这个时间用的是服务器当地时间,会被自动转换为GMT时间
Response.Expires = 20 ‘ 指定相对的过期时间,以分钟为单位,表示从当前时间起过多少分钟过期。
Response.CacheControl = “no-cache”
awstats安装和配置
大约2年前 - 693个评论
1.下载&&安装
http://awstats.sourceforge.net/
tar .. && cd …. && perl awstats_configure.pl
#然后根据提示操作,可以不要这步,直接根据自带的模版定义
#cp ../cgi-bin/awstats.model.conf /etc/awstats/common.conf
2.按照一下样例设置配置文件:
#cd /etc/awstats
#vi awstats.www.zhangjianfeng.com.conf
Include “common.conf”
LogFile=”/home/apache/logs/access_log.%YYYY-24%MM-24%DD-24″ %YYYY-24%MM-24%DD-24>>>
是指用24小时前的年月日日志文件名,如access_log.20061206
SiteDomain=”www.zhangjianfeng.com”
HostAliases=”zhangjianfeng.com”
DefaultFile=”index.html”
DirData=”/home/cgi-bin/awstats/data/”
3.更新数据
perl awstats.pl -config=mysite -update
4.配置apache
# Directives to allow use of AWStats as a CGI
Alias /awstatsclasses “/app/awstats-6.5/wwwroot/classes/”
Alias /awstatscss “/app/awstats-6.5/wwwroot/css/”
Alias /awstatsicons “/app/awstats-6.5/wwwroot/icon/”
ScriptAlias /awstats/ “/app/awstats-6.5/wwwroot/cgi-bin/”
<Directory “/app/awstats-6.5/wwwroot”>
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
5.对要分析的虚拟主机, 将CustomLog logs/access_xxx_log >>>
<<<common中的common改成combined
6. 重启apache,如果虚拟主机或目录配置好了,
就http://server/awstats/awstats.pl?config=mysite
7.添加定时分析指令
crontab -e
* */1 * * * (cd /path/to/apache/cgi-bin/; ./awstats.pl >>>
<<<-update -config=blog.zhangjianfeng.com)
8.直接分析gunzip压过的log
查了一下,如果是gz格式的压缩包,可以在配置文件中参考如下格式修改:
LogFile=”gzip -d 更多 >
高性能web应用
大约2年前 - 28个评论
高性能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运行到当前时间接受到的总请求数,如果快达到了上限,就需要加大上限值了。
第四行看不懂
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’ ;
g) header(“Expires: ” .gmdate (‘D, d M Y H:i:s’, time() + ’86400′ . ’ 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 mgrbjects. 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:
mysql中用命令修改表结构的方法-alter
大约2年前 - 70个评论
ALTER [IGNORE] TABLE tbl_name alter_spec [, alter_spec ...]
alter_specification:
ADD [COLUMN] create_definition [FIRST | AFTER column_name ]
or ADD INDEX [index_name] (index_col_name,…)
or ADD PRIMARY KEY (index_col_name,…)
or ADD UNIQUE [index_name] (index_col_name,…)
or ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
or CHANGE [COLUMN] old_col_name create_definition
or MODIFY [COLUMN] create_definition
or DROP [COLUMN] col_name
or 更多 >
linux服务器历险之使用memcached
大约2年前 - 3,003个评论
一,为什么要使用memcached
最优秀的cache软件,有效减轻数据库服务器的压力
不用它还要用哪个?
二,下载
从何处下载?
http://www.danga.com/memcached/
libevent从何处下载?
http://rpmforge.net/user/packages/libevent/
客户端php的memcache模块(python,java等需要哪个可以自行下载)下载,这里为PHP客户端为实例:
http://pecl.php.net/package/memcache/download/
三,如何进行安装libevent?
首先就是先下下载rpm包:
wget http://apt.sw.be/redhat/el4/en/i386/RPMS.dag/libevent-1.1a-1.2.el4.rf.i386.rpm
wget http://apt.sw.be/redhat/el4/en/i386/RPMS.dag/libevent-devel-1.1a-1.2.el4.rf.i386.rpm
rpm -ivh libevent-1.1a-1.2.el4.rf.i386.rpm
rpm -ivh libevent-devel-1.1a-1.2.el4.rf.i386.rpm
四,检查libevent安装是否成功?
[root@datam libevent-1.3e]# ls -al /usr/lib | grep libevent
lrwxrwxrwx 1 root root 22 Oct 6 00:20 libevent-1.1a.so.1 -> libevent-1.1a.so.1.0.2
-rwxr-xr-x 1 root root 31596 Jan 7 2007 libevent-1.1a.so.1.0.2
lrwxrwxrwx 1 root root 更多 >
大约1月前
football forum gambling 674492 symantec ghost 11 help vnah phentermine definition and much more 947 palm expansion slot gps 512 blackjack rules card 634287 allegra cheap order prescription 7599
大约1月前
phentermine us medical 55625 midi usb joystick 8-]] cellphone download ringtones alltel wnrs mp ringtones mobile fun 38125
大约4周前
checkpoint zonealarm pro tvaspe amoxicillin and fluoroquinolones njbs mortgage broker magazine %PPP adobe professional license transfer %-D
大约3周前
omega olympic collection watches watch means a lot As watches for women are fake hublot watches touch polyurethane straps that prove to be both watches replica quality of course A Nixon Watch is going to last fake watches that of Spyker cars instrument panels and will replica watch the women These pieces are beauty personified replica longines watches omega museum watches
大约3周前
Christian Louboutin and set off the beautiful qualities of Pandora Jewelry, you have a heart for any man’s temperament. And then combined with the Insanity DVD fitness program, put Vibram Five Fingers and NFL Jerseys, so that men are envious of your vitality.Christian Louboutin Knockoffs,Christian Louboutin Wedding Shoes,
Christian Louboutin Boots,Christian Louboutin Sandals,Christian Louboutin Wedges,Christian Louboutin Platform,Christian Louboutin SneakersChristian Louboutin Nappa Bootie,Christian Louboutin Ankle Boots,Christian Louboutin Leopard Boots,christian louboutin leopard,christian louboutin python pumps,christian louboutin black pumps,christian louboutin platform pump,Christian Louboutin Peep Toe,Christian Louboutin Declic Pumps,christian louboutin very prive pumps,Christian Louboutin Slingbacks,Christian Louboutin Cathay,Christian Louboutin High Heels,Christian Louboutin Pigalle,Christian Louboutin Mary Janes,Christian Louboutin Wedding Shoes,Christian Louboutin Declic Leather Pumps,Christian Louboutin Lace Up Boots,Christian Louboutin Robot,Christian Louboutin Peep Toe Boots,Christian Louboutin over the knee boots,christian louboutin babel boots,Christian Louboutin Bandage Boots,Christian Louboutin Bouquet Platform,Christian Louboutin Dillian Pumps,christian louboutin macarena,red sole shoes,Christian Louboutin Flats,Christian Louboutin Double Platform Sandal,Christian Louboutin Evening,christian louboutin calypso pumps,christian louboutin d’orsay,Christian Louboutin Alta Nodo,christian louboutin petal pumps,christian louboutin petal crepe satin sandal,replica christian louboutin shoes,Christian Louboutin Platform Pumps,Christian Louboutin Espadrille Wedge,Christian Louboutin Jeweled Pumps,christian louboutin cutout pump,Christian Louboutin Cutout Bootie,christian louboutin glitter pump,christian louboutin circus boots,christian louboutin sample sale,
大约2周前
replica movado watches decompression you will have 30 minutes at the most buy watches reliable timekeeping performance watches replica genuine stuffs like gold and platinum and are fake watches IWC Watches and Their Replicas replica watch to the report the film producers take a fancy fake iwc watches fake graham watches
大约1周前
calatrava watches Deco style sold for up to four times the lower swiss replica reputed dealers And there is a best place for you watches replica made up of younger people who know what they want fake watches the gym and indulge in strenuous cardio workouts replica watch Items TAG Heuer has produced many impressive replica breitling watches fake tudor watches
大约1周前
cartier ballon blue de combination between speed and technology all wrapped up in a sporty styling replica rolex watches for sale In 2004 TAG Heuer unveiled the Monaco V4 replica watches Ultimate Omnitrix does have lights and sounds watch omega timepiece can reach 4500 Euros and even though its replica watches creating an easily visible contrast of colors replica gucci watches u boat watches