centos 5.4 nginx+mysql+php+php-fpm 安装详解
作者:pkfeiyang 博客:http://blog.chinaunix.net/u3/103362/article_119529.html
系统环境:
我的是centos 5.4 i386
[root@daniel opt]# uname -a
Linux daniel 2.6.18-164.el5 #1 SMP Thu Sep 3 03:33:56 EDT 2009 i686 i686 i386 GNU/Linux但是我是在我的xen上进行安装,多少和真是物理机可能有区别,但是不大。创建用户 useradd www groupadd www usermod -a -G www www mkdir -p /data/wwwroot chmod +w /data/wwwroot/ chown /data/wwwroot/ -R调节时间crontab -e加入:15 3 * * * /usr/sbin/ntpdate 210.72.145.44 >/dev/null 2>&1安装需要的软件包: yum -y install ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel ncurses-devel openssl-devel libtool* zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel curl curl-devel pam-devel e2fsprogs-devel krb5-devel libidn libidn-devel libevent-devel libevent 下载软件包: pcre 下载 wget nginx 下载 wget gd库下载 wget lib库下载 wget wget 算法需要的 wget wget wget wget wget wget wget wget wget tar -xjf gd-2.0.35.tar.bz2 106 107 cd gd-2.0.35 108 109 ./configure --prefix=/usr/local/gd2 110 make && make install 111 cd .. 112 113 tar -xjf libmcrypt-2.5.8.tar.bz2 114 cd libmcrypt-2.5.8 115 116 ./configure --prefix=/usr 117 118 make && make install 119 122 tar -xzf libiconv-1.13.tar.gz 123 cd libiconv-1.13 124 ls 125 ./configure --prefix=/usr 126 make && make install 127 128 129 tar -xzf mhash-0.9.9.9.tar.gz 130 cd mhash-0.9.9.9 131 ./configure --prefix=/usr 132 make && make install 133 vi /etc/ld.so.conf 加上/usr/lib ldconfig
安装mysql
157 CFLAGS="-march=nocona -O3 -pipe" 158 CXXFLAGS="{CFLAGS}" 161 tar -xzf mysql-5.1.48.tar.gz 162 cd mysql-5.1.48 ./configure --prefix=/usr/local/mysql5 --localstatedir=/data/mysql/data --with-comment=Source --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=gbk --with-extra-charsets=all --with-pthread --enable-static --with-collation=gbk_chinese_ci --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-plugins=all --without-ndb-debug make
make install
useradd mysql -d /data/mysql -s/sbin/nologin
/usr/local/mysql/bin/mysql_install_db--user=mysql
cd /usr/local/mysql
chown -R root:mysql .
mkdir -p /data/mysql/data
chown -R mysql /data/mysql/data
cp share/mysql/my-huge.cnf /etc/my.cnf
cp share/mysql/mysql.server/etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
/etc/rc.d/init.d/mysqld start
安装php
tar -xzf php-5.3.3.tar.gzgzip -cd php-5.2.13-fpm-0.5.14.diff.gz | patch -d php-5.3.3 -p1CFLAGS="-march=prescott -O3 -pipe -comit-rrame-pointer"CXXFLAGS="S{CFLAGS}"./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/mysql5 --with-libxml-dir --with-xmlrpc --with-gd=/usr/local/gd2 --with-jpeg-dir --with-png-dir --with-bz2 --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-curl --with-curlwrappers --with-openssl --with-mcrypt --with-mhash --enable-pcntl --enable-sockets --enable-sysvsem --enable-inline-optimization --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-debug --disable-ipv6 --enable-pdo --with-pdo-mysql=shared --with-pdo-sqlite=shared (这个需要加上 如果你用pdo 来连接数据库的话)sed -i 's#-lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt#& -liconv#' Makefilemake ZENDEXTRA_LIBS='liconv'make installcp php.ini-development /usr/local/php-fcgi/etc/php.ini
安装其他软件
安装memachetar -xzf memcache-2.2.5.tgzcd memcache-2.2.5/usr/local/php-fcgi/bin/phpize./configure --with-php-config=/usr/local/php-fcgi/bin/php-configmake && make install
安装eaccelerator
tar -xjf eaccelerator-0.9.6.1.tar.bz2/usr/local/php-fcgi/bin/phpizecd eaccelerator-0.9.6.1/usr/local/php-fcgi/bin/phpize./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php-fcgi/bin/php-config安装PDO_MYSQLtar -xzf PDO_MYSQL-1.0.2.tgzcd PDO_MYSQL-1.0.2/usr/local/php-fcgi/bin/phpize./configure --with-php-config=/usr/local/php-fcgi/bin/php-config --with-pdo-mysql=/usr/local/mysql5make && make install安装ZendOptimizer 这个版本高,不用安装了tar -xzf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz编辑php。ini 手工修改:查找/usr/local/webserver/php/etc/php.ini中的extension_dir = "./" 修改为extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/" 并在此行后增加以下几行,然后保存: extension = "memcache.so" extension = "pdo_mysql.so" extension = "imagick.so" 再查找output_buffering = Off 修改为output_buffering = On 再查找; cgi.fix_pathinfo=0 修改为cgi.fix_pathinfo=0,防止Nginx文件类型错误解析漏洞[eAccelerator]extension="eaccelerator.so"eaccelerator.shm_size="32"eaccelerator.cache_dir="/cache_tmpfs/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.shm_prune_period="0"eaccelerator.shm_only="0"eaccelerator.compress="1"eaccelerator.compress_level="9"
安装nginx
wget
tar zxvf ngx_cache_purge-1.0.tar.gz
tar -xzf nginx-0.8.49.tar.gzcd nginx-0.8.49./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-openssl=/usr/lib --add-module=../ngx_cache_purge-1.0
--add-module=/Users/mikewest/Repositories/nginx-static-etags (当nginx需要使用etags 进行页面缓
存的设置时就需要加载这个模块 然后在nginx。conf 添加这个参数
--add-module=../ngx_cache_purge-1.0 编译时
location / {
...
FileETag on;
...
}
)
make && make install
nginx 测试:
[root@daniel core]# /usr/local/nginx/sbin/nginx -tthe configuration file /usr/local/nginx/conf/nginx.conf syntax is okconfiguration file /usr/local/nginx/conf/nginx.conf test is successful如果没有错误,说明nginx 没问题
下来我们编辑nginx.conf文件
下面这个红色部分可加可不加,不加的话,就自己去创建虚拟目录了,在这里进行目录映射
如下面那个 这是个你的web服务配置文件, 前边用include 进行映射user www www;worker_processes 8;pid /var/run/nginx.pid;# [ debug | info | notice | warn | error | crit ]#error_log /dev/null;error_log /var/www/logs/nginx_error.log error;#error_log logs/error.log notice;#error_log logs/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 5120;}http{ include mime.types; default_type application/octet-stream; charset utf-8; 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 /dev/null; #General Options server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; ignore_invalid_headers on; recursive_error_pages on; server_name_in_redirect off; sendfile on; #timeouts keepalive_timeout 60; #TCP Options tcp_nopush on; tcp_nodelay on; #fastcgi options 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; #size limits client_max_body_size 50m; client_body_buffer_size 256k; #gzip compression gzip on; gzip_min_length 0; gzip_buffers 16 8k; gzip_http_version 1.0; gzip_comp_level 9; gzip_types text/plain text/css image/x-icon image/png; gzip_vary on; #temp files proxy_temp_path /var/www/tmp/proxy_temp; fastcgi_temp_path /var/www/tmp/fastcgi_temp; client_body_temp_path /var/www/tmp/client_body_temp; #client_body_temp_path /usr/local/nginx8/client_body_temp 1 2; #proxy_temp_path /usr/local/nginx8/proxy_temp 1 2; #fastcgi_temp_path /usr/local/nginx8/fastcgi_temp 1 2; #proxy 代理缓存设置 #proxy proxy_buffering on; proxy_cache_min_uses 3; proxy_cache_path /tmp/cache/ levels=1:2 keys_zone=cache:10m inactive=10m max_size=1000M; proxy_cache_valid any 10m; proxy_ignore_client_abort off; proxy_intercept_errors on; proxy_next_upstream error timeout invalid_header; proxy_redirect off; proxy_set_header X-Forwarded-For $remote_addr; proxy_connect_timeout 60; proxy_send_timeout 60; proxy_read_timeout 60; #upstream 做集群用
# upstream { # ip_hash; # server 127.0.0.1:8080; # server 192.168.0.8:8080; # server 192.168.0.9.68; #}# server {
#
# root /data/wwwroot;
#
## server_name localhost;
# listen 80;
#
# access_log /var/www/logs/localhost.access.log;
#
# location / {
# index index.html index.htm index.php;
# }
#对 "/" 启用负载均衡
location / {
proxy_pass (和upstream 定义的要一直)
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;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /var/www/wwwroot;
#}
# pass the *.php scripts to @php_fpm_bin@ listening on tcp port @php_fpm_port@
#
# include vhosts/enable.php5.conf;
# }
#
# The following includes are specified for virtual hosts # include vhosts/.conf; (这里可以写更多web配置文件)}
编辑php-fpm.conf文件
[root@daniel core]# vi /usr/local/php-fcgi/etc/php-fpm.conf;;;;;;;;;;;;;;;;;;;;;; FPM Configuration ;;;;;;;;;;;;;;;;;;;;;;; All relative paths in this configuration file are relative to PHP's install; prefix.; 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.;include=/usr/local/php-fcgi/etc/fpm.d/*.conf;;;;;;;;;;;;;;;;;;; Global Options ;;;;;;;;;;;;;;;;;;;[global]; Pid file; Default Value: none;pid = /usr/local/php-fcgi/var/run/php-fpm.pid; Error log file; Default Value: /usr/local/php-fcgi/var/log/php-fpm.log;error_log = /usr/local/php-fcgi/var/log/php-fpm.log; Log level; Possible Values: alert, error, warning, notice, debug; Default Value: notice;log_level = notice; 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 = 0; 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 = 0; 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 = 0; 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'.[www]; 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: -1;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: anylisten.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 = nobody;listen.group = nobody;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 = wwwgroup = 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 = dynamic; 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 = 50; 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) / 2pm.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: 0pm.max_requests = 500; 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.; 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; 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:; ; ?json; ?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: /usr/local/php-fcgi/var/log/php-fpm.log.slow;slowlog = /usr/local/php-fcgi/var/log/php-fpm.log.slow; Set open file descriptor rlimit.; Default Value: system defined valuerlimit_files = 1024; Set max core size rlimit.; Possible Values: 'unlimited' or an integer greater or equal to 0; Default Value: system defined valuerlimit_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: 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 setchroot =; Chdir to this directory at the start. This value must be an absolute path.; Default Value: current directory or / when chrootchdir = /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.; Default Value: nocatch_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.; 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 www@my.domain.com;php_flag[display_errors] = off;php_admin_value[error_log] = /var/log/fpm-php.;php_admin_flag[log_errors] = on;php_admin_value[memory_limit] = 32M
编辑你的主机目录
[root@daniel core]# vi /usr/local/nginx/conf/vhosts/.confserver { listen 80; server_name ; index index.html index.php index.htm; root /data/wwwroot; #access_log /var/log/nginx/access_bbs.redocn.com.log combined; location / { #设置代理缓存
proxy_pass
proxy_cache cache;
proxy_cache_valid 200 24h;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_ignore_headers Expires Cache-Control;
proxy_cache_valid 200 304 12h;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
expires 1d;
if (!-e $request_filename) { rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last; rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2 last;last; rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last; rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last; break; } } #Preventing hot linking of images and other file types location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip)$ { valid_referers none blocked server_names *.aa.com if ($invalid_referer) { rewrite ^/ http:///images/default/logo.gif; return 403; } location ~ /purge(/.*)
{
allow 127.0.0.1;
allow x.x.x.187; #注意ACL
allow 60.x.x.0/24;
deny all;
proxy_cache_purge cache_one $host$1$is_args$args;
}
} # Add expires header for static content location ~* \.(js|css|jpg|jpeg|gif|png|swf)$ { if (-f $request_filename) { root /data/wwwroot; expires 1d; break; } } #support php location ~ .*\.php?$ { include fcgi.conf; (支持php的配置文件,否则你的php将不能正常访问) } }
编辑fcgi.conf
这个文件 我的这个nginx版本的问题,在安装nginx的时候已经产生fastcgi。conf文件只需在主机目录里映射这个文件即可。 fastcgi_pass 127.0.0.1:9000;(这个端口要和php-fpm.conf里的端口一直,否则出错)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-redirectfastcgi_param REDIRECT_STATUS 200;
日志轮回设置 因为不想apache那样 有cronlog 可以轮回日志,nginx 需要自己进行设置以下是我写的脚本#!/bin/bash#srclogs_path="/var/www/logs"time=`date +%Y-%m-%d-%H`#backlogs_dir="/website/log"/bin/mv ${logs_path}/access.aa.log ${logs_dir}/$time.access.aa.logkill -USR1 `cat /var/run/nginx.pid` 让其自动执行
00 00 * * * /usr/sbin/shell/nginxlog.sh > /dev/null 2>&1
下面进行测试:
启动php-fpm /usr/local/php-fcgi/sbin/php-fpm (当然和版本有关系,低版本需要后边加上start命令参数)ps -ef | grep php-fpm 查看进程有没有启动nginx/usr/local/nginx/sbin/nginx更改selinux 否则访问web 有时会报错setenforce 0 更改iptables-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT加上这一条重启iptables 在虚拟录下 编辑测试php文件vi /data/wwwroot/index.php
phpinfo();
?>
然后在浏览器里输入
能看到那个测试页面说明,配置成功。
内核优化
vi /etc/sysctl.conf
在末尾增加以下内容:
引用
# Add
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_len = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024 65535
下面讨论nginx的优化 请看优化篇
参考: