Tag: nginx

Nginx的worker_cpu_affinity详解

Posted by – 2009-11-09

配置文件中的worker_cpu_affinity可以用来绑定每个nginx进程所使用的CPU
官方的解释是:
#----------------------------引用文字-开始----------------------------
Syntax: worker_cpu_affinity cpumask [cpumask...]
Default: none
Linux only.
With this option you can bind the worker process to a CPU, it calls sched_setaffinity().
For example,
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
Bind each worker process to one CPU only.
worker_processes 2;
worker_cpu_affinity 0101 1010;
Bind the first worker to CPU0/CPU2, bind the second worker to CPU1/CPU3. This is suitable for HTT.
#----------------------------引用文字-结束----------------------------

最关键的地方没说清楚,怎样来表示每个CPU?

经过漫天的搜索和多次尝试发现
详解

那么,16核的cpu每个进程分配到一个cpu就应该是
配置

测试一下,用别的服务器发出大量请求
ab -n 20000 -k http://您的ip或域名/index.php

在被测试的服务器上查看cpu状态
top
然后按1
16cpu信息

可以看到每个cpu都在工作了。

Nginx平滑升级

Posted by – 2009-09-27

#################################
# Nginx平滑升级 #
# Author: 楚霏 #
# Date: 2009-09-25#
# Env: Centos 5.3 x86_64#
#################################

#以nginx0.7.61升级到nginx0.7.62为例
#下载新版
cd /usr/local/src
wget http://sysoev.ru/nginx/nginx-0.7.62.tar.gz
tar xvf nginx-0.7.62.tar.gz
cd nginx-0.7.62
#和旧版本的编译参数一样
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/var/nginx.pid --lock-path=/usr/local/nginx/var/nginx.lock --without-select_module --without-poll_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --without-http_ssi_module --without-http_userid_module --without-http_geo_module --without-http_memcached_module --without-http_map_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module
make
#先不要安装拷贝文件,把旧版本重命名

mv /usr/local/nginx /usr/local/nginx.0.7.61
#可以安装了
make install
#拷回配置文件
cd /usr/local/nginx
mv conf conf.bak
mv ../nginx.0.7.61/conf ./
#检查配置
service nginx configtest
#过滤出现在正在运行的nginx进程
ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
#再輸入以下 3 個命令 ( 數字部份請填入你自己的pid )
kill -USR2 3084
kill -WINCH 3084
kill -QUIT 3084
#检查一下,pid已经和以前的已经不同了
ps aux | grep nginx
#完成

Debian+nginx+mediawiki的rewrite问题

Posted by – 2009-09-08

环境是Debian+nginx0.7.61+php5.3.0+mysql5.1.37
一、保证mediawiki目录下的LocalSettings.php文件中没有对做url重写的相关没配置,也就是注释或删除下边这个参数
#----------------------------引用文字-开始----------------------------
#$wgArticlePath = "/$1";
#----------------------------引用文字-结束----------------------------

二、在nginx的vhost.conf进行rewrite的配置
#----------------------------引用文字-开始----------------------------
location / {
index index.html index.htm index.php;
root /www/wwwroot/chengyongxu.cn;
rewrite ^/wiki/index.php/([^?]*)(?:\?(.*))? /wiki/index.php?title=$1&$2;
}
#----------------------------引用文字-结束----------------------------
#上边只加了一条规则,这样就可以通过访问
http://chengyongxu.cn/wiki/index.php/阿贾克斯
来访问到
http://chengyongxu.cn/wiki/index.php?title=阿贾克斯

三、如果要做rewrite,一定要保证同类的链接的一致性
不能阿贾克斯的链接是:
http://chengyongxu.cn/wiki/index.php/阿贾克斯
而类似的巴塞罗那的链接是:
http://chengyongxu.cn/index.php/巴塞罗那

CentOS+memcached

Posted by – 2009-05-15


