借助阿里云sh脚本Linux一键安装web环境

系统环境:CentOS6

卸载CentOS自带Apache

rpm -qa|grep httpd,查看与httpd相关软件包。
rpm -e httpd

因为这个一键安装是通过脚本编译按照的。
SO,首先需要解决编译环境问题

获取相关开源程序:
1、【适用CentOS操作系统】利用CentOS Linux系统自带的yum命令安装、升级所需的程序库(RedHat等其他Linux发行版可从安装光盘中找到这些程序库的RPM包,进行安装):
sudo -s
LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

2、进入home目录建立tmp目录
mkdir -p /home/tmp
cd tmp

3、下载一键安装脚本
wget http://soft.phpwind.me/web/sh.zip

unzip sh.zip
chmod -R 777 sh
cd sh
./install.sh

出现了一个选择提示,进入web服务器版本的选择界面,可以根据需要选择apache或者nginx服务器
这里我们选择nginx,输入n,回车

参考:
linux一键安装web环境全攻略 http://help.aliyun.com/manual?helpId=129

Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版)[原创] http://blog.s135.com/nginx_php_v6/

一键安装web环境全攻略

Debian6(Squeeze)使用 apt-get 安装Nginx+MySQL+PHP服务器环境(备忘)

#cat /proc/version
Linux version 2.6.32-5-amd64 (Debian 2.6.32-39) (houyi-dev@aliyun-inc.com) (gcc version 4.3.5 (Debian 4.3.5-4) ) #1 SMP Sun Jan 1 04:57:38 CST 2012

#uname -a
Linux AY***cb 2.6.32-5-amd64 #1 SMP Sun Jan 1 04:57:38 CST 2012 x86_64 GNU/Linux

# apt-get update

# apt-get dist-upgrade

Debian官方的源一般都以稳定为主,所以里面的软件版本也相对比较低,Dotdeb的源更新速度比较快,而且里面的软件包都是最新稳定版的,所以我使用Debian一般都喜欢加入Dotdeb的源,安装最新的稳定版软件。

根据你使用的Debian的发行版本(Debian 5.0 “Lenny”/oldstable 或 Debian 6.0 “Squeeze”/stable),在/etc/apt/sources.list文件中加入两行(选择最近的镜像站):
Squeeze :
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all
Lenny :
deb http://packages.dotdeb.org oldstable all
deb-src http://packages.dotdeb.org oldstable all

增加源,支持php5-fpm
然后获取GnuPG 密钥
wget http://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg | apt-key add –

rm dotdeb.gpg

# apt-get update

# apt-get dist-upgrade

2:安装 MySQL 5

apt-get install mysql-server mysql-client

在弹出的页面输入2次密码

修改mysql配置文件,去掉innodb,这样可以节省不少内存
vi /etc/mysql/my.cnf

增加下面语句
skip-innodb

保存后,mysql重启一下就生效

3:安装Nginx+php+php5-fpm+memcache

apt-get install php5-cgi php5-mysql php5-gd php5-imagick php5-mcrypt php5-memcache memcached php5-fpm php5-cli nginx

apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-imagick php5-mcrypt php5-mhash libmcrypt* libmcrypt-dev php5-memcache memcached php5-fpm php5-cli php5-xmlrpc nginx

apt-get install php5-cgi php5-mysql php5-curl php5-imagick php5-mcrypt php5-mhash libmcrypt* libmcrypt-dev php5-fpm php5-cli php5-xmlrpc nginx

安装成功后

mkdir /var/www
chown www-data:www-data /var/www

修改memcache的端口和内存大小
vi /etc/memcached.conf

vi /etc/php5/cgi/php.ini
修改下面这句
cgi.fix_pathinfo=1

我的是512M的vps,所以修改php-fpm的配置文件
vi /etc/php5/fpm/pool.d/www.conf

pm.max_children = 25
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 10
pm.max_requests = 500

大家也可以根据自己服务器的条件和实际负载需要进行调整

修改nginx的配置文件

vi /etc/nginx/sites-available/default

添加:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
}

保存后,重启nginx
/etc/init.d/nginx restart

写一个测试php页面

如果能正常显示那页面,那就大功告成

如果你想手工编译nginx+php+fpm,请参考我的另外一篇指导文章
VPS 安装Nginx+MySQL+PHP 5.2.17(FastCGI)服务器环境(Debian6)备忘

常用组合,查看出正在连接和网络信息
netstat -ntulpa

nginx 监控状态说明

nginx 监控

server
{
listen 80;
server_name s.clin003.com;

location / {
stub_status on;
access_log off;
}
}

Active connections: 2
server accepts handled requests
130732 130732 176591
Reading: 1 Writing: 1 Waiting: 0

nginxstatus 显示的内容意思如下:

●active connections – 当前 nginx 正处理的活动连接数。
●server accepts handled requests — 总共处理了 130732 个连接 , 成功创建 130732 次握手 ( 证明中间没有失败的 ), 总共处理了 176591 个请求 。
●reading — nginx 读取到客户端的 header 信息数。
●writing — nginx 返回给客户端的 header 信息数。
●waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading + writing),意思就是 nginx 已经处理完正在等候下一次请求指令的驻留连接。

Apache2/Nginx 下配置404页面 备忘

 

今天发现空间没有设置404错误页面,折腾Apache/Nginx配置文件

环境:
Apache2
Nginx0.8

Apache下配置404错误页面

1、vi /etc/apache2/site-available/clin003.com(你的网站配置文件)
修改
AllowOverride None

AllowOverride All
2、在网站根目录.htaccess中添加
ErrorDocument 404 /404.html

3、重启apache
/etc/init.d/apache2 restart

Nginx下配置404错误页面

1、更改nginx.conf在http定义区域加入:

fastcgi_intercept_errors on;

2、更改nginx.conf在server 区域加入:

error_page 404 = /404.html

3、检查配置文件是否有误,然后加载配置文件

/usr/local/server/nginx/sbin/nginx -t(这个server目录,要看你自己的情况喔)

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

VPS 安装Nginx+MySQL+PHP 5.2.17(FastCGI)服务器环境(Debian6)备忘

CentOS 5.3,和RedHat请参考张宴“Nginx0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版):http://blog.s135.com/nginx_php_v6/

附件:debian6服务器环境 Nginx MySQL php5.2.17(FastCGI)服务器环境配置备忘

debian6服务器环境:
cat /proc/version
Linux version 2.6.18-194.26.1.el5.028stab079.2 (root@rhel5-build-x64) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Fri Dec 17 19:25:15 MSK 2010
root@vps:~# cat /etc/issue
Debian GNU/Linux 6.0 \n \l

root@vps:~# uname -a
Linux vps 2.6.18-194.26.1.el5.028stab079.2 #1 SMP Fri Dec 17 19:25:15 MSK 2010 i686 GNU/Linux

 

photonvps买了个VPS,装上了debian6,然后装shopex的,折腾那个zend,结果debian默认是php3的,本来内存不大,干脆就直接卸掉Apache,换用Nginx了,还是编译安装php5.2装shopex吧。(话说shopex对这个“高”版本的mysql 5.5.3也是不能很好支持的,最后是直接用原来空间里的备份文件恢复进去的,直接新装是悲剧的,安装系统数据失败什么的,总之shopex真挺拽的!!)
用netstat -ntlp查检一下系统中启动的哪些服务

删除sendmail named(bind9)
/etc/init.d/sendmail stop
/etc/init.d/apache2 stop
/etc/init.d/bind9 stop
/etc/init.d/samba stop
dpkg -l |grep sendmail
apt-get remove sendmail sendmail-base sendmail-bin sendmail-cf sendmail-doc
dpkg -l |grep sendmail
dpkg –force-all -P sendmail-base sendmail-bin sendmail-cf sendmail-doc

dpkg -l |grep apache
apt-get remove apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common
dpkg -l |grep apache
dpkg –force-all -P apache2-doc apache2.2-common

dpkg -l |grep bind9
apt-get remove bind9 bind9-host bind9utils libbind9-60
dpkg -l |grep bind9
dpkg –force-all -P bind9 libbind9-60

dpkg -l |grep samba
apt-get remove samba samba-common
dpkg -l |grep samba
dpkg –force-all -P samba samba-common
安装源码编译的环境
apt-get install build-essential

 

 

获取相关开源程序
mkdir /root/soft
cd /root/soft
vim down.sh
内容如下:
wget http://sysoev.ru/nginx/nginx-0.8.34.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
wget http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz
wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget “http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0”
wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://pecl.php.net/get/imagick-2.3.0.tgz
设置可执行权限
chmod +x down.sh
开始下载
./down.sh
安装PHP 5.2.13(FastCGI模式)
编译安装PHP 5.2.13所需的支持库
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure –prefix=/usr/local
make && make install
cd ../
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
/sbin/ldconfig
cd libltdl/
./configure –-enable-ltdl-install
make && make install
cd ..
./configure
make && make install
cd ../

tar zxvf mhash-0.9.9.9.tar.gz
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./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
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make && make install
cd ../
编译安装MySQL-5.5.3-m3
mysql安装前需要安装 libncurses5-dev
apt-get install libncurses5-dev

可以开始编译mysql

