posts - 23,  comments - 0,  trackbacks - 0
  2011年8月23日

Mysql配置文件my.cnf详解

原文地址:http://apps.hi.baidu.com/share/detail/30356338 

posted @ 2011-08-23 16:12 MinisFox 阅读(12) 评论(0) 编辑

PHP Session原生及兼容双向技术方案阐述和实现PHP Session原生及兼容双向技术方案阐述和实现

 原文:http://apps.hi.baidu.com/share/detail/35156835

posted @ 2011-08-23 11:56 MinisFox 阅读(12) 评论(0) 编辑
  2011年8月1日
posted @ 2011-08-01 16:10 MinisFox 阅读(6) 评论(0) 编辑
  2011年7月14日
摘要: 推荐参考地址:MailinglistARChives官方讨论区http://marc.info/?l=nginxhttp://edu.codepub.com/2010/0829/25477.php推荐参考地址:Mailing list ARChives 官方讨论区http://marc.info/?l=nginxNginx 常见应用技术指南[Nginx Tips]http://bbs.linuxtone.org/thread-1685-1-1.html本日志内容来自互联网和平日使用经验,整理一下方便日后参考。正则表达式匹配,其中:* ~ 为区分大小写匹配* ~* 为不区分大小写匹配* !~和!阅读全文
posted @ 2011-07-14 15:18 MinisFox 阅读(16) 评论(0) 编辑
  2011年5月27日
下载 : Nginx 中文手册 2010-02-02 (206.69 KB, 已下载 3401 次)

Nginx 常见应用技术指南[Nginx Tips] 第二版

作者:NetSeek http://www.linuxtone.org (IT运维专家网|集群架构|性能调优)
欢迎转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明.
首发时间: 2008-11-25 更新时间:2009-1-14

目 录

一、 Nginx 基础知识
二、 Nginx 安装及调试
三、 Nginx Rewrite
四、 Nginx Redirect
五、 Nginx 目录自动加斜线:
六、 Nginx Location
七、 Nginx expires
八、 Nginx 防盗链
九、 Nginx 访问控制
十、 Nginx日志处理
十一、 Nginx Cache
十二、 Nginx 负载均衡
十三、 Nginx简单优化
十四、 如何构建高性能的LEMP环境
十五、 Nginx服务监控
十六、 常见问题与错误处理.
十七、 相关资源下载

【前言】:

编写此技术指南在于推广普及NGINX在国内的使用,更方便的帮助大家了解和掌握NGINX
的一些使用技巧。本指南很多技巧来自于网络和工作中或网络上朋友们问我的问题.在此对
网络上愿意分享的朋友们表示感谢和致意!欢迎大家和我一起丰富本技术指南提出更好的建
议!请朋友们关注: http://www.linuxtone.org 技术分享社区! 互想学习共同进步!

一、 Nginx 基础知识

1、简介
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服
务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超
过两年半了。Igor 将源代码以类BSD许可证的形式发布。尽管还是测试版,但是,Nginx 已经因为它的稳
定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。

更多的请见官方wiki: http://wiki.codemongers.com/

2、 Nginx的优点
nginx做为HTTP服务器,有以下几项基本特性:
1) 处理静态文件,索引文件以及自动索引;打开文件描述符缓冲.
2) 无缓存的反向代理加速,简单的负载均衡和容错.
3) FastCGI,简单的负载均衡和容错.
4) 模块化的结构。包括gzipping, byte ranges, chunked responses, 以及 SSI-filter等filter。
如果由FastCGI或其它代理服务器处理单页中存在的多个SSI,则这项处理可以并行运行,而不
需要相互等待。
5) 支持SSL 和 TLS SNI.
Nginx专为性能优化而开发,性能是其最重要的考量, 实现上非常注重效率 。它支持内核Poll模型,
能经受高负载的考验, 有报告表明能支持高达 50,000 个并发连接数。

Nginx具有很高的稳定性。其它HTTP服务器,当遇到访问的峰值,或者有人恶意发起慢速连接时,
也很可能会导致服务器物理内存耗尽频繁交换,失去响应,只能重启服务器。例如当前apache一旦上到
200个以上进程,web响应速度就明显非常缓慢了。而Nginx采取了分阶段资源分配技术,使得它的CPU与
内存占用率非常低。nginx官方表示保持10,000个没有活动的连接,它只占2.5M内存,所以类似DOS这
样的攻击对nginx来说基本上是毫无用处的。就稳定性而言, nginx比lighthttpd更胜一筹。

Nginx支持热部署。它的启动特别容易, 并且几乎可以做到7*24不间断运行,即使运行数个月也不
需要重新启动。你还能够在不间断服务的情况下,对软件版本进行进行升级。

Nginx采用master-slave模型, 能够充分利用SMP的优势,且能够减少工作进程在磁盘I/O的阻
塞延迟。当采用select()/poll()调用时,还可以限制每个进程的连接数。

Nginx代码质量非常高,代码很规范, 手法成熟, 模块扩展也很容易。特别值得一提的是强大
的Upstream与Filter链。 Upstream为诸如reverse proxy, 与其他服务器通信模块的编写奠定了很好的
基础。而Filter链最酷的部分就是各个filter不必等待前一个filter执行完毕。它可以把前一个filter
的输出做为当前filter的输入,这有点像Unix的管线。这意味着,一个模块可以开始压缩从后端服务器
发送过来的请求,且可以在模块接收完后端服务器的整个请求之前把压缩流转向客户端。

Nginx采用了一些os提供的最新特性如对sendfile (Linux 2.2+),accept-filter (FreeBSD
4.1+),TCP_DEFER_ACCEPT (Linux 2.4+) 的支持,从而大大提高了性能

二、 Nginx 安装及调试

1、Pcre 安装

./configure
make && make install
cd ../

2. nginx 编译安装

/configure --user=www --group=www --prefix=/usr/local/nginx/ --with-http_stub_status_module
--with-openssl=/usr/local/openssl

make && make install

更详细的模块定制与安装请参照官方wiki.

3、Nginx 配置文件测试:

# /usr/local/nginx/sbin/nginx -t //Debug 配置文件的关键命令需要重点撑握.

2008/12/16 09:08:35 [info] 28412#0: the configuration file /usr/local/nginx/conf/nginx.conf
syntax is ok
2008/12/16 09:08:35 [info] 28412#0: the configuration file /usr/local/nginx/conf/nginx.conf was
tested successfully

3、 Nginx 启动:

# /usr/local/nginx/sbin/nginx

4、 Nginx 配置文件修改重新加载:

# kill -HUP `cat /usr/local/nginx/logs/nginx.pid `

三、 Nginx Rewrite

1. Nginx Rewrite 基本标记(flags)
last - 基本上都用这个Flag。
※相当于Apache里的[L]标记,表示完成rewrite,不再匹配后面的规则
break - 中止Rewirte,不再继续匹配
redirect - 返回临时重定向的HTTP状态302
permanent - 返回永久重定向的HTTP状态301
※原有的url支持正则 重写的url不支持正则

2. 正则表达式匹配,其中:
~ 为区分大小写匹配
~* 为不区分大小写匹配
!~!~* 分别为区分大小写不匹配及不区分大小写不匹配

3. 文件及目录匹配,其中:
-f !-f 用来判断是否存在文件
-d!-d 用来判断是否存在目录
-e!-e 用来判断是否存在文件或目录
-x !-x 用来判断文件是否可执行

3. Nginx 的一些可用的全局变量,可用做条件判断:

$args
$content_length
$content_type
$document_root
$document_uri
$host
$http_user_agent
$http_cookie
$limit_rate
$request_body_file
$request_method
$remote_addr
$remote_port
$remote_user
$request_filename
$request_uri
$query_string
$scheme
$server_protocol
$server_addr
$server_name
$server_port
$uri

四、 Nginx Redirect

将所有linuxtone.org与netseek.linuxtone.org域名全部自跳转到http://www.linuxtone.org

server {
    listen 80;
    server_name linuxtone.org netseek.linuxtone.org;
    index index.html index.php;
    root /data/www/wwwroot;
    if ($host !~ "^www\.linxtone\.org$") {
        rewrite ^(.*) http://www.linuxtone.org$1 redirect;
    }
    .....................
}

五、 Nginx 目录自动加斜线:

if (-d $request_filename){
    rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}

六、 Nginx Location

1.基本语法:[和上面rewrite正则匹配语法基本一致]
location [=|~|~*|^~] /uri/ { … }
~ 为区分大小写匹配
~* 为不区分大小写匹配
!~!~* 分别为区分大小写不匹配及不区分大小写不匹配

示例1:

location = / {
    # matches the query / only.
    # 只匹配 / 查询。
}

匹配任何查询,因为所有请求都已 / 开头。但是正则表达式规则和长的块规则将被优先和查询匹配

示例2:

location ^~ /images/ {
    # matches any query beginning with /images/ and halts searching,
    # so regular expressions will not be checked.
    # 匹配任何以 /images/ 开头的任何查询并且停止搜索。任何正则表达式将不会被测试。
}

示例3:

location ~* \.(gif|jpg|jpeg)$ {
    # matches any request ending in gif, jpg, or jpeg. However, all
    # requests to the /images/ directory will be handled by
    # 匹配任何以 gif、jpg 或 jpeg 结尾的请求。
}

七、 Nginx expires

1.根据文件类型判断,添加expires

# Add expires header for static content
location ~* \.(js|css|jpg|jpeg|gif|png|swf)$ {
    if (-f $request_filename) {
        root /data/www/wwwroot/bbs;
        expires 1d;
        break;
    }
}

2、根据某个目录判断,添加expires

# serve static files
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
    root /data/www/wwwroot/down;
    expires 30d;
}

八、 Nginx 防盗链

1. 针对不同的文件类型

#Preventing hot linking of images and other file types
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip)$ {
    valid_referers none blocked server_names *.linuxtone.org linuxtone.org http://localhost baidu.com;
    if ($invalid_referer) {
        rewrite ^/ http://www.linuxtone.org/images/default/logo.gif;
        # return 403;
    }
}

2. 针对不同的目录

location /img/ {
    root /data/www/wwwroot/bbs/img/;
    valid_referers none blocked server_names *.linuxtone.org http://localhost baidu.com;
    if ($invalid_referer) {
        rewrite ^/ http://www.linuxtone.org/images/default/logo.gif;
        #return 403;
    }
}

3. 同实现防盗链和expires的方法

#Preventing hot linking of images and other file types
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip)$ {
    valid_referers none blocked server_names *.linuxtone.org linuxtone.org http://localhost ;
    if ($invalid_referer) {
        rewrite ^/ http://www.linuxtone.org/images/default/logo.gif;
    }
    access_log off;
    root /data/www/wwwroot/bbs;
    expires 1d;
    break;
}

九、 Nginx 访问控制

1. Nginx 身份证验证

#cd /usr/local/nginx/conf
#mkdir htpasswd
/usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/htpasswd/tongji linuxtone

#添加用户名为linuxtone
New password: (此处输入你的密码)
Re-type new password: (再次输入你的密码)
Adding password for user

http://count.linuxtone.org/tongji/data/index.html(目录存在/data/www/wwwroot/tongji/data/目录

下)

将下段配置放到虚拟主机目录,当访问http://count.linuxtone/tongji/即提示要密验证:

location ~ ^/(tongji)/ {
    root /data/www/wwwroot/count;
    auth_basic "LT-COUNT-TongJi";
    auth_basic_user_file /usr/local/nginx/conf/htpasswd/tongji;
}

2. Nginx 禁止访问某类型的文件.

如,Nginx下禁止访问*.txt文件,配置方法如下.

location ~* \.(txt|doc)$ {
    if (-f $request_filename) {
        root /data/www/wwwroot/linuxtone/test;
        #rewrite …..可以重定向到某个URL
        break;
    }
}

方法2:

location ~* \.(txt|doc)${
    root /data/www/wwwroot/linuxtone/test;
    deny all;
}

实例:
禁止访问某个目录