####################################
#CentOS+memcached #
#Author:楚霏 #
#Date: 2009-5-15 #
#Env: Centos 5.3 x86_64 #
####################################
一、准备工作
环境:Centos 5.3 x86_64
所需软件:
libevent
memcached服务端与客户端
libmemcached
####################################
下载相关软件
cd /usr/local/src
wget http://monkey.org/~provos/libevent-1.4.10-stable.tar.gz
wget http://danga.com/memcached/dist/memcached-1.3.0.tar.gz
wget http://pecl.php.net/get/memcached-0.1.5.tgz
wget http://download.tangent.org/libmemcached-0.28.tar.gz
####################################
二、安装
(1)安装memcached的服务端支持库
cd /usr/local/src
tar xvf libevent-1.4.10-stable.tar.gz
cd libevent-1.4.10-stable
./configure --help
./configure
make
make install
(2)安装memcached服务器端
cd /usr/local/src
tar xvf memcached-1.3.0.tar.gz
./configure
make
make install
ln -s /usr/local/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2
(3)安装libmemcached
cd /usr/local/src
tar xvf libmemcached-0.28.tar.gz
cd libmemcached-0.28
./configure
make
make install
(4)让php支持memcached
cd /usr/local/src
tar xvf memcached-0.1.5.tgz
cd memcached-0.1.5
/usr/local/php-fcgi/bin/phpize
./configure --help
./configure --enable-memcache --with-php-config=/usr/local/php-fcgi/bin/php-config
make
make test
make install
cp /usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-200*/memcached.so /usr/local/php-fcgi/ext/
echo "extension=memcached.so" >> /usr/local/php-fcgi/etc/php.ini
#测试一下是否已加载上
/usr/local/php-fcgi/bin/php-cgi -m |grep mem
(5)启动
#启动memcached
#看一下启动参数
memcached --help
memcached -d -u root -m 1000 -l 127.0.0.1 -p 11211 -P /tmp/memcached.pid
#重启一下web服务器
service nginx restart

nginx+mysql+php配置

Posted by – 2009-01-19

#########################
# Nginx Configuration #########
# Author: hao32#############
# Update: 楚霏##############
# Date: 2009-1-19###########
# Env: Centos 5.2 x86_64#####
######################
一. 分区完毕后, 关闭selinux等不必要的服务等等, 重启下系统:
相关文件
/etc/selinux/config    selinux配置文件
chkconfig    管理服务
dmesg    查看系统是否有报错等信息
###########################################################

二. 配置加速yum
cd /etc/yum.repos.d
cp CentOS-Base.repo--  CentOS-Base.repo.bak
vi CentOS-Base.repo
加入内容如下:
#----------------------------引用文字-开始----------------------------
[base]
name=CentOS-5 - Base
baseurl=http://centos.ustc.edu.cn/centos/5/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#released updates
[update]
name=CentOS-5 - Updates
baseurl=http://centos.ustc.edu.cn/centos/5/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released
[addons]
name=CentOS-5 - Addons
baseurl=http://centos.ustc.edu.cn/centos/5/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-5 - Extras
baseurl=http://centos.ustc.edu.cn/centos/5/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-5 - Plus
baseurl=http://centos.ustc.edu.cn/centos/5/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-5 - Contrib
baseurl=http://centos.ustc.edu.cn/centos/5/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#packages in testing
[testing]
name=CentOS-5 - Testing
baseurl=http://centos.ustc.edu.cn/centos/5/testing/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#----------------------------引用文字-结束----------------------------
###########################################################

三. 准备工作:
yum -y update
安装如下软件包:
yum install -y wget at ntp sysstat vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel curl curl-devel patch make libtool gettext-devel mlocate zlib zlib-devel compat-libstdc* libxml2 libxml2-devel openssl-devel e2fsprogs-devel krb5-devel libidn-devel *g77
###########################################################

四. 准备如下软件包(尽量都去官方站点去下载最新的release):
gd-2.0.35.tar.gz
pcre-7.8.tar.gz
libmcrypt-2.5.8.tar.bz2
libxml2-2.7.2.tar.gz
php-5.2.8-fpm-0.5.10.diff.gz
php-5.2.8.tar.bz2
mysql-5.1.30-linux-x86_64-icc-glibc23.tar.gz
nginx-0.6.34.tar.gz
eaccelerator-0.9.5.3.tar.bz2
ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz
###########################################################