groupadd mysql
useradd -g mysql mysql
tar zxvf mysql-5.5.3-m3.tar.gz
cd mysql-5.5.3-m3/
./configure –-prefix=/usr/local/webserver/mysql/ –-enable-assembler –-with-extra-charsets=complex –-enable-thread-safe-client –-with-big-tables -–with-readline –-with-ssl –-with-embedded-server –-enable-local-infile -–with-plugins=partition,innobase,myisammrg
make && make install
chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
cd ../
①、创建MySQL数据库存放目录
mkdir -p /data0/mysql/3306/data/
mkdir -p /data0/mysql/3306/binlog/
mkdir -p /data0/mysql/3306/relaylog/
chown -R mysql:mysql /data0/mysql/
②、以mysql用户帐号的身份建立数据表
/usr/local/webserver/mysql/bin/mysql_install_db –-basedir=/usr/local/webserver/mysql –-datadir=/data0/mysql/3306/data –-user=mysql

③、创建my.cnf配置文件
vi /data0/mysql/3306/my.cnf
内容参考附件
④、创建管理MySQL数据库的shell脚本
vi /data0/mysql/3306/mysql
输入内容参考附件(这里的用户名admin和密码12345678接下来的步骤会创建)

⑤、赋予shell脚本可执行权限
chmod +x /data0/mysql/3306/mysql ⑥、启动MySQL
/data0/mysql/3306/mysql start ⑦、设置MySql root用户的密码(记住,后面用到)
/usr/local/webserver/mysql/bin/mysqladmin -u root password ’123456789′ ⑧、通过命令行登录管理MySQL服务器(提示输入密码时,输入刚才设置的密码)
/usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
这时候到mysql命令行中
⑨、输入以下SQL语句,创建一个具有root权限的用户(admin)和密码(12345678)
GRANT ALL PRIVILEGES ON *.* TO ‘admin’@’localhost’ IDENTIFIED BY ’12345678′;
GRANT ALL PRIVILEGES ON *.* TO ‘admin’@’127.0.0.1′ IDENTIFIED BY ’12345678′;
exit
⑩、(可选)停止MySQL
/data0/mysql/3306/mysql stop

 

编译安装PHP(FastCGI模式)扩展
我们先来看一下下面这两个命令的作用
apt-cache search “freetype”
这个命令是在源中查找和freetype有关的所有软件,然后再根据软件包的描述,找你自己需要的软件,然后就可以用下面的命令进行安装
apt-get install libfreetype6-dev
当然是要根据错误提示来查找相关的软件。
我们在编译过程中,缺什么,就补什么,这个也算是一种解决问题的思路。希望能给大家带来点帮助!
下面也是同样的道理,我就简写了。
tar zxvf php-5.2.14.tar.gz
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
cd php-5.2.13/
./configure –prefix=/usr/local/webserver/php –with-config-file-path=/usr/local/webserver/php/etc –with-mysql=/usr/local/webserver/mysql –with-mysqli=/usr/local/webserver/mysql/bin/mysql_config –with-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-ldap –with-ldap-sasl –with-xmlrpc –enable-zip –enable-soap
make ZEND_EXTRA_LIBS=’-liconv’
make install
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ../
如果出现下面的错误提示
checking for xml2-config… no
checking for xml-config… no
configure: error: XML configuration could not be found
安装
apt-get install libxml2-dev
出现
configure: error: Cannot find OpenSSL’s <evp.h>
安装
apt-get install libssl-dev
出现
configure: error: Please reinstall the libcurl distribution –
easy.h should be in <curl-dir>/include/curl/
安装
apt-get install libcurl4-openssl-dev
出现
configure: error: libjpeg.(a|so) not found.
安装
apt-get install libjpeg62-dev
出现
configure: error: libpng.(a|so) not found.
安装
apt-get install libpng12-dev
出现
configure: error: freetype.h not found.
安装
apt-get install libfreetype6-dev
出现
configure: error: sasl.h not found!
安装
apt-get install libsasl2-dev

