Ubuntu 11.04 Server X86-64 + ICC 12.0.4 編譯Nginx 1.0.4 與PHP 5.3.6 [轉貼 Backup]

0

如今Intel 自家的編譯器已經發展到了第12個發行版,對於兼容性來說達到了極大的提高,以往版本無法編譯的程序現在大部分都可以編譯通過了,那麼現在,已經到了介紹如何使用ICC 的時機咯。(採用ICC 編譯的程序運行效率普遍比GCC 高10%~300%)當然拉,我們還是只介紹64 位Linux OS 的安裝方式,32位的朋友請先RIOS

Step 1:確保你的服務器安裝的是Intel 芯片

Step 2:安裝JDK

mkdir /software
cd software
wget http://download.oracle.com/otn-pub/java/jdk/6u26-b03/jdk-6u26-linux-x64.bin
chmod 777 jdk-6u26-linux-x64.bin
./ jdk-6u26-linux-x64.bin

請按照提示一路往下yes, 最終生成jdk 文件夾

mv jdk-($version) /usr/local/jdk

修改環境變量

nano /etc/profile

在最下方插入

export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

重啟服務器

reboot

檢測JDK 是否安裝成功

java -version

Step 3:安裝ICC

首先更新需要支持的軟件包

apt-get install gcc g++ libstdc++6

下載並安裝ICC 12

cd /software
wget http://registrationcenter-download.intel.com/akdlm/irc_nas/2136/l_ccompxe_intel64_2011.4.191.tgz
tar zxf l_ccompxe_intel64_2011.4.191.tgz
cd l_ccompxe_intel64_2011.4.191
./install.sh

一路往下,遇到輸入序列號部分請輸入N49V-RFT67VK7 注意這是非商用版本,安裝成功後需要首先開啟編譯器系統集成

source /opt/intel/composerxe-2011.4.191/bin/iccvars.sh intel64

至此ICC 安裝成功,檢測一下,如遇到文本中未指出錯誤,請開動腦筋Google

icc -v

Step 4:安裝PHP NGINX 支持軟件包,以下軟件包若不偷懶也可採用ICC 編譯

apt-get install autoconf libfreetype6-dev libxml2-dev zlib1g-dev linux-libc-dev libglib2.0-dev bzip2 libbz2-dev libncurses5-dev curl libcurl4-openssl-dev e2fsprogs libkrb5-dev libidn11-dev openssl libssl-dev make libsasl2 -dev libperl-dev libgeoip-dev

下載需要安裝的軟件

cd /software
wget http://saco.iamalex.org/software/libiconv-1.13.1.tar.gz
wget http://saco.iamalex.org/software/libmcrypt-2.5.8.tar.gz
wget http: //saco.iamalex.org/software/mcrypt-2.6.8.tar.gz
wget http://saco.iamalex.org/software/mhash-0.9.9.9.tar.gz
wget http://saco.iamalex. org/software/php-5.3.6.tar.gz
wget http://saco.iamalex.org/software/memcached-1.4.5.tar.gz
wget http://saco.iamalex.org/software/memcache- 2.2.6.tgz
wget http://saco.iamalex.org/software/pcre-8.12.tar.gz
wget http://saco.iamalex.org/software/nginx-1.0.3.tar.gz
wget http: //saco.iamalex.org/software/jpegsrc.v8c.tar.gz
wget http://saco.iamalex.org/software/libpng-1.5.2.tar.gz
wget http://saco.iamalex.org/ software/GD_2_0_33.tar.gz
wget http://saco.iamalex.org/software/libevent-2.0.12-stable.tar.gz

針對Ubuntu 11.04 Server X86-64改寫支持文件

nano /usr/include/linux/errno.h
nano /usr/include/linux/param.h
nano /usr/include/sys/syscall.h
nano /usr/include/asm-generic/unistd.h
nano /usr/ include/bits/socket.h
nano /usr/include/asm-generic/socket.h
nano /usr/include/bits/ioctls.h
nano /usr/include/linux/ioctl.h
nano /usr/include/bits/ ioctl-types.h
修改這些文件

asm/
改寫為
asm-generic/

編輯鏈接庫文件

nano /etc/ld.so.conf.d/lib.conf

輸入

/usr/lib
/usr/local/lib
/opt/intel/composerxe-2011.4.191/compiler/lib/intel64

重新載入鏈接庫

ldconfig

編譯安裝各種支持類庫

tar zxf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
make dist-clean
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
CFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel – fno-implicit-templates -fno-exceptions -fno-rtti’ \
./configure -prefix=/usr/local
make
make install
cd ..

tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
CFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec -div -fp-model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -fno-implicit- templates -fno-exceptions -fno-rtti’ \
./configure
make
make install
ldconfig
cd libltdl
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
CFLAGS=’-O3 -axsse4.2 -ip -unroll2 – no-prec-div -fp-model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -fno -implicit-templates -fno-exceptions -fno-rtti’ \
./configure –enable-ltdl-install
make
make install
cd ../../

tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
CFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec -div -fp-model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -fno-implicit- templates -fno-exceptions -fno-rtti’ \
./configure
make
make install
cd ..

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/ lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s / usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash. so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0. 1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
ldconfig
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
CFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no -prec-div -fp-model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -fno- implicit-templates -fno-exceptions -fno-rtti’ \
./configure
make
make install
cd ..

tar zxf jpegsrc.v8c.tar.gz
cd jpeg-8c
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
CFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp -model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -fno-implicit-templates -fno- exceptions -fno-rtti’ \
./configure
make
make install

tar zxf libpng-1.5.2.tar.gz
cd libpng-1.5.2
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
CFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec -div -fp-model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -fno-implicit- templates -fno-exceptions -fno-rtti’ \
./configure
make
make install

tar zxf GD_2_0_33.tar.gz
cd pierrejoye-gd-libgd-5551f61978e3/src
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
CFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec -div -fp-model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -fno-implicit- templates -fno-exceptions -fno-rtti’ \
./configure
make
make install
ldconfig

Step 5:安裝PHP

創建編譯文件

cd /software
tar zxf php-5.3.6.tar.gz
cd php-5.3.6
nano compiler-php.sh

輸入以下內容,注意請按照你的CPU 規格填寫CFLAGS 及CXXFLAGS 特徵,在此採用Mysqlnd 實現Mysql / Mysqli / PDO

#!/bin/bash
make distclean
DEST=/usr/local/webserver/php
CFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -fno-implicit-templates -fno-exceptions -fno-rtti’ \
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
./configure \
-prefix=$DEST \
-enable-fpm \
-enable-force-cgi-redirect \
-enable-fastcgi \
-enable-mbstring \
-enable-mbregex \
-enable-pcntl \
-enable-exif \
-enable-sockets \
-enable-sysvsem \
-enable-sysvshm \
-enable-inline-optimization \
-enable-zend-multibyte \
-enable-xml \
-enable-discard- path \
-enable-bcmath \
-enable-shmop \
-enable-sysvsem \
-enable-sockets \
-enable-gd-native-ttf \
-with-mcrypt \
-with-gd \
-with-openssl \
-enable-inline -optimization \
-disable-ipv6 \
-disable-debug \
-disable-rpath \
-with-mysql=mysqlnd \
-with-mysqli=mysqlnd \
-with-pdo-mysql=mysqlnd \
-with-config-file-path= $DEST/etc \
-with-config-file-scan-dir=$DEST/etc/php.d \
-with-zlib \
-with-curl \
-with-curlwrappers \
-with-gettext \
-with-freetype- dir \
-with-iconv-dir=/usr/local \
-with-jpeg-dir \
-with-png-dir \
-with-libxml-dir=/usr \
-with-mhash \
-with-xmlrpc \
-enable -zip \
-enable-soap \
-with-pcre-regex

對編譯文件授權並執行配置編譯

chmod 777 compiler-php.sh
./compiler-php.sh
make ZEND_EXTRA_LIBS=’-liconv’
make install
cp php.ini-production /usr/local/webserver/php/etc/php.ini

