歡迎您光臨本站 註冊首頁

LEMP構建高性能WEB伺服器 二

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

LEMP構建高性能WEB伺服器 二

LEMP構建高性能WEB伺服器 二


    三、編譯安裝PHP及Nginx
1.PHP(Fastcgi)編譯安裝

  1)php-fpm 給PHP(Fastcgi)打補丁
    #tar xvf php-5.2.6.tar.bz2
    #gzip -cd php-5.2.6-fpm-0.5.8.diff.gz | patch -d php-5.2.6 -p1

  2)PHP(Fastcgi)安裝.
    #cd php-5.2.6
    #vi in_php5.sh
./configure \

•        "--prefix=/usr/local/php-fcgi" \

•        "--enable-fastcgi" \

•        "--enable-fpm" \

•        "--enable-discard-path" \

•        "--enable-force-cgi-redirect" \

•        "--with-config-file-path=/usr/local/php-fcgi/etc" \

•        "--enable-zend-multibyte" \

•        "--with-mysql=/usr/local/mysql" \

•        "--with-libxml-dir" \

•        "--with-iconv-dir=/usr/lib" \

•        "--with-xmlrpc" \

•        "--with-gd=/usr/local/gd2" \

•        "--with-jpeg-dir" \

•        "--with-png-dir" \

•        "--with-bz2" \

•        "--with-freetype-dir" \

•        "--with-zlib-dir " \

•        "--with-openssl=/usr/local/openssl" \

•        "--with-mcrypt=/usr/local/libmcrypt" \

•        "--enable-sysvsem" \

•        "--enable-inline-optimization" \

•        "--enable-soap" \

•        "--enable-gd-native-ttf" \

•        "--enable-ftp" \

•        "--enable-mbstring" \

•        "--enable-exif" \

•        "--disable-debug" \

•        "--disable-ipv6"

•     make && make install

•     cp php.ini-dist /usr/local/php-fcgi/etc/php.ini
複製代碼#sh in_php5.sh


  4)安裝Xcache
  tar xvf xcache-1.2.2.tar.gz
  cd xcache-1.2.2
  #vi in_xcache.sh
  /usr/local/php-fcgi/bin/phpize

•  ./configure --enable-xcache --enable-xcache-coverager --with-php-config=/usr/local/php-fcgi/bin/php-config \

•   --enable-inline-optimization --disable-debug

•  make && make install
複製代碼#sh in_xcache.sh
  
  #vi /usr/local/php-fcgi/etc/php.ini  #編輯php.ini在其內容最後加入如下內容:


•zend_extension      = /usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-20060613/xcache.so





•xcache.admin.user   = "admin"

•;如何生成md5密碼: echo -n "password"| md5sum

•xcache.admin.pass   = "035d849226a8a10be1a5e0fec1f0f3ce"  #密碼為52netseek





•; Change xcache.size to tune the size of the opcode cache

•xcache.size         = 24M

•xcache.shm_scheme   = "mmap"

•xcache.count        = 4

•xcache.slots        = 8K

•xcache.ttl          = 0

•xcache.gc_interval  = 0



•; Change xcache.var_size to adjust the size of variable cache

•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    = "/dev/zero"

•xcache.coredump_directory =   ""

•xcache.cacher       = On

•xcache.stat         = On

•xcache.optimizer    = Off





•xcache.coverager    = On

•xcache.coveragedump_directory = ""
複製代碼4)安裝Memcache
  cd memcache-2.2.3
#vi in_memcache.sh
  /usr/local/php-fcgi/bin/phpize

•./configure --with-php-config=/usr/local/php-fcgi/bin/php-config

•make && make install
複製代碼#sh in_memcache.sh

  5) PHP初始化腳本
# cat init_fcgi.sh
#!/bin/bash

•#php-fastcgi.php

•fcgi_cf="/usr/local/php-fcgi/etc/php.ini"

•sed -i '205 s#;open_basedir =#open_basedir = /data/www/wwwroot:/tmp#g' $fcgi_cf

•sed -i '210 s#disable_functions =#disable_functions =



•phpinfo,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,



•dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server#g' $fcgi_cf

•sed -i '/expose_php/s/On/Off/' $fcgi_cf

•sed -i '/display_errors/s/On/Off/' $fcgi_cf

•sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-20060613/"\nextension



•= "memcache.so"\n#' $fcgi_cf
複製代碼6)ZendOptimizer-3.3.3-linux-glibc23-i386 (解壓後進入目錄./install,安提示選擇相關的目錄及配置文件存放目錄即可)

2.安裝Nginx
1)Nginx編譯安裝
cd pcre-7.7/
  ./configure
  make && make install
  cd ../


cd nginx-0.6.31
#vi in_nginx.sh
./configure --user=www --group=www --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-



•openssl=/usr/local/openssl

•make && make install
複製代碼sh in_nginx.sh

2)初始化Nginx相關配置
  #mkdir /usr/local/nginx/conf/vhosts  創建存放虛擬主機配置文件目錄
  #cd /usr/local/nginx/conf
  #mv nginx.conf nginx.conf_back 將原配置文件備份供以後參考.
  #vi nginx.conf 重新創建nginx主配置文件
user  www www;



•worker_processes 8;



•pid /var/run/nginx.pid;

•# [ debug | info | notice | warn | error | crit ]

•#error_log  /var/log/nginx.error_log  info;

•#Specifies the value for maximum file descriptors that can be opened by this process.

•worker_rlimit_nofile 51200;



•events

•{

•       use epoll;



•       #maxclient = worker_processes * worker_connections / cpu_number

•       worker_connections 51200;

•}



•http

•{

•         include       mime.types;

•       default_type  application/octet-stream;

•       charset  gb2312;

•       server_names_hash_bucket_size 128;

•       client_header_buffer_size 32k;

•       large_client_header_buffers 4 32k;



•       log_format  main  '$remote_addr - $remote_user [$time_local] $request '

•                         '"$status" $body_bytes_sent "$http_referer" '

•                         '"$http_user_agent" "$http_x_forwarded_for"';



•       #access_log  /data/www/logs/access.log  main;

•       access_log  /dev/null;



•       sendfile on;

•       tcp_nopush     on;



•       keepalive_timeout 60;

•       tcp_nodelay on;



•       fastcgi_connect_timeout 300;

•       fastcgi_send_timeout 300;

•       fastcgi_read_timeout 300;

•       fastcgi_buffer_size 128k;

•       fastcgi_buffers 4 128k;

•       fastcgi_busy_buffers_size 128k;

•       fastcgi_temp_file_write_size 128k;

•       fastcgi_intercept_errors on;



•       gzip  on;

•       gzip_comp_level     4;

•       gzip_min_length  1100;

•       gzip_buffers     4 8k;

•       gzip_http_version 1.0;

•       gzip_proxied        any;

•       gzip_types       text/plain text/xml text/javascript application/x-javascript text/css text/html application/xml;



•       #

•       client_max_body_size       10m;

•       client_body_buffer_size    256k;

•       #

•       #proxy_temp_path            /dev/shm/proxy_temp;

•       fastcgi_temp_path          /dev/shm/fastcgi_temp;

•       client_body_temp_path      /dev/shm/client_body_temp;





•       # The following includes are specified for virtual hosts

•       include          vhosts/bbs.linxutone.org.conf;

•       include          vhosts/down.redocn.com.conf;

•       include          vhosts/count.linuxtone.org.conf;

•}
複製代碼#vi /enable_php5.conf Nginx支持PHP配置文件.
fastcgi_pass  127.0.0.1:8085;

•fastcgi_index index.php;



•fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;

•fastcgi_param  SERVER_SOFTWARE    nginx;



•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_FILENAME    $document_root$fastcgi_script_name;

•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  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;



•# PHP only, required if PHP was built with --enable-force-cgi-redirect

•#fastcgi_param  REDIRECT_STATUS    200;
複製代碼3)配置修改php-fpm腳本
配置php-fpm腳本:
cd /usr/local/php-fcgi/etc/
vi php-fpm.conf  修改如下內容:(進入vi編輯器,輸入:set nu 顯示行號.)
41                         <value name="listen_address">127.0.0.1:8085</value>

•62                         Unix user of processes

•63                         <value name="user">www</value>

•65                         Unix group of processes

•66                         <value name="group">www</value>

•79                                 <value name="max_children">128</value>

•80

•81                                 Settings group for 'apache-like' pm style

•82                                 <value name="apache_like">

•83

•84                                         Sets the number of server processes created on startup.

•85                                         Used only when 'apache-like' pm_style is selected

•86                                         <value name="StartServers">20</value>

•87

•88                                         Sets the desired minimum number of idle server processes.

•89                                         Used only when 'apache-like' pm_style is selected



•90                                         <value name="MinSpareServers">5</value>

•91

•92                                         Sets the desired maximum number of idle server processes.

•93                                         Used only when 'apache-like' pm_style is selected

•94                                         <value name="MaxSpareServers">250</value>

•104                         Set open file desc rlimit

•105                         <value name="rlimit_files">51200</value>

•106

•107                         Set max core size rlimit

•108                         <value name="rlimit_core">0</value>

•109

•110                         Chroot to this directory at the start

•111                         <value name="chroot"></value>

•112

•113                         Chdir to this directory at the start

•114                         <value name="chdir"></value>

•115

•116                         Redirect workers' stdout and stderr into main error log.

•117                         If not set, they will be redirected to /dev/null, according to FastCGI specs

•118                         <value name="catch_workers_output">yes</value>

•119

•120                         How much requests each process should execute before respawn.

•121                         Useful to work around memory leaks in 3rd party libraries.

•122                         For endless request processing please specify 0

•123                         Equivalent to PHP_FCGI_MAX_REQUESTS

•124                         <value name="max_requests">51200</value>
複製代碼4) Nginx+PHP(fastcgi)啟動腳本參考:http://bbs.linuxtone.org/thread-372-1-2.html
《解決方案》

好貼,頂起來

[火星人 ] LEMP構建高性能WEB伺服器 二已經有623次圍觀

http://coctec.com/docs/service/show-post-2000.html