cd /usr/local/src
wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz
wget ftp://xmlsoft.org/libxml2/libxml2-2.7.2.tar.gz
wget http://php-fpm.anight.org/downloads/head/php-5.2.8-fpm-0.5.10.diff.gz
wget http://sysoev.ru/nginx/nginx-0.6.34.tar.gz
wget http://downloads.phpchina.com/zend/optimizer/3.3.3/ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz
wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
下面几个软件下载后上传至服务器
#http://www.php.net/get/php-5.2.8.tar.bz2/from/a/mirror
php-5.2.8.tar.bz2

#http://nchc.dl.sourceforge.net/sourceforge/mcrypt/
#http://sourceforge.net/project/showfiles.php?group_id=87941&package_id=91774&release_id=487459
libmcrypt-2.5.8.tar.bz2

#http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.30-linux-x86_64-icc-glibc23.tar.gz/from/pick#mirrors
mysql-5.1.30-linux-x86_64-icc-glibc23.tar.gz
###########################################################

五. 开始安装过程:
tar jxvf php-5.2.8.tar.bz2
gzip -cd php-5.2.8-fpm-0.5.10.diff.gz | patch -d php-5.2.8 -p1
#编译 php 增加此参数 --enable-fpm
(1)安装GD库和PHP支持相关的库
tar xvf gd-2.0.3?.tar.gz; cd gd-2.0.3?/
./configure --prefix=/usr/local/gd2
make
make install
(2) LibXML2
cd /usr/local/src
tar zxvf libxml2-2.7.2.tar.gz; cd libxml2-2.7.2
./configure --prefix=/usr/local/libxml2
make
make install
(3) LibMcrypt
cd /usr/local/src
tar xjvf libmcrypt-2.5.8.tar.bz2; cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt
make
make install
(4) MySQL服务的安装
cd /usr/local/src
tar zxvf mysql-5.1.30-linux-x86_64-icc-glibc23.tar.gz
mv mysql-5.1.30-linux-x86_64-icc-glibc23 /usr/local/
ln -s /usr/local/mysql-5.1.30-linux-x86_64-icc-glibc23 /usr/local/mysql
useradd mysql -M
chown -R mysql:root /usr/local/mysql/
cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
vi /etc/my.cnf
----------------- my.cnf说明 -------------------
务必指定datadir的位置, 一般是/var/lib/mysql
------------------------------------------------
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 3 mysqld on
chown -R mysql:mysql /var/lib/mysql
cd /usr/local/mysql/bin
for i in *; do ln -s /usr/local/mysql/bin/$i /usr/bin/$i; done
(5) 编译PHP(fastcgi模式)
cd /usr/local/src/php-5.2.8
./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=/usr/local/libxml2 --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-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
(6) 安装ZendOptimizer
cd /usr/local/src; tar zxvf ZendOptimizer-3.3.?-linux-glibc23-x86_64.tar.gz
cd ZendOptimizer-3.3.?-linux-glibc23-x86_64; ./install
----------------- 安装ZendOptimizer说明 ------------------
基本上是一直回车, 值得注意一点的是:
当您看到要选择php的路径时就写:
/usr/local/php-fcgi/etc
看到Are you using Apache Web server?
选NO
-----------------------------------------------------------
(7) 安装eaccelerator
cd ../ ;tar jxvf eaccelerator-0.9.?.?.tar.bz2
cd eaccelerator-0.9.?.?
/usr/local/php-fcgi/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php-fcgi/bin/php-config
make
make install
mkdir /tmp/eaccelerator && chmod 777 /tmp/eaccelerator && touch /var/log/eaccelerator_log && mkdir /usr/local/php-fcgi/ext
mv /usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so /usr/local/php-fcgi/ext/