location ~ ^/(WEB-INF)/ {
    deny all;
}

3. 使用ngx_http_access_module限制ip访问

location / {
    deny 192.168.1.1;
    allow 192.168.1.0/24;
    allow 10.1.1.0/16;
    deny all;
}

详细参见wiki: http://wiki.codemongers.com/NginxHttpAccessModule#allow

4. Nginx 下载限制并发和速率

limit_zone linuxtone $binary_remote_addr 10m;
server {
    listen 80;
    server_name down.linuxotne.org;
    index index.html index.htm index.php;
    root /data/www/wwwroot/down;
    #Zone limit
    location / {
        limit_conn linuxtone 1;
        limit_rate 20k;
    }
    ..........
}

只允许客房端一个线程,每个线程20k.

【注】limit_zone linuxtone $binary_remote_addr 10m; 这个可以定义在主的

5. Nginx 实现Apache一样目录列表

location / {
    autoindex on;
}

6. 上文件大小限制
主配置文件里加入如下,具体大小根据你自己的业务做调整。

client_max_body_size 10m;

十、 Nginx 日志处理

1.Nginx 日志切割

#contab -e
59 23 * * * /usr/local/sbin/logcron.sh /dev/null 2>&1

# cat /usr/local/sbin/logcron.sh

#!/bin/bash

log_dir="/data/logs"

time=`date +%Y%m%d`

/bin/mv ${log_dir}/access_linuxtone.org.log ${log_dir}/access_count.linuxtone.org.$time.log
kill -USR1 `cat /var/run/nginx.pid`

更多的日志分析与处理就关注(同时欢迎你参加讨论):http://bbs.linuxtone.org/forum-8-1.html

2.利用AWSTATS分析NGINX日志
设置好Nginx日志格式,仍后利用awstats进行分析.
请参考: http://bbs.linuxtone.org/thread-56-1-1.html

3. Nginx 如何不记录部分日志
日志太多,每天好几个G,少记录一些,下面的配置写到server{}段中就可以了

location ~ .*\.(js|jpg|JPG|jpeg|JPEG|css|bmp|gif|GIF)$ {
    access_log off;
}

十一、Nginx Cache服务配置

如果需要将文件缓存到本地,则需要增加如下几个子参数:

proxy_store on;
proxy_store_access user:rw group:rw all:rw;
proxy_temp_path 缓存目录;

其中,
proxy_store on 用来启用缓存到本地的功能,
proxy_temp_path 用来指定缓存在哪个目录下,如:proxy_temp_path html;

在经过上一步配置之后,虽然文件被缓存到了本地磁盘上,但每次请求仍会向远端拉取
文件,为了避免去远端拉取文件,必须修改proxy_pass:

if ( !-e $request_filename) {
    proxy_pass http://mysvr;
}

即改成有条件地去执行proxy_pass,这个条件就是当请求的文件在本地的
proxy_temp_path指定的目录下不存在时,再向后端拉取。

更多更高级的应用可以研究ncache,官方网站: http://code.google.com/p/ncache/

详细安装请参照http://bbs.linuxtone.org 应用加速版ncache相关的贴子.

十二、Nginx 负载均衡

1. Nginx 负载均衡基础知识

nginx的upstream目前支持4种方式的分配

1)、轮询(默认)
每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。

2)、weight
指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。

2)、ip_hash
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。

3)、fair(第三方)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。

4)、url_hash(第三方)

2. Nginx 负载均衡实例1

upstream bbs.linuxtone.org { #定义负载均衡设备的Ip及设备状态
    server 127.0.0.1:9090 down;
     server 127.0.0.1:8080 weight=2;
     server 127.0.0.1:6060;
     server 127.0.0.1:7070 backup;
}

在需要使用负载均衡的server中增加

proxy_pass http://bbs.linuxtone.org/;

每个设备的状态设置为:
a) down 表示单前的server暂时不参与负载
b) weight 默认为1.weight越大,负载的权重就越大。
c) max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误
d) fail_timeout:max_fails次失败后,暂停的时间。
e) backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。

nginx支持同时设置多组的负载均衡,用来给不用的server来使用。

client_body_in_file_only 设置为On 可以讲client post过来的数据记录到文件中用来做debug
client_body_temp_path 设置记录文件的目录 可以设置最多3层目录
location 对URL进行匹配.可以进行重定向或者进行新的代理 负载均衡

3. Nginx 负载均衡实例 2
按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓
存时比较有效,也可以用作提高Squid缓存命中率.

简单的负载均等实例:
#vi nginx.conf //nginx主配置文件核心配置
.........

#loadblance my.linuxtone.org
upstream my.linuxtone.org {
    ip_hash;
    server 127.0.0.1:8080;
    server 192.168.169.136:8080;
    server 219.101.75.138:8080;
    server 192.168.169.117;
    server 192.168.169.118;
    server 192.168.169.119;
}
.........
include vhosts/linuxtone_lb.conf;
.........

# vi proxy.conf

proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 30;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
proxy_store on;
proxy_store_access user:rw group:rw all:r;
#nginx cache
#client_body_temp_path /data/nginx_cache/client_body 1 2;
proxy_temp_path /data/nginx_cache/proxy_temp 1 2;

#vi linuxtone_lb.conf

server {

    listen 80;
    server_name my.linuxtone.org;
    index index.php;
    root /data/www/wwwroot/mylinuxtone;

    if (-f $request_filename) {
        break;
    }

    if (-f $request_filename/index.php) {
        rewrite (.*) $1/index.php break;
    }

    error_page 403 http://my.linuxtone.org/member.php?m=user&a=login;

    location / {
        if ( !-e $request_filename) {
            proxy_pass http://my.linuxtone.org;
            break;
        }
        include /usr/local/nginx/conf/proxy.conf;
    }
}

十三、Nginx简单优化

1. 减小nginx编译后的文件大小 (Reduce file size of nginx)
默认的nginx编译选项里居然是用debug模式(-g)的(debug模式会插入很多跟踪和
ASSERT之类),编译以后一个nginx有好几兆。去掉nginx的debug模式编译,编译以
后只有几百K

