[root@localhost log]# cat /var/log/secure|more
Mar 16 00:00:01 localhost crond[11717]: pam_limits(crond:session): unknown limit item 'noproc'
Mar 16 00:00:01 localhost crond[11718]: pam_limits(crond:session): unknown limit item 'noproc'
Mar 16 00:00:01 localhost crond[11717]: pam_limits(crond:session): unknown limit item 'noproc'
Mar 16 00:00:01 localhost crond[11718]: pam_limits(crond:session): unknown limit item 'noproc'
Mar 16 00:01:01 localhost crond[11739]: pam_limits(crond:session): unknown limit item 'noproc'
Mar 16 00:01:01 localhost crond[11738]: pam_limits(crond:session): unknown limit item 'noproc'
Mar 16 00:01:01 localhost crond[11739]: pam_limits(crond:session): unknown limit item 'noproc'
Mar 16 00:01:01 localhost crond[11738]: pam_limits(crond:session): unknown limit item 'noproc'
Mar 16 00:02:01 localhost crond[11786]: pam_limits(crond:session): unknown limit item 'noproc'
Mar 16 00:02:01 localhost crond[11786]: pam_limits(crond:session): unknown limit item 'noproc'
Mar 16 00:03:01 localhost crond[11808]: pam_limits(crond:session): unknown limit item 'noproc'
Mar 16 00:03:01 localhost crond[11808]: pam_limits(crond:session): unknown limit item 'noproc'
Mar 16 00:04:01 localhost crond[11833]: pam_limits(crond:session): unknown limit item 'noproc'
几乎每分钟都有一到两个,看错误信息应该和limits.conf有关,执行 ulimit -n 看一下当前系统设置的是什么数值。
[root@localhost log]# ulimit -n
65535
打开/etc/security/limits.conf配置文件发现问题
接下来我们看看配置文件中注释是怎么写的,底部画红线的部分
* soft noproc 65535
* hard noproc 65535
应该改为
* soft nproc 65535
* hard nproc 65535
才对,至此该错误解决。有碰到和我一样错误的朋友不妨看一下limits.conf文件是否也是这样写的。
一、PHP加速器介绍
PHP加速器是一个为了提高PHP执行效率,从而缓存起PHP的操作码,这样PHP后面执行就不用解析转换了,可以直接调用PHP操作码,这样速度上就提高了不少。
Apache中使用mod_php的请求、响应执行流程:
1、Apache接收请求。
2、Apache传递请求给mod_php。
3、mod_php定位磁盘文件,并加载到内存中。
4、mod_php编译源代码成为opcode树。
5、mod_php执行opcode树。
PHP加速器相应的就是第四步,它的目的就是防止PHP每次请求都重复编译PHP代码,因为在高访问量的网站上,大量的编译往往没有执行速度快呢?所以这里面有个瓶颈就是PHP的重复编译既影响了速度又加载了服务器负载,为了解决此问题,PHP加速器就这样诞生了。
二、PHP加速器安装与配置
1、安装配置APC
APC全称是Alternative PHP Cache,官方翻译叫”可选PHP缓存”,它是PHP PECL中的一个扩展,好像是facebook在使用它,下面开始安装(ubuntu环境):
#wget http://pecl.php.net/get/APC-3.0.19.tgz
#tar xvzf APC-3.0.19.tgz
#cd APC-3.0.19/APC-3.0.19
#/usr/local/php/bin/phpize
#./configure –enable-apc –enable-apc-mmap –with-php-config=/usr/local/php/bin/php-config
#make
#make install
下面我们再配置APC,因为我的PECL扩展路径改变了,所以我得移动下编译好的文件:
#mv /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/apc.so /usr/local/php/lib/php/extensions/PECL
然后我们再编辑php.ini文件进行配置,请把下面的代码加入到php.ini中即可:
extension_dir = "/usr/local/php/lib/php/extensions/PECL"
extension = apc.so
; APC
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 64
apc.optimization = 1
apc.num_files_hint = 0
apc.ttl = 0
apc.gc_ttl = 3600
apc.cache_by_default = on
这样重启apache就会在phpinfo()信息中显示。
2、安装配置eAccelerator
eAccelerator的前身其实是truck-mmcache,因为开发truk-mmcache的人被Zend给招安了,所以开发eAccelerator的人继承了truk-mmcache的一些特性,设计出eAccelerator加速器。安装如下:
#wget http://jaist.dl.sourceforge.net/sourceforge/eaccelerator/eaccelerator-0.9.5.tar.bz2
#tar -jxf eaccelerator-0.9.5.tar.bz2
#cd eaccelerator-0.9.5
#/usr/local/php/bin/phpize
#./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php/bin/php-config
#make
#sudo make install
#sudo mv /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so /usr/local/php/lib/php/extensions/PECL
将下面代码加入php.ini文件中
extension = eaccelerator.so
; eAccelerator
eaccelerator.shm_size = "16"
eaccelerator.cache_dir = "/tmp/eaccelerator"
eaccelerator.enable = "1"
eaccelerator.optimizer = "1"
eaccelerator.check_mtime = "1"
eaccelerator.debug = "0"
eaccelerator.filter = ""
eaccelerator.shm_max = "0"
eaccelerator.shm_ttl = "0"
eaccelerator.prune_period = "0"
eaccelerator.shm_only = "0"
eaccelerator.compress = "1"
eaccelerator.compress_level = "9"
创建缓存目录,重启apache
# mkdir /tmp/eaccelerator
#chmod 777 /tmp/eaccelerator
#/usr/local/apache/apachectl restart
在phpinfo()检查是否安装成功.
3、安装配置XCache
XCache作为国人自己开发的东西,做小菜鸟的我也感到骄傲,而且XCache无论在速度还是性能上都做的不错。下面就赶紧让我们品尝它吧!
#wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
#tar xvzf xcache-1.2.2.tar.gz
#cd xcache-1.2.2
#/usr/local/php/bin/phpize
#./configure –enable-xcache –enable-xcache-coverager –with-php-config=/usr/local/php/php-config
#make
#make install
#mv /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so /usr/local/php/lib/php/extensions/PECL
在php.ini添加配置信息:
extension = xcache.so
; xcache
xcache.admin.user = "admin"
xcache.admin.pass = "(执行) echo ’(你的密码)’|md5sum(得出的密文)"
;
xcache.size = 24M
xcache.shm_scheme = "mmap"
xcache.count = 2
xcache.slots = 8k
xcache.ttl = 0
xcache.gc_interval = 0
xcache.var_size = 8M
xcache.var_count = 1
xcache.var_slots = 8k
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
xcache.mmap_path = "/tmp/xcache"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
;
xcache.coverager = On
xcache.coveragedump_directory = ""
创建缓存目录,重启apache
#mkdir /tmp/xcache
#chmod 777 /tmp/xcache
#/usr/local/apache/bin/apachectl restart
去查看phpinfo()信息吧!
三、PHP加速器测试
1、测试环境
硬件: AMD Athlon 64 X2 Dual Core Processor 4400+ @ 2.2GHz CPU, 2GB 内存. 160GB SATA 硬盘
软件: Linux Ubuntu server Gutsy 7.10, Apache 2.2.4, MySQL 5.0.45 和 PHP 5.2.3
测试指令: ab -c5 -n3000 http://example.com/ (我们使用的是Apache Benchmark (ab) 工具,并发连接为5,3000次请求)
2、测试结果
无任何加速器:
Document Path: /
Document Length: 21757 bytes
Concurrency Level: 5
Time taken for tests: 288.255212 seconds
Complete requests: 3000
Failed requests: 0
Write errors: 0
Total transferred: 66777000 bytes
HTML transferred: 65271000 bytes
Requests per second: 10.41 [#/sec] (mean)
Time per request: 480.425 [ms] (mean)
Time per request: 96.085 [ms] (mean, across all concurrent requests)
Transfer rate: 226.23 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 19
Processing: 181 479 186.0 444 1822
Waiting: 166 461 184.7 427 1708
Total: 181 479 186.0 444 1822
Percentage of the requests served within a certain time (ms)
50% 444
66% 525
75% 577
80% 619
90% 732
95% 819
98% 946
99% 1012
100% 1822 (longest request)
APC加速器:
Document Path: /
Document Length: 21757 bytes
Concurrency Level: 5
Time taken for tests: 98.530068 seconds
Complete requests: 3000
Failed requests: 0
Write errors: 0
Total transferred: 66777000 bytes
HTML transferred: 65271000 bytes
Requests per second: 30.45 [#/sec] (mean)
Time per request: 164.217 [ms] (mean)
Time per request: 32.843 [ms] (mean, across all concurrent requests)
Transfer rate: 661.84 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 2
Processing: 58 163 71.2 155 2452
Waiting: 53 158 69.6 150 2329
Total: 58 163 71.2 155 2452
Percentage of the requests served within a certain time (ms)
50% 155
66% 178
75% 193
80% 204
90% 235
95% 258
98% 285
99% 302
100% 2452 (longest request)
eAccelerator加速器:
Document Path: /
Document Length: 21757 bytes
Concurrency Level: 5
Time taken for tests: 95.983986 seconds
Complete requests: 3000
Failed requests: 0
Write errors: 0
Total transferred: 66777000 bytes
HTML transferred: 65271000 bytes
Requests per second: 31.26 [#/sec] (mean)
Time per request: 159.973 [ms] (mean)
Time per request: 31.995 [ms] (mean, across all concurrent requests)
Transfer rate: 679.39 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 3
Processing: 57 159 91.3 148 3830
Waiting: 50 152 89.8 142 3704
Total: 57 159 91.3 148 3830
Percentage of the requests served within a certain time (ms)
50% 148
66% 174
75% 193
80% 205
90% 239
95% 263
98% 289
99% 309
100% 3830 (longest request)
XCache加速器:
Document Path: /
Document Length: 21757 bytes
Concurrency Level: 5
Time taken for tests: 99.76300 seconds
Complete requests: 3000
Failed requests: 0
Write errors: 0
Total transferred: 66777000 bytes
HTML transferred: 65271000 bytes
Requests per second: 30.28 [#/sec] (mean)
Time per request: 165.127 [ms] (mean)
Time per request: 33.025 [ms] (mean, across all concurrent requests)
Transfer rate: 658.19 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 2
Processing: 59 164 83.4 155 3367
Waiting: 52 156 66.4 148 1802
Total: 59 164 83.4 155 3367
Percentage of the requests served within a certain time (ms)
50% 155
66% 178
75% 196
80% 206
90% 237
95% 263
98% 287
99% 305
100% 3367 (longest request)
3、结果摘要
请求时间(秒) | 单次请求时间(毫秒) | 最大内存占用(MB) | 最小内存占用(MB) | |
None | 10.41 | 96.08 | 24 | 24 |
APC | 30.45 | 32.84 | 21 | 21 |
eAccelerator | 31.26 | 31.99 | 23 | 18 |
XCache | 30.28 | 33.02 | 29 | 19 |
四、PHP加速器比较结果总结
1、通过测试得出eAccelerator在请求时间和内存占用综合方面是最好的。
2、通过测试得出使用加速器比无加速器在请求时间快了3倍左右。
3、通过各个官方观察,XCache是更新最快的,这也说明最有发展的。
以上是总结结果,你也许会问我到底用那个加速器好呢?我只能告诉你,首先,用一定比不用好,其次每个加速器还有一些可以调优的参数,所以要根据你的系统环境而定,然后,我个人觉得你可以详细研究下eAccelerator和XCache,这两款潜力还是很大的,最后我从比较专业的测试网站搞了一张结果图:
fastcgi.conf
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param PATH_INFO $path_info;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
#fastcgi_param REDIRECT_STATUS 200;
nginx.conf
user nginx nginx;
worker_processes 16;
error_log logs/nginx_error.log crit;
pid logs/nginx.pid;
events {
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
log_format weblog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log weblog;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_proxied any;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
include /usr/local/nginx/conf/test.conf;
}
test.conf
server
{
listen 80;
server_name www.test.com;
access_log logs/test.log;
root /home/wwwroot/ci;
index index.php index.html index.htm;
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ \.php {
set $real_script_name $fastcgi_script_name;
set $path_info "";
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include fastcgi.conf;
}
}
以上配置可以支持ThinkPHP,CI,ZF等等框架
下面是NGINX官方对于pathinfo提供的解决方法:
fastcgi_split_path_info
syntax: fastcgi_split_path_info regex
context: location
version: ≥ 0.7.31
This directive allows the setting of the SCRIPT_FILENAME (SCRIPT_NAME) and PATH_INFO variables of the CGI specification. The regex consists of two groups:
path to the script that will handle the request — corresponding to $fastcgi_script_name.
the value of the parameter to be given to the script — corresponding to the $fastcgi_path_info.
Here's an example. The script show.php receives as argument the string article/0001. The following configuration will handle path splitting properly:
location ~ ^.+\.php {
(...)
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
(...)
}
Requesting /show.php/article/0001 sets SCRIPT_FILENAME to /path/to/php/show.php and PATH_INFO to /article/0001.
1、安装在根目录下:
# BEGIN YOURLS
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourls-loader.php [L]
# END YOURLS
2、安装在子目录下
# BEGIN YOURLS
RewriteEngine On
RewriteBase /somedir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /somedir/yourls-loader.php [L]
# END YOURLS
3、使用非带www的域名
# BEGIN WithoutWWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yourls\.org$ [NC]
RewriteRule ^(.*)$ http://yourls.org/$1 [R=301,L]
# END WithoutWWW
二、Nginx YOURLS Rewrite规则
1、安装在根目录下
location /
{
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/([0-9A-Za-z]+)/?$ /yourls-go.php?id=$1 last;
}
rewrite ^/([0-9A-Za-z]+)\+/?$ /yourls-infos.php?id=$1 last;
rewrite ^/([0-9A-Za-z]+)\+all/?$ /yourls-infos.php?id=$1&all=1 last;
}
2、安装在子目录下
location /dir/
{
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/dir/([0-9A-Za-z]+)/?$ /url/yourls-go.php?id=$1 last;
}
rewrite ^/dir/([0-9A-Za-z]+)\+/?$ /url/yourls-infos.php?id=$1 last;
rewrite ^/dir/([0-9A-Za-z]+)\+all/?$ /url/yourls-infos.php?id=$1&all=1 last;
}
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz
wget http://downloads.sourceforge.net/project/htop/htop/1.0.1/htop-1.0.1.tar.gz
二、编译安装
tar xvfz ncurses-5.9.tar.gz
cd ncurses-5.9
./configure
make
make install
tar xzvf htop-1.0.1.tar.gz
cd htop-1.0.1
./configure
make
make install