目标:
nginx cronolog日志分割配置文档,每分钟分割一次NGINX访问日志。
大体步骤如下:
1.nginx日志配置
access_log /var/log/nginx/access.log_pipe main;
2.先创建一个命名管道 
mkfifo /var/log/nginx/access.log_pipe 3.配置cronolog按年月日时分保存分割后的文件
nohup cat /var/log/nginx/access.log_pipe | cronolog /var/log/nginx/domain.access_%Y%m%d%H%M.log 2>&1 & 4.启动Nginx
/usr/local/nginx/sbin/nginx
注意: cronolog必须在nginx启动前启动

最后详细讲解下cronolog的安装使用:

(1).直接用yum安装

1
[root@node6 src]# yum install -y cronolog httpd
 

好了,到这里我们的cronolog就安装完成了,下面我们来说一下cronolog如何使用。

(3)cronolog 使用

.基本使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@node6 ~]# cronolog -h
usage: cronolog [OPTIONS] logfile-spec
   -H NAME,   --hardlink=NAME maintain a hard link from NAME to current log
   -S NAME,   --symlink=NAME  maintain a symbolic link from NAME to current log
   -P NAME,   --prev-symlink=NAME  maintain a symbolic link from NAME to previous log
   -l NAME,   --link=NAME     same as -S/--symlink
   -h,        --help          print this help, then exit
   -p PERIOD, --period=PERIOD set the rotation period explicitly
   -d DELAY,  --delay=DELAY   set the rotation period delay
   -o,        --once-only     create single output log from template (not rotated)
   -x FILE,   --debug=FILE    write debug messages to FILE
                              ( or to standard error if FILE is "-")
   -a,        --american         American date formats
   -e,        --european         European date formats (default)
   -s,    --start-time=TIME   starting time
   -z TZ, --time-zone=TZ      use TZ for timezone
   -V,      --version         print version number, then exit

cronolog 一般是采取管道的方式来工作的,采用如下的形式:

1
[root@node6 ~]# loggenerator | cronolog log_file_pattern

其中,loggenerator为产生log的程序,而log_file_pattern是日志文件的路径,可以在其中加入cronolog所支持的时间相关的pattern字符,如/www/log/%y/%m/%d/access.log。其pattern为%字符后跟一特殊字符,简述如下:

转义符:

1
2
3
%    %字符
n    换行
t    水平制表符

时间域:

1
2
3
4
5
6
7
H    小时(00..23)
I    小时(01..12)
p    该locale下的AM或PM标识
M    分钟(00..59)
S    秒 (00..61, which allows for leap seconds)
X    该locale下时间表示符(e.g.: "15:12:47")
Z    时区。若时区不能确定,则无意义

日期域:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
a    该locale下的工作日简名(e.g.: Sun..Sat)
A    该locale下的工作日全名(e.g.: Sunday ..  Satur-ay)
b    该locale下的月份简称(e.g.: Jan .. Dec)
B    该locale下的月份全称(e.g.:  January .. December)
c    该locale下的日期和时间(e.g.: "Sun Dec 15  14:12:47 GMT 1996")
d    当月中的天数 (01 .. 31)
j    当年中的天数 (001 .. 366)
m    月数 (01 .. 12)
U    当年中的星期数,以周日作为一周开始,其中第一周为首个含星期天的星期(00..53)
W    当年中的星期数,以星期一作为一周的开始,其中第一周为首个含星期天的星期(00..53)
w    工作日数(0 .. 6, 0表示星期天)
x    该locale下的日期表示(e.g. "13/04/97")
y    两位数的年份(00 .. 99)
Y    四位数的年份(1970 .. 2038)
 

下面是效果

1
2
3
4
5
6
7
[root@localhost ~]# cd /log/www/
[root@localhost www]# ll
total 15072
-rw-r--r-- 1 root root   16028 Dec 26 15:16 access_20131225.log
-rw-r--r-- 1 root root 2406307 Dec 26 23:59 access_20131226.log
-rw-r--r-- 1 root root 8292792 Dec 27 23:59 access_20131227.log
-rw-r--r-- 1 root root 4682211 Dec 28 18:56 access_20131228.log
												

最新文章

  1. sql 批量插入数据到Sqlserver中 效率较高的方法
  2. Java 读取Properties文件时应注意的路径问题
  3. js 浮点运算出现的精度丢失问题
  4. css before&after 特殊用途
  5. saiku执行速度慢
  6. Visual Studio Code初探
  7. 微软SQLHelper.cs类 中文版
  8. 记事本写hello world_Java
  9. php composer使用
  10. Gradle 1.12翻译——第十九章. Gradle 守护进程
  11. k8s的flannel的pod运行一段时间init error
  12. Game Engine Architecture 3
  13. Node.js这么下去...
  14. Mysql Window 解压版卸载
  15. Linux下快速分区格式化大于2T磁盘存储
  16. webkit下面的CSS设置滚动条
  17. Python Counter
  18. django相关
  19. Huffman 编码压缩算法
  20. js 判断 obj 是否是 数组 array

热门文章

  1. 状态压缩DP----HDU2809
  2. 软件工程实践一 —— java之wc.exe
  3. android eclipse 报error loading /system/media/audio/ xxx 错的解决办法。
  4. python之numpy文件操作
  5. 国外物联网平台(4):Ayla Networks
  6. C# 常用正则验证[转]
  7. excel文档中嵌入对象(excel、word等)
  8. OO 抽象类与接口的区别
  9. 题解 P3386 【【模板】二分图匹配】
  10. application的使用(实现计数器)