« »
2007-12-14Lighttpd

84

Lighttpd+Mysql+Php(FAST-CGI)+eAccelerator

一:基本安装

A:Lighttpd+Mysql+Php(FAST-CGI)+eAccelerator

安装lighttpd前需要预装下列软件包:

pcre

zlib

pcre-devel

zlib-devel

1. 安装配置MYSQL服务器

mysql 安装:
$ tar zxvf mysql-5.0.37.tar.gz
$ cd mysql-5.0.37
# groupadd mysql          

# useradd -g mysql mysql  
# ./configure –prefix=/Data/apps/mysql

# make
# make install
# cp support-files/my-medium.cnf /etc/my.cnf
# cd /Data/appsl/mysql
# bin/mysql_install_db –user=mysql
# chown -R root .
# chown -R mysql var
# chgrp -R mysql .

# bin/mysqld_safe –user=mysql &

2.安装配置lighttpd

2.1 首先创建运行lighttpd的用户和组

# groupadd lighttpd

# useradd -g lighttpd -s /sbin/nologin -d /dev/null lighttpd

2.2 开始安装lighttpd

# wget http://www.lighttpd.net/download/lighttpd-1.4.15.tar.gz

# tar zxvf lighttpd-1.4.15.tar.gz

# cd lighttpd-1.4.15

# ./configure –prefix=/Data/apps/lighttpd

# make

# make install

# mkdir /Data/apps/lighttpd/conf

# mkdir /Data/apps/lighttpd/log

# mv ./doc/lighttpd.conf /Data/apps/lighttpd/conf/

# cp ./doc/rc.lighttpd.redhat /etc/init.d/lighttpd[可忽略]

# cp ./doc/spawn-php.sh /Data/apps/lighttpd/bin/

# chown -R lighttpd:lighttpd /Data/apps/lighttpd

2.3 配置lighttpd

# vi /Data/apps/lighttpd/conf/lighttpd.conf

================+===============+================

server.modules              = (

                                “mod_rewrite”,

                                “mod_redirect”,

                                “mod_access”,

                                “mod_fastcgi”,

                                “mod_compress”,

                                “mod_accesslog” )

#$HTTP["url"] =~ “\.pdf$” {

#server.range-requests = “disable”

#}

server.document-root = “/Data/webapps”

server.errorlog  = “/Data/apps/lighttpd/log/lighttpd.error.log”

accesslog.filename = “/Data/apps/lighttpd/log/access.log”

server.pid-file            = “/var/run/lighttpd.pid”

server.username = “lighttpd”

server.groupname = “lighttpd”

compress.cache-dir         = “/tmp”

compress.filetype          = (“text/plain”, “text/html”)

fastcgi.server             = ( “.php” =>

                               ( “localhost” =>

                                (

                                   “socket” => “/tmp/php-fastcgi.socket”,

                                   “bin-path” => “/Data/apps/php-fcgi/bin/php”

                                 )

                               )

                            )

================+===============+================

3. 安装配置PHP(FAST-CGI)

3.1 下载安装PHP

# wget http://mirrors.easynews.com/php/php-5.2.1.tar.gz

# tar zxvf php-5.2.1.tar.gz

# cd php-5.2.1

# ./configure \

–prefix=/Data/apps/php-fcgi \

–enable-fastcgi  \

–enable-zend-multibyte \

–with-config-file-path=/Data/apps/php-fcgi/conf \

–enable-discard-path \

–enable-force-cgi-redirect \

           –with-mysql=/Data/apps/mysql \

           –enable-mbstring \

           –with-curl \

           –disable-debug \

           –enable-inline-optimization -q \

           –with-jpeg-dir=/usr/local/ \

           –with-png-dir \

           –enable-thread-safety \

           –enable-ctype \

           –with-bz2 \

           –with-zlib \

           –with-gd \

           –with-kerberos \

           –with-gettext \

           –with-iconv \

           –enable-gd-native-ttf \

           –enable-sockets

# make

# make install

#mkdir /.Data/apps/php-fcgi/conf

# cp php.ini-dist /Data/apps/php-fcgi/conf/php.ini

4. 安装配置EAccelerator(PHP加速器)

4.1 下载安装EAccelerator