auto/cc/gcc,最后几行有:

# debug
CFLAGS=”$CFLAGS -g”

注释掉或删掉这几行,重新编译即可。

2. 修改Nginx的header伪装服务器

1) 修改nginx.h

#vi nginx-0.7.30/src/core/nginx.h
#define NGINX_VERSION "1.8"
#define NGINX_VER "LTWS/" NGINX_VERSION
#define NGINX_VAR "NGINX"
#define NGX_OLDPID_EXT ".oldbin"

2) 修改nginx_http_header_filter_module
#vi nginx-0.7.30/src/http/ngx_http_header_filter_module.c
将如下

static char ngx_http_server_string[] = "Server: nginx" CRLF;

修改为

static char ngx_http_server_string[] = "Server: LTWS" CRLF;

a) 修改nginx_http_header_filter_module
#vi nginx-0.7.30/src/http/ngx_http_special_response.c
将如下:

static u_char ngx_http_error_full_tail[] =
"<hr><center>" NGINX_VER "</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

static u_char ngx_http_error_tail[] =
"<hr><center>nginx</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

修改为:

static u_char ngx_http_error_full_tail[] =
"<center> "NGINX_VER" </center>" CRLF
"<hr><center>http://www.linuxtone.org</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

static u_char ngx_http_error_tail[] =
"<hr><center>LTWS</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

修改后重新编译一下环境,

404错误的时候显示效果图(如果没有指定错误页的话):

利用curl命令查看服务器header

3. 为特定的CPU指定CPU类型编译优化.

默认nginx使用的GCC编译参数是-O

需要更加优化可以使用以下两个参数

--with-cc-opt='-O3' \

--with-cpu-opt=opteron \

使得编译针对特定CPU以及增加GCC的优化.

此方法仅对性能有所改善并不会有很大的性能提升,供朋友们参考.

CPUD类型确定:

# cat /proc/cpuinfo | grep "model name"

编译优化参数参考:http://en.gentoo-wiki.com/wiki/Safe_Cflags

4. Tcmalloc优化Nginx 性能

# wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz
# tar zxvf libunwind-0.99-alpha.tar.gz
# cd libunwind-0.99-alpha/
# CFLAGS=-fPIC ./configure
# make CFLAGS=-fPIC
# make CFLAGS=-fPIC install
# wget http://google-perftools.googlecode.com/files/google-perftools-0.98.tar.gz
# tar zxvf google-perftools-0.98.tar.gz
# cd google-perftools-0.98/
# ./configure
# make && make install
# echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
# ldconfig
# lsof -n | grep tcmalloc

编译nginx 加载google_perftools_module:

./configure --with-google_perftools_module

在主配置文件加入nginx.conf 添加:

google_perftools_profiles /path/to/profile;

5. 内核参数优化
# vi /etc/sysctl.conf

#在末尾增加以下内容:
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000

#使配置立即生效
/sbin/sysctl -p

十四、如何构建高性的LEMP

请参见: http://www.linuxtone.org/lemp/lemp.pdf

1、 提供完整的配置脚本下载:http://www.linuxtone.org/lemp/scripts.tar.gz
2、 提供NGINX常见配置范例含(虚拟主机,防盗链,Rewrite,访问控制,负载均衡Discuz相关程序静态化及等等),你只要稍稍修改即可线上应用。
3、将原版的xcache替换成EA,并提供相关简单调优脚本及配置文件。

更多的及更新资料请关注: http://www.linuxtone.org

十五、Nginx监控

1、 RRDTOOL+Perl脚本画图监控
先安装好rrdtool ,关于rrdtool本文不作介绍,具体安装请参照linuxtone监控版块.

#cd /usr/local/sbnin
#wget http://blog.kovyrin.net/files/mrtg/rrd_nginx.pl.txt
#mv rrd_nginx.pl.txt rrd_nginx.pl
#chmod a+x rrd_nginx.pl

#vi rrd_nginx.pl //配置脚本文件设置好路径

#!/usr/bin/perl
use RRDs;
use LWP::UserAgent;

# define location of rrdtool databases
my $rrd = '/data/www/wwwroot/nginx/rrd';

# define location of images
my $img = '/data/www/wwwroot/nginx/html';

# define your nginx stats URL
my $URL = "http:// 219.32.205.13/nginx_status";
…………

【注】根据自己具体的状况修改相应的路径.

#crontab –e //加入如下

* * * * * /usr/local/sbin/rrd_nginx.pl

重启crond后,通过配置nginx虚拟主机指到/data/www/wwwroot/nginx/html目录,通过crond
自动执行perl脚本会生成很多图片.

http://xxx/connections-day.png即可看到服务器状态图。

2、 官方Nginx-rrd 监控服务(多虚拟主机)(推荐)
网址:http://www.nginx.eu/nginx-rrd.html

此解决方案其实是基于上述监控方案的一个改进和增强,同样先安装好rrdtool这个画图工
具和相应的perl模块再做如下操作:

# yum install perl-HTML*

先建立好生成的库存和图片存放录

#mkdir -p /data/www/wwwroot/nginx/{rrd,html}
#cd /usr/local/sbin
#wget http://www.nginx.eu/nginx-rrd/nginx-rrd-0.1.4.tgz
#tar zxvf nginx-rrd-0.1.4.tgz
#cd nginx-rrd-0.1.4
#cd etc/
#cp nginx-rrd.conf /etc
#cd etc/cron.d
#cp nginx-rrd.cron /etc/cron.d
#cd /usr/local/src/nginx-rrd-0.1.4/html
# cp index.php /data/www/wwwroot/nginx/html/
#cd /usr/local/src/nginx-rrd-0.1.4/usr/sbin
#cp * /usr/sbin/

#vi /etc/nginx-rrd.conf

#####################################################
#
# dir where rrd databases are stored

RRD_DIR="/data/www/wwwroot/nginx/rrd";

# dir where png images are presented

WWW_DIR="/data/www/wwwroot/nginx/html";

# process nice level

NICE_LEVEL="-19";

# bin dir