編譯安裝Memcached 及PHP5 擴展模塊

tar zxf libevent-2.0.12-stable.tar.gz
cd libevent-2.0.12-stable
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
CFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel – fno-implicit-templates -fno-exceptions -fno-rtti’ \
./configure
make
make install
cd ../

cd /software
tar zxf memcached-1.4.5.tar.gz
cd memcached-1.4.5
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
CFLAGS=’-O3 -axsse4.2 -ip -unroll2 – no-prec-div -fp-model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -fno -implicit-templates -fno-exceptions -fno-rtti’ \
./configure
make
make install
cd ../
ldconfig

啟動Memcached

memcached -d -m 2048 -u root -l 10.0.0.18 -p 34567 -c 51200 -P /tmp/memcached.pid

tar zxvf memcache-2.2.6.tgz
cd memcache-2.2.6/
/usr/local/webserver/php/bin/phpize
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
CFLAGS=’-O3 – axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -fno-implicit-templates -fno-exceptions -fno-rtti’ \
./configure –with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ..

修改php.ini 配置

nano /usr/local/webserver/php/etc/php.ini
修改以下部分
extension_dir = “/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/”
output_buffering
Default Value: On
Development Value: 4096
Production Value: 4096
cgi.fix_pathinfo=0
在最後添加
extension = “memcache.so”

創建www用戶及用戶組

/usr/sbin/groupadd www
/usr/sbin/useradd -g www www

創建虛擬主機目錄並授權

mkdir /webs
chmod +w /webs
chown -R www:www /webs

創建php-fpm配置文件

nano /usr/local/webserver/php/etc/php-fpm.conf