(8) 编辑php.ini
mv /usr/local/php-fcgi/etc/php.ini /usr/local/php-fcgi/etc/php.ini.chushibak
#把extension_dir = "./" 修改成: extension_dir = "/usr/local/php-fcgi/ext/"
sed 's/extension_dir = "./"/extension_dir = "/usr/local/php-fcgi/ext/"/g' /usr/local/php-fcgi/etc/php.ini.chushibak >>/usr/local/php-fcgi/etc/php.ini
cat <<EOF>>/usr/local/php-fcgi/etc/php.ini
#----------------------------引用文字-开始----------------------------
extension=eaccelerator.so
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.log_file = "/var/log/eaccelerator_log"
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"
EOF
#----------------------------引用文字-结束----------------------------
(7) 创建nginx运行用户和虚拟主机目录
groupadd www -g 78 ; useradd -u 78 -g www www -M
mkdir -p /www/wwwroot/test.com
chown  www:www /www/wwwroot
(8) nginx的安装与配置
安装Nginx所需的pcre库:
tar xvf pcre-7.8.tar.gz ; cd pcre-7.8/
./configure
make && make install
安装Nginx:
cd /usr/local/src ; tar xvf nginx-0.6.3?.tar.gz ; cd nginx-0.6.3?
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log  --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/var/nginx.pid --lock-path=/usr/local/nginx/var/nginx.lock --without-select_module --without-poll_module --with-http_realip_module --with-http_sub_module   --with-http_gzip_static_module --with-http_stub_status_module --without-http_ssi_module --without-http_userid_module --without-http_geo_module --without-http_memcached_module --without-http_map_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module
make && make install
cd /usr/local/nginx/conf/ ; cp nginx.conf nginx.conf.bak
vi nginx.conf
加入以下内容(事例):
#----------------------------引用文字-开始----------------------------
daemon on;
user www www;
worker_rlimit_nofile 8192;
worker_processes 4;
error_log logs/error.log error;
#pid var/nginx.pid;
lock_file var/nginx.lock;
events {
worker_connections  4096;
use epoll;
multi_accept on;
}
http {
include       mime.types;
default_type  application/octet-stream;
server_names_hash_max_size 512;
server_names_hash_bucket_size 128;
sendfile       off;
tcp_nopush     off;
tcp_nodelay    on;
keepalive_timeout  3;
client_max_body_size  2m;
client_header_timeout 30;
client_body_timeout   30;
send_timeout          30;
fastcgi_connect_timeout 300;
fastcgi_send_timeout    300;
fastcgi_read_timeout    300;
client_header_buffer_size    1k;
large_client_header_buffers  4 4k;
gzip_static on;
gzip_min_length  1024;
gzip_buffers     4 8k;
gzip_http_version 1.1;
gzip_comp_level 1;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
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 logs/access.log combined;
# include virtual host config
include vhosts/test.com;
}
#----------------------------引用文字-结束----------------------------
mkdir vhost
vi test.com
添加如下内容(事例):
#----------------------------引用文字-开始----------------------------
server {
listen       80;
server_name test.com www.test.com;
access_log  logs/test.com-access.log combined buffer=32k;
error_log   logs/test.com-error.log crit;
location / {
index           index.html index.htm index.php;
root            /www/wwwroot/test.com;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_pass  unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/wwwroot/test.com$fastcgi_script_name;
}

}
#----------------------------引用文字-结束----------------------------

编辑fpm配置文件:
vi /usr/local/php-fcgi/etc/php-fpm.conf
加入如下内容:
#----------------------------引用文字-开始----------------------------
<?xml version="1.0" ?>
<configuration>
<section name="global_options">
<value name="pid_file">/usr/local/php-fcgi/logs/php-fpm.pid</value>
<value name="error_log">/usr/local/php-fcgi/logs/php-fpm.log</value>
<value name="log_level">notice</value>
<value name="emergency_restart_threshold">10</value>
<value name="emergency_restart_interval">1m</value>
<value name="process_control_timeout">5s</value>
<value name="daemonize">yes</value>
</section>
<workers>
<section name="pool">
<value name="name">default</value>
<value name="listen_address">/tmp/php-fcgi.sock</value>
<value name="listen_options">
<value name="backlog">-1</value>
<value name="owner">www</value>
<value name="group">www</value>
<value name="mode">0666</value>
</value>.
<value name="php_defines">
<!--            <value name="sendmail_path">/usr/sbin/sendmail -t -i</value>            -->
<!--            <value name="display_errors">0</value>                                                          -->
</value>
<value name="user">www</value>
<value name="group">www</value>
<value name="pm">
<value name="style">static</value>
<value name="max_children">100</value>
<value name="apache_like">
<value name="StartServers">20</value>
<value name="MinSpareServers">5</value>
<value name="MaxSpareServers">35</value>
</value>
</value>
<value name="request_terminate_timeout">31s</value>
<value name="request_slowlog_timeout">0s</value>
<value name="slowlog">logs/slow.log</value>
<value name="rlimit_files">4096</value>
<value name="rlimit_core">0</value>
<value name="chroot"></value>
<value name="chdir"></value>
<value name="catch_workers_output">yes</value>
<value name="max_requests">500</value>
<value name="allowed_clients">127.0.0.1</value>
<value name="environment">
<value name="HOSTNAME">$HOSTNAME</value>
<value name="PATH">/usr/local/bin:/usr/bin:/bin</value>
<value name="TMP">/tmp</value>
<value name="TMPDIR">/tmp</value>
<value name="TEMP">/tmp</value>
<value name="OSTYPE">$OSTYPE</value>
<value name="MACHTYPE">$MACHTYPE</value>
<value name="MALLOC_CHECK_">2</value>
</value>
</section>
</workers>
</configuration>
#----------------------------引用文字-结束----------------------------
创建nginx的启动脚本:
vi /etc/init.d/nginx
#----------------------------引用文字-开始----------------------------
#! /bin/bash
#
# nginx          Start/Stop the nginx daemon.
#
# chkconfig: 2345 90 60
# description: nginx
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid

# Source function library.
. /etc/init.d/functions

# Nginx Settings
NGX_PID_FILE='/usr/local/nginx/var/nginx.pid'
NGX_PROC='/usr/local/nginx/sbin/nginx'
NGX_LOCK_FILE='/var/lock/subsys/nginx'
PHP_FPM='/usr/local/php-fcgi/sbin/php-fpm'

# Progran name
prog="nginx"

start() {
ulimit -HSn 65536
echo -n $"Starting $prog: "
if [ -e $NGX_LOCK_FILE ]; then
if [ -e $NGX_PID_FILE ] && [ -e /proc/`cat $NGX_PID_FILE` ]; then
echo -n $"cannot start $prog: nginx is already running."
failure $"cannot start $prog: nginx is already running."
echo
return 1
fi
fi
$NGX_PROC
RETVAL=$?
[ $RETVAL -eq 0 ] && success $"$prog start" || failure $"$prog start"
[ $RETVAL -eq 0 ] && touch $NGX_LOCK_FILE
echo

#php-fpm
$PHP_FPM start
return $RETVAL
}

stop() {
echo -n $"Stopping $prog: "
if [ ! -e $NGX_LOCK_FILE ] || [ ! -e $NGX_PID_FILE ]; then
echo -n $"cannot stop $prog: nginx is not running."
failure $"cannot stop $prog: nginx is not running."
echo
return 1
fi
PID=`cat $NGX_PID_FILE`
if checkpid $PID 2>&1; then
# TERM first, then KILL if not dead
kill -TERM $PID >/dev/null 2>&1
usleep 100000
if checkpid $PID && sleep 1 && checkpid $PID && sleep 3 && checkpid $PID; then
kill -KILL $PID >/dev/null 2>&1
usleep 100000
fi
fi
checkpid $PID
RETVAL=$((! $?))
[ $RETVAL -eq 0 ] && success $"$prog shutdown" || failure $"$prog shutdown"
[ $RETVAL -eq 0 ] && rm -f $NGX_LOCK_FILE;
echo

#php-fpm
$PHP_FPM stop
return $RETVAL
}

status() {
status $prog
}

restart() {
stop
start
}

reload() {
echo -n $"Reloading $prog: "
if [ ! -e $NGX_LOCK_FILE ] || [ ! -e $NGX_PID_FILE ]; then
echo -n $"cannot reload $prog: nginx is not running."
failure $"cannot reload $prog: nginx is not running."
echo
return 1
fi
kill -HUP `cat $NGX_PID_FILE` >/dev/null 2>&1
RETVAL=$?
[ $RETVAL -eq 0 ] && success $"$prog reload" || failure $"$prog reload"
echo
return $RETVAL
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
status)
status
;;
condrestart)
[ -f $NGX_LOCK_FILE ] && restart || :
;;
configtest)
$NGX_PROC -t
;;
*)
echo $"Usage: $0 {start|stop|status|reload|restart|condrestart|configtest}"
exit 1
esac
#----------------------------引用文字-结束----------------------------
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 3 nginx on
启动nginx:
service nginx start
启动mysql:
service mysqld restart

设定mysql的root密码
mysql> update mysql.user set password=PASSWORD('新密码') where User='root';
mysql> flush privileges;
mysql> quit