编译安装PHP5扩展模块
在这一步中,我们需要安装autoconf这个软件包
apt-get install autoconf
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/webserver/php/bin/phpize
./configure –with-php-config=/usr/local/webserver/php/bin/php-config
make && make install
cd ../
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/webserver/php/bin/phpize
./configure –enable-eaccelerator=shared –with-php-config=/usr/local/webserver/php/bin/php-config
make && make install
cd ../
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/webserver/php/bin/phpize
./configure –with-php-config=/usr/local/webserver/php/bin/php-config –with-pdo-mysql=/usr/local/webserver/mysql
make && make install
cd ../
安装 ImageMagick的时候make会出现
/usr/bin/ld: cannot find -lperl
这时候就要安装
apt-get install libperl-dev
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make && make install
cd ../
tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/webserver/php/bin/phpize
./configure –with-php-config=/usr/local/webserver/php/bin/php-config
make && make install
cd ../
5、修改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
自动修改:
sed -i ‘s#extension_dir = “./”#extension_dir = “/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/”\nextension = “memcache.so”\nextension = “pdo_mysql.so”\nextension = “imagick.so”\n#’ /usr/local/webserver/php/etc/php.ini
sed -i ‘s#output_buffering = Off#output_buffering = On#’ /usr/local/webserver/php/etc/php.ini
sed -i “s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g” /usr/local/webserver/php/etc/php.ini
6、配置eAccelerator加速PHP
mkdir -p /usr/local/webserver/eaccelerator_cache
vi /usr/local/webserver/php/etc/php.ini
到配置文件的最末尾,加上以下配置信息
[eaccelerator]
zend_extension=”/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/usr/local/webserver/eaccelerator_cache”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=””
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”3600″
eaccelerator.shm_prune_period=”3600″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
7、创建www用户和组,以及供debian.freeopens.com虚拟主机使用的目录
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /data0/htdocs/www
chmod +w /data0/htdocs/www
chown -R www:www /data0/htdocs/www
8、创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi)
在/usr/local/webserver/php/etc/目录中创建php-fpm.conf文件
rm -f /usr/local/webserver/php/etc/php-fpm.conf
vi /usr/local/webserver/php/etc/php-fpm.conf
内容参考附件

 

9、启动php-cgi进程,监听127.0.0.1的9000端口,进程数为128(如果服务器内存小于3GB,可以只开启64个进程),用户为www:
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start
注:/usr/local/webserver/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。
如果出现下面的错误(这个错误是我在安装过程中发现的,是内在不足导致的,在文章的结尾优化后,就不会有这样的问题了,在这里做个记录,方便大家学习)
Starting php_fpm eAccelerator: Could not allocate 67108864 bytes, the maximum size the kernel allows is 33554432 bytes. Lower the amount of memory request or increase the limit in /proc/sys/kernel/shmmax.
PHP Warning: [eAccelerator] Can not create shared memory area in Unknown on line 0
PHP Fatal error: Unable to start eAccelerator module in Unknown on line 0
failed

 

安装Nginx 0.8.34
1、安装Nginx所需的pcre库
tar zxvf pcre-8.10.tar.gz
cd pcre-8.10/
./configure
make && make install
cd ../
2、安装Nginx
tar zxvf nginx-0.8.34.tar.gz
cd nginx-0.8.34/
./configure –user=www –group=www –prefix=/usr/local/webserver/nginx –with-http_stub_status_module –with-http_ssl_module
make && make install
cd ../
3、创建Nginx日志目录
mkdir -p /data1/logs
chmod +w /data1/logs
chown -R www:www /data1/logs
4、创建Nginx配置文件
①、在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件:
rm -f /usr/local/webserver/nginx/conf/nginx.conf
vi /usr/local/webserver/nginx/conf/nginx.conf
输入内容参考附件

②、在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件
vi /usr/local/webserver/nginx/conf/fcgi.conf
5、启动Nginx
ulimit -SHn 65535
/usr/local/webserver/nginx/sbin/nginx
如果出现下面的错误
usr/local/webserver/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory
安装
apt-get install libpcre3-dev

 

配置开机自动启动Nginx + PHP + Mysql
vi /etc/rc.local
把下面的内容增加到exit 0的上面
/data0/mysql/3306/mysql start
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx
相关软件的重新启动
如果说你改了nginx的配置文件,就要用下面的命令,使配置生效
/usr/local/webserver/nginx/sbin/nginx -t
对于Nginx 0.8.x版本,现在平滑重启Nginx配置非常简单,执行以下命令即可
/usr/local/webserver/nginx/sbin/nginx -s reload
2)对于Nginx 0.8.x之前的版本,平滑重启稍微麻烦一些,按照以下步骤进行即可。输入以下命令查看Nginx主进程号
ps -ef | grep “nginx: master process” | grep -v “grep” | awk -F ‘ ‘ ‘{print $2}’
屏幕显示的即为Nginx主进程号,例如:6302
这时,执行以下命令即可使修改过的Nginx配置文件生效:kill -HUP 6302

每天定时切割Nginx日志
1、创建脚本/usr/local/webserver/nginx/sbin/cut_nginx_log.sh
vi /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
输入以下内容
#!/bin/bash
# This script run at 00:00

# The Nginx logs path
logs_path=”/usr/local/webserver/nginx/logs/”

mkdir -p ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/
mv ${logs_path}access.log ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/access_$(date -d “yesterday” +”%Y%m%d”).log
kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`
2、设置crontab,每天凌晨00:00切割nginx访问日志 crontab -e
增加以下内容
00 00 * * * /bin/bash /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

 

附件地址:http://clin003.com/wp-content/uploads/2012/10/new-www.txt