BIN_DIR="/usr/sbin";

# servers to test

# server_utl;server_name

SERVERS_URL="http://219.32.205.13/nginx_status;219.32.205.13

http://www.linuxtone.org/nginx_status;www.linuxtone.org"" //根据你的具体情况做调整.

SEVERS_URL 格式 http://domain1/nginx_status;domain1 http://domain2/nginx_status;domain2

这种格式监控多虚拟主机连接状态:
重点启crond服务,仍后通过http://219.32.205.13/nginx/html/ 即可访问。配置过程很简单!

3、 CACTI模板监控Nginx

利用Nginx_status状态来画图实现CACTI监控
nginx编译时允许http_stub_status_module

# vi /usr/local/nginx/conf/nginx.conf

location /nginx_status {
    stub_status on;
    access_log off;
    allow 192.168.1.37;
    deny all;
}
# kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
# wget http://forums.cacti.net/download.php?id=12676
# tar xvfz cacti-nginx.tar.gz
# cp cacti-nginx/get_nginx_socket_status.pl /data/cacti/scripts/
# cp cacti-nginx/get_nginx_clients_status.pl /data/cacti/scripts/
# chmod 755 /data/cacti/scripts/get_nginx*

检测插件
# /data/cacti/scripts/get_nginx_clients_status.pl http://192.168.1.37/nginx_status

在cacti管理面板导入

cacti_graph_template_nginx_clients_stat.xml
cacti_graph_template_nginx_sockets_stat.xml

十六、常见问题与错误处理

1、 400 bad request错误的原因和解决办法
配置nginx.conf相关设置如下.

client_header_buffer_size 16k;
large_client_header_buffers 4 64k;

根据具体情况调整,一般适当调整值就可以。

2、 Nginx 502 Bad Gateway错误

proxy_next_upstream error timeout invalid_header http_500 http_503;

或者尝试设置:

large_client_header_buffers 4 32k;

3、 Nginx出现的413 Request Entity Too Large错误

这个错误一般在上传文件的时候会出现,

编辑Nginx主配置文件Nginx.conf,找到http{}段,添加

client_max_body_size 10m; //设置多大根据自己的需求作调整.

如果运行php的话这个大小client_max_body_size要和php.ini中的如下值的最大值
一致或者稍大,这样就不会因为提交数据大小不一致出现的错误。

post_max_size = 10M
upload_max_filesize = 2M

4、 解决504 Gateway Time-out(nginx)

遇到这个问题是在升级discuz论坛的时候遇到的

一般看来, 这种情况可能是由于nginx默认的fastcgi进程响应的缓冲区太小造成的,
这将导致fastcgi进程被挂起, 如果你的fastcgi服务对这个挂起处理的不好, 那么最后就
极有可能导致504 Gateway Time-out

现在的网站, 尤其某些论坛有大量的回复和很多内容的, 一个页面甚至有几百K。

默认的fastcgi进程响应的缓冲区是8K, 我们可以设置大点

在nginx.conf里, 加入:

fastcgi_buffers 8 128k

这表示设置fastcgi缓冲区为8×128k

当然如果您在进行某一项即时的操作, 可能需要nginx的超时参数调大点,例如设置成60秒:

send_timeout 60;

只是调整了这两个参数, 结果就是没有再显示那个超时, 可以说效果不错, 但是也
可能是由于其他的原因, 目前关于nginx的资料不是很多, 很多事情都需要长期的经验
累计才有结果, 期待您的发现哈!

5、 如何使用Nginx Proxy

朋友一台服务器运行tomcat 为8080端口,IP:192.168.1.2:8080,另一台机器
IP:192.168.1.8. 朋友想通过访问http://192.168.1.8即可访问tomcat服务.配置如下:

在192.168.1.8的nginx.conf上配置如下:

server {
    listen 80;
    server_name java.linuxtone.org
    location / {
        proxy_pass http://192.168.1.2:8080;
        include /usr/local/nginx/conf/proxy.conf;
    }
}

6、 如何关闭Nginx的LOG

access_log /dev/null;
error_log /dev/null;

十七、相关资源下载

1. nginx配置示例及脚本下载:
# wget http://www.linuxtone.org/lemp/scripts.tar.gz #此脚本范例定期更新.

【附】:
本文档定期更新,同时欢迎朋友多提宝贵意见,丰富nginx tips内容.
最新的文档发布.请朋友们关注: http://bbs.linuxtone.org

Tags: , ,

本文地址: http://www.21andy.com/blog/20100203/1609.html

posted @ 2011-05-27 17:00 MinisFox 阅读(590) 评论(0) 编辑
  2011年4月28日

门户网站架构Nginx+Apache+MySQL+PHP+Memcached+Squid

服务器的大用户量的承载方案

一、前言
二、编译安装
三、 安装MySQL、memcache
四、 安装Apache、PHP、eAccelerator、php-memcache
五、 安装Squid
六、后记

一、前言,准备工作

当前,LAMP开发模式是WEB开发的首选,如何搭建一个高效、可靠、稳定的WEB服务器一直是个热门主题,本文就是这个主题的一次尝试。
我们采用的架构图如下:
引用——– ———- ————- ——— ————
| 客户端 | ===> |负载均衡器| ===> |反向代理/缓存| ===> |WEB服务器| ===> |数据库服务器|
——– ———- ————- ——— ————
Nginx Squid Apache,PHP MySQL
eAccelerator/memcache准备工作:
引用服务器: Intel(R) Xeon(TM) CPU 3.00GHz * 2, 2GB mem, SCISC 硬盘
操作系统:CentOs4.4,内核版本2.6.9-22.ELsmp,gcc版本3.4.4
软件:
Apache 2.2.3(能使用MPM模式)
PHP 5.2.0(选用该版本是因为5.2.0的引擎相对更高效)
eAccelerator 0.9.5(加速PHP引擎,同时也可以加密PHP源程序)
memcache 1.2.0(用于高速缓存常用数据)
libevent 1.2a(memcache工作机制所需)
MySQL 5.0.27(选用二进制版本,省去编译工作)
Nginx 0.5.4(用做负载均衡器)
squid-2.6.STABLE6(做反向代理的同时提供专业缓存功能)

