用cronolog分割Nginx日志

方法一(来源网络):

1,安装cronolog

wget http://cronolog.org/download/cronolog-1.6.2.tar.gz

tar zxvf cronolog-1.6.2.tar.gz

cd cronolog-1.6.2

mkdir -p /usr/local/cronolog

./configure --prefix=/usr/local/cronolog

make

make install

2,创建一个命名管道

mkfifo /data/access_log_pipe

3,配置cronolog:

nohup cat /data/access_log_pipe | /usr/local/cronolog/sbin/cronolog /data/logs/%Y%m%d/access_%Y%m%d%H%M.log &

4,配置nginx.conf日志

log_format post_tracking '{\"ip\":\"$remote_addr\",\"request\":\"$request\",\"body\":\"$request_body\",\"time\":\"$time_local\",\"status\":\"$status\"}';

access_log  /data/access_log_pipe post_tracking;

5,重启Nginx

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

方法二:

1,安装cronolog

wget http://cronolog.org/download/cronolog-1.6.2.tar.gz

tar zxvf cronolog-1.6.2.tar.gz

cd cronolog-1.6.2

mkdir -p /usr/local/cronolog

./configure --prefix=/usr/local/cronolog

make

make install

2,配置cronolog:

nohup cat /data/www/log/nginx.log | /usr/sbin/cronolog -z Asia/Shanghai /data/log/nginx-access-%Y%m%d.log &

3,配置nginx

log_format access '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" $http_x_forwarded_for';


access_log /data/www/log/nginx.log;

4,重启Nginx

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


你可能感兴趣的:(用cronolog分割Nginx日志)