;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;
; All relative paths in this configuration file are relative to PHP’s install
; prefix (/usr/local/webserver/php). This prefix can be dynamicaly changed by using the
; ‘-p’ argument from the command line.
; Include one or more files. If glob(3) exists, it is used to include a bunch of
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used . They will be prefixed by:
; – the global prefix if it’s been set (-p arguement)
; – /usr/local/webserver/php otherwise
;include=etc/fpm.d/*.conf
;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;
[global] ; Pid file
; Note: the default prefix is /usr/local/webserver/php/var
; Default Value: none
pid = /usr/local/webserver/php/logs/php-fpm.pid
; Error log file
; Note: the default prefix is /usr/local/webserver/php/var
; Default Value: log/php-fpm.log
error_log = /usr/local/webserver/php/logs/php-fpm.log
; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = error
; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of ‘0’ means ‘Off’.
; Default Value: 0
emergency_restart_threshold = 10
; Interval of time used by emergency_restart_interval to determine when
; a graceful restart will be initiated. This can be useful to work around
; accidental corruptions in an accelerator’s shared memory.
; Available Units: s(econds), m(inutes), h( ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
emergency_restart_interval = 1m
; Time limit for child processes to wait for a reaction on signals from master.
; Available units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
process_control_timeout = 5s
; Send FPM to background. Set to ‘no’ to keep FPM in foreground for debugging.
; Default Value: yes
daemonize = yes
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;
; Multiple pools of child processes may be started with different listening
; ports and different management options. The name of the pool will be
; used in logs and stats. There is no limitation on the number of pools which
; FPM can handle. Your system will tell you anyway:)
; Start a new pool named ‘www’.
; the variable $pool can we used in any directive and will be replaced by the
; pool name (‘www’ here)
[default] ; Per pool prefix
; It only applies on the following directives:
; – ‘slowlog’
; – ‘listen’ (unixsocket)
; – ‘chroot’
; – ‘chdir’
; – ‘php_values’
; – ‘php_admin_values’
; When not set , the global prefix (or /usr/local/webserver/php) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; ‘ip.add.re.ss:port’ – to listen on a TCP socket to a specific address on
; a specific port;
; ‘port’ – to listen on a TCP socket to all addresses on a
; specific port;
; ‘/path/to/unix/socket’ – to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000
; Set listen(2) backlog. A value of ‘-1’ means unlimited.
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
listen.backlog = -1
; List of ipv4 addresses of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
listen.allowed_clients = 127.0.0.1
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0666
listen.owner =
listen.group =
listen.mode = 0666
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user’s group
; will be used.
user = www
group = www
; Choose how the process manager will control the number of child processes.
; Possible Values:
; static – a fixed number (pm.max_children) of child processes;
; dynamic – the number of child processes are set dynamically based on the
; following directives :
; pm.max_children – the maximum number of children that can
; be alive at the same time.
; pm.start_servers – the number of children created on startup.
; pm.min_spare_servers – the minimum number of children in ‘idle’
; state (waiting to process). If the number
; of ‘idle’ processes is less than this
; number then some children will be created.
; pm.max_spare_servers – the maximum number of children in ‘idle’
; state (waiting to process). If the number
; of ‘idle’ processes is greater than this
; number then some children will be killed.
; Note: This value is mandatory.
pm = static
; The number of child processes to be created when pm is set to ‘static’ and the
; maximum number of child processes to be created when pm is set to ‘dynamic’.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI.
; Note: Used when pm is set to either ‘static’ or ‘dynamic’
; Note: This value is mandatory.
pm.max_children = 320
; The number of child processes created on startup.
; Note: Used only when pm is set to ‘dynamic’
; Default Value: min_spare_servers + (max_spare_servers – min_spare_servers) / 2
;pm.start_servers = 20
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to ‘dynamic’
; Note: Mandatory when pm is set to ‘dynamic’
;pm.min_spare_servers = 5
; The desired maximum number of idle server processes.
; Note: Used only when pm is set to ‘dynamic’
; Note: Mandatory when pm is set to ‘dynamic’
;pm.max_spare_servers = 35
; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify ‘0’. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
pm.max_requests = 102400
; The URI to view the FPM status page. If this value is not set, no URI will be
; recognized as a status page. By default, the status page shows the following
; information:
; accepted conn – the number of request accepted by the pool;
; pool – the name of the pool;
; process manager – static or dynamic;
; idle processes – the number of idle processes;
; active processes – the number of active processes;
; total processes – the number of idle + active processes.
; max children reached – number of times, the process limit has been reached,
; when pm tries to start more children (works only for
; pm ‘dynamic’)
; The values ​​of ‘idle processes’, ‘active processes’ and ‘total processes’ are
; updated each second. The value of ‘accepted conn’ is updated in real time.
; Example output:
; accepted conn: 12073
; pool: www
; process manager: static
; idle processes: 35
; active processes: 65
; total processes: 100
; max children reached: 1
; By default the status page output is formatted as text/plain. Passing either
; ‘html’ or ‘json’ as a query string will return the corresponding output
; syntax. Example:
; http://www.foo.bar/status
; http://www.foo.bar/status?json
; http://www.foo.bar/status?html
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file.
; Default Value: not set
;pm.status_path = /status
; The ping URI to call the monitoring page of FPM. If this value is not set, no
; URI will be recognized as a ping page. This could be used to test from outside
; that FPM is alive and responding, or to
; – create a graph of FPM availability (rrd or such);
; – remove a server from a group if it is not responding (load balancing);
; – trigger alerts for the operating team (24/7).
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file.
; Default Value: not set
;ping. path = /ping
; This directive may be used to customize the response of a ping request. The
; response is formatted as text/plain with a 200 response code.
; Default Value: pong
;ping.response = pong
; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the ‘max_execution_time’ ini option
; does not stop script execution for some reason. A value of ‘0’ means ‘off’ .
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_terminate_timeout =0
; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the ‘slowlog’ file. A value of ‘0s’ means ‘off’.
; Available units: s(econds)(default), m(inutes ), h(ours), or d(ays)
; Default Value: 0
request_slowlog_timeout = 0
; The log file for slow requests
; Default Value: not set
; Note: slowlog is mandatory if request_slowlog_timeout is set
;slowlog = log/$pool.log.slow
; Set open file descriptor rlimit.
; Default Value: system defined value
;rlimit_files = 1024
; Set max core size rlimit.
; Possible Values: ‘unlimited’ or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0
; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: you can prefix with ‘$prefix’ to chroot to the pool prefix or one
; of its subdirectories. If the pool prefix is not set, the global prefix
; will be used instead.
; Note: chrooting is a great security feature and should be used whenever
; possible. However, all PHP paths will be relative to the chroot
; (error_log, sessions.save_path, …).
; Default Value: not set
;chroot =
; Chdir to this directory at the start.
; Note: relative path can be used.
; Default Value: current directory or / when chroot
;chdir = /var/www
; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Note: on highloaded environement, this can cause some delay in the page
; process time (several ms).
; Default Value: no
catch_workers_output = yes
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values ​​previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
; php_value/php_flag – you can set classic ini defines which can
; be overwritten from PHP call ‘ini_set’.
; php_admin_value/php_admin_flag – these directives won’t be overwritten by
; PHP call ‘ini_set’
; For php_*flag, valid values ​​are on, off, 1, 0, true, false, yes or no.
; Defining ‘extension’ will load the corresponding shared extension from
; extension_dir. Defining ‘disable_functions’ or ‘disable_classes’ will not
; overwrite previously defined php.ini values, but will append the new value
; instead.
; Note: path INI options can be relative and will be expanded with the prefix
; (pool, global or /usr/local/webserver/php)
; Default Value: nothing is defined by default except the values ​​in php.ini and
; specified at startup with the -d argument
;php_admin_value[sendmail_path]= /usr/sbin/sendmail -t -i -f [email protected]. com
;php_flag[display_errors]= off
;php_admin_value[error_log]= /var/log/fpm-php.www.log
;php_admin_flag[log_errors]= on
;php_admin_value[memory_limit]= 32M

啟動php-cgi進程

mkdir -p /usr/local/webserver/php/logs/
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm

Step 6:安裝Nginx

安裝pcre 注意pcre並不兼容icc編譯

tar zxvf pcre-8.12.tar.gz
cd pcre-8.12
LD=xild \
AR=xiar \
CFLAGS=’-Os’ \
CXXFLAGS=’-Os’ \
./configure
make
make install
cd ..
ldconfig

安裝nginx

tar zxvf nginx-1.0.3.tar.gz
cd nginx-1.0.3
CC=icc \
CXX=icpc \
LD=xild \
AR=xiar \
CFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec -div -fp-model source -restrict -static-intel’ \
CXXFLAGS=’-O3 -axsse4.2 -ip -unroll2 -no-prec-div -fp-model source -restrict -static-intel -fno-implicit- templates -fno-exceptions -fno-rtti’ \
./configure –user=www –group=www –prefix=/usr/local/webserver/nginx –with-http_stub_status_module –with-http_ssl_module –with- http_flv_module –with-http_gzip_static_module –with-http_geoip_module
make
make install
cd ..

創建nginx配置文件

nano /usr/local/webserver/nginx/conf/nginx.conf

user www www;
worker_processes 8;
pid /usr/local/webserver/nginx/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 200m;
access_log /dev/null;
error_log /usr/local/webserver/nginx/logs/error.log;
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 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /webs;
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
access_log on;
}
}

創建 nano /usr/local/webserver/nginx/conf/fcgi.conf

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;

啟動Nginx

ulimit -SHn 65535
/usr/local/webserver/nginx/sbin/nginx

創建PHP測試文件

nano /webs/index.php

配置開機啟動

nano /etc/rc.local
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx

優化內核參數

nano /etc/sysctl.conf
在末尾添加
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.ip_local_port_range = 1024 65535
使設置生效

/sbin/sysctl -p

無縫重啟Nginx

/usr/local/webserver/nginx/sbin/nginx -s reload

無縫重啟php

kill -SIGUSR2 `cat /usr/local/webserver/php/logs/php-fpm.pid`

Share.

About Author

hahahahahaha......nothing here

發表迴響