二、编译安装

 安装Nginx

1.) 安装
Nginx发音为[engine x],是由俄罗斯人Igor Sysoev建立的项目,基于BSD许可。据说他当初是F5的成员之一,英文主页:http://nginx.net。俄罗斯的一些大网站已经使用它超过两年多了,一直表现不凡。
Nginx的编译参数如下:
[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
在这里,需要说明一下,由于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
然后,修改 objs/Makefile 大概在908行的位置上,注释掉以下内容:
./configure –disable-shared
接下来,就可以正常执行 make 及 make install 了。
2.) 修改配置文件 /usr/local/server/nginx/conf/nginx.conf
以下是我的 nginx.conf 内容,仅供参考:
#运行用户
user nobody nobody;
#启动进程
worker_processes 2;
#全局错误日志及PID文件
error_log logs/error.log notice;
pid logs/nginx.pid;
#工作模式及连接数上限
events {
use epoll;
worker_connections 1024;
}
#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
#设定mime类型
include conf/mime.types;
default_type application/octet-stream;
#设定日志格式
log_format main ‘$remote_addr – $remote_user [$time_local] ‘
‘”$request” $status $bytes_sent ‘
‘”$http_referer” “$http_user_agent” ‘
‘”$gzip_ratio”‘;
log_format download ‘$remote_addr – $remote_user [$time_local] ‘
‘”$request” $status $bytes_sent ‘
‘”$http_referer” “$http_user_agent” ‘
‘”$http_range” “$sent_http_content_range”‘;
#设定请求缓冲
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
#开启gzip模块
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
output_buffers 1 32k;
postpone_output 1460;
#设定access log
access_log logs/access.log main;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
#设定负载均衡的服务器列表
upstream mysvr {
#weigth参数表示权值,权值越高被分配到的几率越大
#本机上的Squid开启3128端口
server 192.168.8.1:3128 weight=5;
server 192.168.8.2:80 weight=1;
server 192.168.8.3:80 weight=6;
}
#设定虚拟主机
server {
listen 80;
server_name 192.168.8.1 www.enew.com.cn;
charset gb2312;
#设定本虚拟主机的访问日志
access_log logs/www.enew.com.cn.access.log main;
#如果访问 /img/*, /js/*, /css/* 资源,则直接取本地文件,不通过squid
#如果这些文件较多,不推荐这种方式,因为通过squid的缓存效果更好
location ~ ^/(img|js|css)/ {
root /data3/Html;
expires 24h;
}
#对 “/” 启用负载均衡
location / {
proxy_pass http://mysvr;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
#设定查看Nginx状态的地址
location /NginxStatus {
stub_status on;
access_log on;
auth_basic “NginxStatus”;
auth_basic_user_file conf/htpasswd;
}
}
}
备注:conf/htpasswd 文件的内容用 apache 提供的 htpasswd 工具来产生即可,内容大致如下:
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运行到当前时间接受到的总请求数,如果快达到了上限,就需要加大上限值了。
第四行是Nginx的队列状态

安装MySQL、memcache

1.) 安装MySQL,步骤如下:
[root@localhost]#tar zxf mysql-standard-5.0.27-linux-i686.tar.gz -C /usr/local/server
[root@localhost]#mv /usr/local/server/mysql-standard-5.0.27-linux-i686 /usr/local/server/mysql
[root@localhost]#cd /usr/local/server/mysql
[root@localhost]#./scripts/mysql_install_db –basedir=/usr/local/server/mysql \
–datadir=/usr/local/server/mysql/data –user=nobody
[root@localhost]#cp /usr/local/server/mysql/support-files/my-large.cnf \
/usr/local/server/mysql/data/my.cnf
2.) 修改 MySQL 配置,增加部分优化参数,如下:
[root@localhost]#vi /usr/local/server/mysql/data/my.cnf
主要内容如下:
[mysqld]
basedir = /usr/local/server/mysql
datadir = /usr/local/server/mysql/data
user = nobody
port = 3306
socket = /tmp/mysql.sock
wait_timeout = 30
long_query_time=1
#log-queries-not-using-indexes = TRUE
log-slow-queries=/usr/local/server/mysql/slow.log
log-error = /usr/local/server/mysql/error.log
external-locking = FALSE
key_buffer_size = 512M
back_log = 400
table_cache = 512
sort_buffer_size = 2M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 32
query_cache_limit = 2M
query_cache_size = 64M
thread_concurrency = 4
thread_stack = 128K
tmp_table_size = 64M
binlog_cache_size = 2M
max_binlog_size = 128M
max_binlog_cache_size = 512M
max_relay_log_size = 128M
bulk_insert_buffer_size = 8M
myisam_repair_threads = 1
skip-bdb
#如果不需要使用innodb就关闭该选项
#skip-innodb
innodb_data_home_dir = /usr/local/server/mysql/data/
innodb_data_file_path = ibdata1:256M;ibdata2:256M:autoextend
innodb_log_group_home_dir = /usr/local/server/mysql/data/
innodb_log_arch_dir = /usr/local/server/mysql/data/
innodb_buffer_pool_size = 512M
innodb_additional_mem_pool_size = 8M
innodb_log_file_size = 128M
innodb_log_buffer_size = 8M
innodb_lock_wait_timeout = 50
innodb_flush_log_at_trx_commit = 2
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_log_files_in_group = 3
以上配置参数请根据具体的需要稍作修改。运行以下命令即可启动 MySQL 服务器:
/usr/local/server/mysql/bin/mysqld_safe \
–defaults-file=/usr/local/server/mysql/data/my.cnf &
由于 MySQL 不是安装在标准目录下,因此必须要修改 mysqld_safe 中的 my_print_defaults 文件所在位置,才能通过
mysqld_safe 来启动 MySQL 服务器。
3.) memcache + libevent 安装编译安装:
[root@localhost]#cd libevent-1.2a
[root@localhost]#./configure –prefix=/usr/ && make && make install
[root@localhost]#cd ../memcached-1.2.0
[root@localhost]#./configure –prefix=/usr/local/server/memcached –with-libevent=/usr/
[root@localhost]#make && make install
备注:如果 libevent 不是安装在 /usr 目录下,那么需要把 libevent-1.2a.so.1 拷贝/链接到 /usr/lib 中,否则
memcached 无法正常加载。运行以下命令来启动 memcached:
[root@localhost]#/usr/local/server/memcached/bin/memcached \
-l 192.168.8.1 -d -p 10000 -u nobody -m 128
表示用 daemon 的方式启动 memcached,监听在 192.168.8.1 的 10000 端口上,运行用户为 nobody,为其分配
128MB 的内存。

