1.安装PCRE

 tar xvf pcre-8.31.tar.gz

 cd pcre-8.31

 ./configure --prefix=/usr/local/webserver/pcre

 make && make install

cp/usr/local/webserver/pcre/lib/libpcre.a  /usr/local/webserver/pcre/libpcre.a

cp/usr/local/webserver/pcre/lib/libpcre.la  /usr/local/webserver/pcre/libpcre.la

cp/usr/local/webserver/pcre/include/pcre.h  /usr/local/webserver/pcre/pcre.h

mkdir /usr/local/webserver/pcre/.libs

cp/usr/local/webserver/pcre/lib/libpcre.a  /usr/local/webserver/pcre/.libs/libpcre.a

cp/usr/local/webserver/pcre/lib/libpcre.la  /usr/local/webserver/pcre/.libs/libpcre.la

cp/usr/local/webserver/pcre/include/pcre.h  /usr/local/webserver/pcre/.libs/pcre.h

2.安装nginx 

tar xvf nginx-1.8.0.tar.gz

cd nginx-1.8.0

./configure--user=nobody--group=nobody--prefix=/usr/local/webserver/nginx--with-http_stub_status_module--without-http_gzip_module

 make && make install

3.创建Nginx日志目录

        mkdir -p /var/log/nginx

        chmod 777 /var/log/nginx

        chown -R nobody:nobody /var/log/nginx

 

创建Nginx配置文件

cd /usr/local/webserver/nginx/conf/

cp -rf nginx.conf nginx.conf.bak

vi /usr/local/webserver/nginx/conf/nginx.conf

 

启动Nginx

ulimit -SHn 65535 >>/etc/profile

source /etc/profile

/usr/local/webserver/nginx/sbin/nginx

netstat -anlp | grep nginx

 

4.切割Nginx日志

        vi /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

================================================

        输入以下内容, 保存:

#!/bin/bash

# This script run at 00:00

 

# The Nginx logs path

logs_path="/var/log/nginx/"

logs_bak_path="/var/log/nginx_bak/"

 

mkdir -p ${logs_bak_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/

cp ${logs_path}access.log ${logs_bak_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log

rm -rf ${logs_path}*.log

kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`

================================================

        #crontab -e        ------->设置crontab,每天凌晨00:00切割nginx访问日志

================================================

    输入以下内容

00 00 * * * /bin/bash  /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

posted on 2016-05-27 12:52  lihanbing  阅读(228)  评论(0编辑  收藏  举报