# wget http://jaist.dl.sourceforge.net/sourceforge/eaccelerator/eaccelerator-0.9.5.tar.bz2

# tar jxvf eaccelerator-0.9.5.tar.bz2

# cd eaccelerator-0.9.5

# export PHP_PREFIX=”/Data/apps/php-fcgi”

# $PHP_PREFIX/bin/phpize

# ./configure \

–prefix=/Data/apps/php-fcgi \

–enable-fastcgi  \

–enable-zend-multibyte \

–with-config-file-path=/Data/apps/php-fcgi/conf \

–enable-discard-path \

–enable-force-cgi-redirect \

           –with-mysql=/Data/apps/mysql \

           –enable-mbstring \

           –with-curl \

           –disable-debug \

           –enable-inline-optimization -q \

           –with-jpeg-dir=/usr/local/ \

           –with-png-dir \

           –enable-thread-safety \

           –enable-ctype \

           –with-bz2 \

           –with-zlib \

           –with-gd \

           –with-kerberos \

           –with-gettext \

           –with-iconv \

           –enable-gd-native-ttf \

           –enable-sockets \

–enable-eaccelerator=shared \

–with-php-config=$PHP_PREFIX/bin/php-config

# make

# make install

# cat eaccelerator.ini >> /Data/apps/php-fcgi/conf/php.ini

EAccelerator会安装在/Data/apps/php-fcgi/lib/php/extensions/no-debug-non-zts-20060613这个目录中

4.2 配置PHP变量

# vi /Data/apps/php-fcgi/conf/php.ini

================+===============+================

cgi.fix_pathinfo = 1

extension_dir = “/Data/apps/php-fcgi/lib/php/extensions/no-debug-non-zts-20060613/”

zlib.output_compression = On

cgi.fix_pathinfo=1

eaccelerator.cache_dir= “/tmp/eaccelerator”

zend_extension=”/Data/apps/php-fcgi/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”

eaccelerator.shm_size = “0″

eaccelerator.enable = “1″

eaccelerator.optimizer = “1″

eaccelerator.debug = 0

eaccelerator.log_file = ” /var/log/httpd/eaccelerator_log ”

eaccelerator.name_space = “”

eaccelerator.check_mtime = “1″

eaccelerator.filter = “”

eaccelerator.shm_max = “0″

eaccelerator.shm_ttl = “0″

eaccelerator.shm_prune_period = “0″

eaccelerator.shm_only = “0″

eaccelerator.compress = “1″

eaccelerator.compress_level = “9″

eaccelerator.keys     = “shm_and_disk”

eaccelerator.sessions = “shm_and_disk”

eaccelerator.content  = “shm_and_disk”

eaccelerator.admin.name=”yourusername”

eaccelerator.admin.password=”yourpassword”

================+===============+================

////创建缓存目录

mkdir /tmp/eaccelerator

chmod 0777 /tmp/eaccelerator

4.3 初始化PHP with FastCGI

# vi /Data/apps/lighttpd/bin/spawn-php.sh

================+===============+================

SPAWNFCGI=”/Data/apps/lighttpd/bin/spawn-fcgi”

FCGIPROGRAM=”/Data/apps/php-fcgi/bin/php”

USERID=lighttpd

GROUPID=lighttpd

================+===============+================

# /Data/apps/lighttpd/bin/spawn-php.sh

5. 启动脚本

添加以下脚本至启动项

/Data/apps/mysql/bin/mysqld_safe –user=mysql &

/Data/apps/lighttpd/bin/spawn-php.sh

/Data/apps/lighttpd/sbin/lighttpd -f /Data/apps/lighttpd/conf/lighttpd.conf

B:Apache+MYSQL+PHP+Zend Optimizer

请参阅

http://longrujun.name/blogs/longrujun/archive/2006/08/15/_167FD18B895BC588_apache2_2B00_php5_2B00_mysql4_2B00_ZendOptimizer_2B00_Cronolog_807B136687656368_.aspx

二: 测试
不考虑数据库瓶颈/文件IO等操作, LIGHTTPD + MYSQL + PHP(FAST-CGI)+eAccelerator整体应用平台运行性能稍好于

Apache+MYSQL+PHP+Zend Optimizer

创建文件phpinfo.php 内容为:

代码:
 
<?php
echo phpinfo();
?>
 

=======================================

1.      LIGHTTPD + MYSQL + PHP(FAST-CGI)+eAccelerator测试数据

[root@as5 bin]# ./php -v

PHP 5.2.1 (cgi-fcgi) (built: Apr 17 2007 16:18:49)

Copyright (c) 1997-2007 The PHP Group

Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

with eAccelerator v0.9.5, Copyright (c) 2004-2006 eAccelerator, by eAccelerator

eAccelerator已经启用

[root@localhost bin]# ./ab -c 20 -n1000 http://x.name/phpinfo.php

This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Copyright 1997-2005 The Apache Software Foundation, http://www.apache.org/

Benchmarking x.name (be patient)

Completed 100 requests

Completed 200 requests

Completed 300 requests

Completed 400 requests

Completed 500 requests

Completed 600 requests

Completed 700 requests

Completed 800 requests

Completed 900 requests

Finished 1000 requests

Server Software:        lighttpd/1.4.15

Server Hostname:        x.name

Server Port:            80

Document Path:          /phpinfo.php

Document Length:        47935 bytes

Concurrency Level:      20

Time taken for tests:   4.134608 seconds

Complete requests:      1000

Failed requests:        566

   (Connect: 0, Length: 566, Exceptions: 0)

Write errors:           0

Total transferred:      48126267 bytes

HTML transferred:       47965169 bytes

Requests per second:    241.86 [#/sec] (mean)

Time per request:       82.692 [ms] (mean)

Time per request:       4.135 [ms] (mean, across all concurrent requests)

Transfer rate:          11366.98 [Kbytes/sec] received

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0   14   3.2     14      27

Processing:    13   67   4.8     67      98

Waiting:        3   17   3.5     18      40

Total:         13   81   5.0     82     102

Percentage of the requests served within a certain time (ms)

  50%     82

  66%     82

  75%     83

  80%     83

  90%     84

  95%     86

  98%     87

  99%     90

 100%    102 (longest request)

2.        Apache+MYSQL+PHP+Zend Optimizer测试数据

[root@localhost bin]# ./php -v

PHP 5.1.2 (cli) (built: Jun 30 2006 18:14:19)

Copyright (c) 1997-2006 The PHP Group

Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

    with Zend Extension Manager v1.0.9, Copyright (c) 2003-2006, by Zend Technologies

with Zend Optimizer v2.6.2, Copyright (c) 1998-2006, by Zend Technologies

Zend Optimizer已经启用了

[root@localhost bin]# ./ab -c 20 -n1000 http://t.name:8080/phpinfo.php

This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Copyright 1997-2005 The Apache Software Foundation, http://www.apache.org/

Benchmarking t.name (be patient)

Completed 100 requests

Completed 200 requests

Completed 300 requests

Completed 400 requests

Completed 500 requests

Completed 600 requests

Completed 700 requests

Completed 800 requests

Completed 900 requests

Finished 1000 requests

Server Software:        Csdn/11.22.33

Server Hostname:        t.name

Server Port:            8080

Document Path:          /phpinfo.php

Document Length:        41610 bytes

Concurrency Level:      20

Time taken for tests:   4.867832 seconds

Complete requests:      1000

Failed requests:        7

   (Connect: 0, Length: 7, Exceptions: 0)

Write errors:           0

Total transferred:      41774965 bytes

HTML transferred:       41609965 bytes

Requests per second:    205.43 [#/sec] (mean)

Time per request:       97.357 [ms] (mean)

Time per request:       4.868 [ms] (mean, across all concurrent requests)

Transfer rate:          8380.53 [Kbytes/sec] received

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    0   0.2      0       2

Processing:    27   96 199.6     62    4087

Waiting:        2   50  18.6     52     443

Total:         27   96 199.6     62    4087

Percentage of the requests served within a certain time (ms)

  50%     62

  66%     67

  75%     70

  80%     72

  90%    129

  95%    318

  98%    520

  99%    597

 100%   4087 (longest request)

您还可能感兴趣的内容

日志信息 »

该日志于2007-12-14 13:28由 x72 发表在Lighttpd分类下, 通告目前不可用,你可以至底部留下评论。

没有评论

发表评论 »


返回顶部