安装Apache、PHP、eAccelerator、php-memcache

四、) 安装Apache、PHP、eAccelerator、php-memcache由于Apache
2下的php静态方式编译十分麻烦,因此在这里采用动态模块(DSO)方式。1.) 安装Apache 2.2.3
[root@localhost]#./configure –prefix=/usr/local/server/apache –disable-userdir –disable-actions \
–disable-negotiation –disable-autoindex –disable-filter –disable-include –disable-status \
–disable-asis –disable-auth –disable-authn-default –disable-authn-file –disable-authz-groupfile \
–disable-authz-host –disable-authz-default –disable-authz-user –disable-userdir \
–enable-expires –enable-module=so
备注:在这里,取消了一些不必要的模块,如果你需要用到这些模块,那么请去掉部分参数。
2.) 安装PHP 5.2.0
[root@localhost]#./configure –prefix=/usr/local/server/php –with-mysql \
–with-apxs2=/usr/local/server/apache/bin/apxs –with-freetype-dir=/usr/ –with-png-dir=/usr/ \
–with-gd=/usr/ –with-jpeg-dir=/usr/ –with-zlib –enable-magic-quotes –with-iconv \
–without-sqlite –without-pdo-sqlite –with-pdo-mysql –disable-dom –disable-simplexml \
–enable-roxen-zts
[root@localhost]#make && make install
备注:如果不需要gd或者pdo等模块,请自行去掉。
3.) 安装eAccelerator-0.9.5
[root@localhost]#cd eAccelerator-0.9.5
[root@localhost]#export PHP_PREFIX=/usr/local/server/php
[root@localhost]#$PHP_PREFIX/bin/phpize
[root@localhost]#./configure –enable-eaccelerator=shared –with-php-config=$PHP_PREFIX/bin/php-config
[root@localhost]#make && make install
4.) 安装memcache模块
[root@localhost]#cd memcache-2.1.0
[root@localhost]#export PHP_PREFIX=/usr/local/server/php
[root@localhost]#$PHP_PREFIX/bin/phpize
[root@localhost]#./configure –enable-eaccelerator=shared –with-php-config=$PHP_PREFIX/bin/php-config
[root@localhost]#make && make install
5.) 修改 php.ini 配置然后修改 php.ini,修改/加入类似以下内容:
extension_dir = “/usr/local/server/php/lib/”
extension=”eaccelerator.so”
eaccelerator.shm_size=”32″ ;设定eaccelerator的共享内存为32MB
eaccelerator.cache_dir=”/usr/local/server/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=”*.php”
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”0″
eaccelerator.shm_prune_period=”3600″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
eaccelerator.log_file = “/usr/local/server/apache/logs/eaccelerator_log”
eaccelerator.allowed_admin_path = “/usr/local/server/apache/htdocs/ea_admin”
extension=”memcache.so”
在这里,最好是在apache的配置中增加默认文件类型的cache机制,即利用apache的expires模块,新增类似如下几行:
ExpiresActive On
ExpiresByType text/html “access plus 10 minutes”
ExpiresByType text/css “access plus 1 day”
ExpiresByType image/jpg “access 1 month”
ExpiresByType image/gif “access 1 month”
ExpiresByType image/jpg “access 1 month”
ExpiresByType application/x-shockwave-flash “access plus 3 day”
这么设置是由于我的这些静态文件通常很少更新,因此我选择的是”access”规则,如果更新相对比较频繁,可以改用”modification”规则;或者也可以用”access”规则,但是在文件更新的时候,执行一下”touch”命令,把文件的时间刷新一下即可。

 安装Squid

