Use Cronolog to cut Tomcat logs and delete log records before the specified number of days under Linux

Source: Internet
Author: User

Use the Cronolog tool to slice Tomcat's catalina.out log files


Normal user download, install Cronolog

[[email protected] ~]$ tar-xf cronolog-1.6.2.tar.gz[[email protected] ~]$ CD Cronolog-1.6.2/[[email protected] cronolog- 1.6.2]$./configure--prefix=/home/tomcat/cronologmakemake Install

Root user download, install Cronolog

[Email protected] ~]# Rpm-qa |grep cronolog[[email protected] ~]# tar zxvf cronolog-1.6.2.tar.gz [[email protected] ~]# CD Cronolog-1.6.2[[email protected] cronolog-1.6.2]#./configure [[email protected] cronolog-1.6.2]# make && Make Install[[email protected] cronolog-1.6.2]# which cronolog/usr/local/sbin/cronolog


In the normal user's home directory, edit the. bash_profile file and add "$HOME/cronolog/sbin" to add the Cronolog installation path

[Email protected] ~]$ Vi. bash_profile

# .bash_profile                                                                                                                                                                                        # get the aliases  and functionsif [ -f ~/.bashrc ]; then         . ~/.bashrcfi# user specific environment and startup programspath=$ PATH: $HOME/bin: $HOME/cronolog/sbinexport path

With which cronolog you can find the path to the installation, which will be used when modifying catalina.sh.


Modify the catalina.sh file

Modify the 186 line "catalina_out=" $CATALINA _base "/logs/catalina.out " to 187 lines "catalina_out=" $CATALINA _base "/logs/ Opres.%y-%m-%d.out " content, log name can be defined by itself;

Comment out 370 lines of "touch" $CATALINA _out "";

383, 384 lines "

Org.apache.catalina.startup.Bootstrap "[email protected]" start \

>> "$CATALINA _out" 2>&1 "&" " Replace with 385, 386 lines "

Org.apache.catalina.startup.Bootstrap "[email protected]" Start 2>&1 \

| /home/tomcat/cronolog/sbin/cronolog "$CATALINA _out" >>/dev/null 2>&1 &

";

396, 397 lines "

Org.apache.catalina.startup.Bootstrap "[email protected]" start \

>> "$CATALINA _out" 2>&1 "&"

" Replace with 394, 395 lines "

Org.apache.catalina.startup.Bootstrap "[email protected]" Start 2>&1 \

| /home/tomcat/cronolog/sbin/cronolog "$CATALINA _out" >>/dev/null 2>&1 &

the final step (394, 395) to note that if the original command is only commented out, the content of the replacement must be on the original content, otherwise it will not start normally, the previous replacement (383, 384) position is not related

97 java_opts= "-xms512m -xmx1024m -xss1024k -xx:permsize=256m -xx:maxpermsize=512m"  98  99 # OS specific support.   $var  _must_ be set  to either true or false.185 if [ -z  "$CATALINA _out"  ]  ;  then186   # catalina_out= "$CATALINA _base"/logs/catalina.out187     catalina_out= "$CATALINA _base"/logs/opres.%y-%m-%d.out370    #touch   "$CATALINA _out" 371    if [  "$"  =  "-security"  ] ; then372      if [  $have _tty -eq 1 ]; then373        echo  "Using security manager" 374     fi375      shift376     eval  "\" $_runjava\ ""   "\" $LOGGING _config\ ""  $ logging_manager  $JAVA_opts  $CATALINA _opts 377       -djava.endorsed.dirs= "\" $JAVA _ Endorsed_dirs\ ""  -classpath  "\" $CLASSPATH \ ""  378       - djava.security.manager 379       -djava.security.policy== "\" $CATALINA _ Base/conf/catalina.policy\ ""  380       -dcatalina.base= "\" $CATALINA _ base\ " 381       -dcatalina.home=" \ "$CATALINA _home\" " 382        -djava.io.tmpdir= "\" $CATALINA _tmpdir\ ""  383       # org.apache.catalina.startup.Bootstrap  "[email protected]"  start 384       # >>  "$CATALINA _out"  2>&1  "&" 385         org.apache.catalina.startup.Bootstrap  "[email  Protected] " start 2>&1 386         | /home/tomcat/cronolog/sbin/cronolog   "$CATALINA _out"  >> /dev/null 2>&1 &387 388    else389     eval  "\" $_runjava\ " " \ "$LOGGING _config\" "  $LOGGING _ manager  $JAVA _opts  $CATALINA _opts 390       - Djava.endorsed.dirs= "\" $JAVA _endorsed_dirs\ ""  -classpath  "\" $CLASSPATH \ ""  391        -dcatalina.base= "\" $CATALINA _base\ ""  392        -dcatalina.home= "\" $CATALINA _home\ ""  393       -djava.io.tmpdir= "\" $CATALINA _tmpdir\ ""  394         org.apache.catalina.startup.bootstrap  "[email protected]"  start 2>&1 395          | /home/tomcat/cronolog/sbin/cronolog  "$CATALINA _out"  >> /dev/null 2>&1 &396      #  org.apache.catalina.startup.Bootstrap  "[email protected]"  start  397     #  >>  "$CATALINA _out"  2>&1  "& "398   fi

You can see if the configuration file is correct by using./catalina.sh start, so that the/usr/local/tomcat/logs is automatically generated every day opres.%y-%m-% D.out file, the next thing we do is to regularly clean up these outdated files, we can crontab to achieve

[[email protected] ~]$ CRONTAB-E30 3 * * */bin/find/home/tomcat/openapi/logs/-mtime +7-type f-name "Opres*.*.out"-E xec/bin/rm-f {} \; [Email protected] ~]$ crontab-l 3 * */bin/find/home/tomcat/open api/logs/-mtime +7-type f-name "Opres*.*.out"-exec/bin/rm-f {} \;

7 days before the purge is performed daily 3:30 A.M. the log expires


This article is from "Operation and maintenance record Mei Ling" blog, please be sure to keep this source http://meiling.blog.51cto.com/6220221/1911769

Use Cronolog to cut Tomcat logs and delete log records before the specified number of days under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.