第一种方法:yum 安装cronolog软件
1.yum install cronolog -y 第三方软件
源码包下载地址
http://download.chinaunix.net/download.php?id=3457&ResourceID=1851
2.修改配置文件。修改前记得备份
[root@tomcat01 sbin]# cat -n /aliyun/tomcat7/bin/catalina.sh
184 #if [ -z "$CATALINA_OUT" ] ; then
185 # CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
186 #fi
改为下面的
187 ###################
188 if [ -z "$CATALINA_OUT" ] ; then
189 CATALINA_OUT="$CATALINA_BASE"/logs/tomcat01.$(date +%F).out
190 fi
191 #####################
注释掉373 #touch "$CATALINA_OUT"
386 387 改为一下:
386 org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
387 | /usr/local/sbin/cronolog "$CATALINA_OUT" >> /dev/null &
395 396 改为一下:
395 org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
396 | /usr/local/sbin/cronolog "$CATALINA_OUT" >> /dev/null &
注意此两处修改不要注视,注释启动tomcat时会报错。要直接删掉这两处的原内容

[root@tomcat01 logs]# /aliyun/tomcat7/bin/startup.sh
报错:/usr/local/sbin/ 没有cronolog
[root@tomcat01 logs]# cp /usr/sbin/cronolog /usr/local/sbin/
/aliyun/tomcat7/bin/startup.sh (成功)
如果抱错catalina.sh,说明此脚本文件没有执行权限,所以 chown +x catalina.sh
3.区分不同的tomcat机器的日志方便集中收集tomcat实时日志
[root@tomcat01 logs]# vim /aliyun/tomcat7/bin/catalina.sh
188 if [ -z "$CATALINA_OUT" ] ; then
189 ATALINA_OUT="$CATALINA_BASE"/logs/ tomcat01.$(date +%F).out
190 fi
/aliyun/tomcat7/bin/startup.sh
[root@tomcat01 logs]# find ./ -type f -name "tomcat01.2016-04-22.out"
./tomcat1.2016-04-22.out

[root@tomcat01 logs]# vim /aliyun/tomcat7/bin/catalina.sh
188 if [ -z "$CATALINA_OUT" ] ; then
189 ATALINA_OUT="$CATALINA_BASE"/logs/ tomcat01.$(date +%F).out
190 fi
/aliyun/tomcat7/bin/startup.sh
[root@tomcat01 logs]# find ./ -type f -name "tomcat01.2016-04-22.out"
./tomcat01.2016-04-22.out

第二种方法源码包编译安装cronolog第三方tomcat日志切割软件
1.源码包下载地址
http://download.chinaunix.net/download.php?id=3457&ResourceID=1851
2.安装过程
cd /aliyun/soft/
rz -y cronolog-1.6.2.tar.gz
ls
tar xf cronolog-1.6.2.tar.gz -C /aliyun/
cd /aliyun/cronolog-1.6.2/
./configure
echo $?
make && make install
echo $?
[root@tomcat02 sbin]# ll /usr/local/sbin/
total 52
-rwxr-xr-x 1 root root 40438 May 12 09:15 cronolog
-rwxr-xr-x 1 root root 9673 May 12 09:15 cronosplit
到此处编译安装完成
3.编辑文件按天切割日志
vim /aliyun/tomcat7/bin/catalina.sh

[root@tomcat01 sbin]# cat -n /aliyun/tomcat7/bin/catalina.sh
184 #if [ -z "$CATALINA_OUT" ] ; then
185 # CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
186 #fi
改为下面的
187 ###################
188 if [ -z "$CATALINA_OUT" ] ; then
189 CATALINA_OUT="$CATALINA_BASE"/logs/tomcat01.$(date +%F).out
190 fi
191 #####################
注释掉373 #touch "$CATALINA_OUT"
386 387 改为一下:
386 org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
387 | /usr/local/sbin/cronolog "$CATALINA_OUT" >> /dev/null &
395 396 改为一下:
395 org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
396 | /usr/local/sbin/cronolog "$CATALINA_OUT" >> /dev/null &
注意此两处修改不要注视,注释启动tomcat时会报错。要直接删掉这两处的原内容
4.重新启动tomcat生效
[root@tomcat02 sbin]# ll /aliyun/tomcat7/logs/
total 0
[root@tomcat02 sbin]# /etc/init.d/tomcat7 stop
tomcat7 service is stopped! [ OK ]
[root@tomcat02 sbin]# ll /aliyun/tomcat7/logs/
total 0
[root@tomcat02 sbin]# /etc/init.d/tomcat7 start
tomcat7 service is starting! [ OK ]
[root@tomcat02 sbin]# ll /aliyun/tomcat7/logs/
total 16
-rw-r--r-- 1 root root 4295 May 12 09:34 catalina.2016-05-12.log
-rw-r--r-- 1 root root 0 May 12 09:34 localhost.2016-05-12.log
-rw-r--r-- 1 root root 0 May 12 09:34 localhost_access_log.2016-05-12.txt
-rw-r--r-- 1 root root 4295 May 12 09:34 tomcat02.2016-05-12.out