五、) 安装Squid
[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
[root@localhost]#make && make install
或使用如下安装方法:
[root@localhost]#yum install squid
如果是2.6的内核,才能支持epoll的IO模式,旧版本的内核则只能选择poll或其他模式了;另外,记得带上支持大文件的选项,否则在access
log等文件达到2G的时候就会报错。设定 squid 的配置大概如下内容:
#设定缓存目录为 /var/cache1 和 /var/lib/squid,每次处理缓存大小为128MB,当缓存空间使用达到95%时
#新的内容将取代旧的而不直接添加到目录中,直到空间又下降到90%才停止这一活动
#/var/cache1 最大1024MB,/var/lib/squid 最大 5000MB,都是 16*256 级子目录
cache_dir aufs /var/cache1 1024 16 256
cache_dir aufs /var/lib/squid 5000 16 256
cache_mem 128 MB
cache_swap_low 90
cache_swap_high 95
#设置存储策略等
maximum_object_size 4096 KB
minimum_object_size 0 KB
maximum_object_size_in_memory 80 KB
ipcache_size 1024
ipcache_low 90
ipcache_high 95
cache_replacement_policy lru
memory_replacement_policy lru
#设置超时策略
forward_timeout 20 seconds
connect_timeout 15 seconds
read_timeout 3 minutes
request_timeout 1 minutes
persistent_request_timeout 15 seconds
client_lifetime 15 minutes
shutdown_lifetime 5 seconds
negative_ttl 10 seconds
#限制一个ip最大只能有16个连接
acl OverConnLimit maxconn 16
http_access deny OverConnLimit
#限制baidu spider访问
#acl AntiBaidu req_header User-Agent Baiduspider
#http_access deny AntiBaidu
#常规设置
visible_hostname cache.enew.com
cache_mgr webmaster@enew.com
client_persistent_connections off
server_persistent_connections on
cache_effective_user nobody
cache_effective_group nobody
tcp_recv_bufsize 65535 bytes
half_closed_clients off
#设定不缓存的规则
hierarchy_stoplist cgi-bin
acl QUERY urlpath_regex cgi-bin
cache deny QUERY
#不要相信ETag 因为有gzip
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
#设置access log,并且令其格式和apache的格式一样,方便awstats分析
emulate_httpd_log on
logformat apache %>a %ui %un [%tl] “%rm %ru HTTP/%rv” %Hs %
初始化和启动squid
[root@localhost]#/usr/local/server/squid/sbin/squid -z
[root@localhost]#/usr/local/server/squid/sbin/squid
第一条命令是先初始化squid缓存哈希子目录,只需执行一次即可。

六、后记

六、后记一、)想要启用squid所需的改变想要更好的利用squid的cache功能,不是把它启用了就可以的,我们需要做以下几个调整:
1、启用apache的 mod_expires 模块,修改 httpd.conf,加入以下内容:
#expiresdefault “modification plus 2 weeks”expiresactive
onexpiresbytype text/html “access plus 10 minutes”expiresbytype
image/gif “modification plus 1 month”expiresbytype image/jpeg “modification
plus 1 month”expiresbytype image/png “modification plus 1
month”expiresbytype text/css “access plus 1 day”expiresbytype
application/x-shockwave-flash “access plus 3 day”
以上配置的作用是规定各种类型文件的cache规则,对那些图片/flash等静态文件总是cache起来,可根据各自的需要做适当调整。
2、修改 php.ini 配置,如下:
session.cache_limiter = nocache
以上配置的作用是默认取消php中的cache功能,避免不正常的cache产生。
3、修改应用程序例如,有一个php程序页面static.php,它存放着某些查询数据库后的结果,并且数据更新并不频繁,于是,我们就可以考虑对其cache。只需在static.php中加入类似如下代码:
header(‘Cache-Control: max-age=86400
,must-revalidate’);header(‘Pragma:’);header(‘Last-Modified: ‘ .
gmdate(‘D, d M Y H:i:s’) . ‘ GMT’ );header(“Expires: ” .gmdate (‘D, d M Y
H:i:s’, time() + ’86400′ ). ‘ GMT’);
以上代码的意思是,输出一个http头部信息,让squid知道本页面默认缓存时长为一天。
二、)squidclient简要介绍
*取得squid运行状态信息: squidclient -p 80 mgr:info
*取得squid内存使用情况: squidclient -p 80 mgr:mem
*取得squid已经缓存的列表: squidclient -p 80 mgr:objects. use it carefully,it may crash
*取得squid的磁盘使用情况: squidclient -p 80 mgr:diskd
*强制更新某个url:squidclient -p 80 -m PURGE http://www.enew.com.cn/static.php
*更多的请查看:squidclient-h 或者 squidclient -p 80 mgr:

原文地址:http://blog.csdn.net/rushcc2006/archive/2009/11/11/4796892.aspx

posted @ 2011-04-28 18:30 MinisFox 阅读(52) 评论(0) 编辑
  2011年2月24日
摘要: 一、Web服务器安全 PHP其实不过是Web服务器的一个模块功能,所以首先要保证Web服务器的安全。当然Web服务器要安全又必须是先保证系统安全,这样就扯远了,无穷无尽。PHP可以和各种Web服务器结合,这里也只讨论Apache。非常建议以chroot方式安装启动Apache,这样即使Apache和PHP及其脚本出现漏洞,受影响的也只有这个禁锢的系统,不会危害实际系统。但是使用chroot的Apache后,给应用也会带来一定的麻烦,比如连接mysql时必须用127.0.0.1地址使用tcp连接而不能用localhost实现socket连接,这在效率上会稍微差一点。还有mail函数发送邮件也是个阅读全文
posted @ 2011-02-24 11:13 MinisFox 阅读(38) 评论(0) 编辑
摘要: 之所以翻译这篇文章,是因为目前关于CGI安全性的文章都是拿Perl作为例子,而专门介绍ASP,PHP或者JSP安全性的文章则很少。Shaun Clowes的这篇文章比较全面地介绍了PHP的安全问题,原文可以http://www.securereality.com.au/studyinscarlet.txt找到。 由于原文比较长,而且有相当一部分是介绍文章的背景或PHP的基础知识,没有涉及到PHP安全方面的内容,因此我没有翻译。如果你想了解这方面的知识,请参考原文。 文章主要从全局变量,远程文件,文件上载,库文件,Session文件,数据类型和容易出错的函数这几个方面分析了PHP的安全性,并且.阅读全文
posted @ 2011-02-24 10:54 MinisFox 阅读(18) 评论(0) 编辑
  2010年8月20日
摘要: 什么是索引?索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存。如果没有索引,执行查询时MySQL必须从第一个记录开始扫描整个表的所有记录,直至找到符合要求的记录。表里面的记录数量越多,这个操作的代价就越高。如果作为搜索条件的列上已经创建了索引,MySQL无需扫描任何记录即可迅速得到目标记录所在的位置。如果表有1000个记录,通过索引查找记录至少要比顺序扫描记录快100...阅读全文
posted @ 2010-08-20 15:15 MinisFox 阅读(15) 评论(0) 编辑
  2010年8月2日
摘要: 一、 如何建立多用户  提醒大家一句,别一直使用root用户,因为root用户在系统中有着至高无上的权力,一不小心就可能破坏系统。比如我们想删除/temp目录下的文件却将命令不小心输成“rm / temp(在‘/’后多了一个空格)”,那么就极可能删去根目录下的所有文件。再者,“Linux是一个真正意义上的多任务、多用户系统”,...阅读全文
posted @ 2010-08-02 11:02 MinisFox 阅读(51) 评论(0) 编辑
<2012年2月>
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910

昵称:MinisFox
园龄:5年2个月
粉丝:0
关注:0

搜索

 
 

常用链接

随笔分类

随笔档案

文章分类

最新评论

阅读排行榜

评论排行榜

推荐排行榜