In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to regularly cut the Tomcat log and delete the log record before the specified number of days under Linux, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
Both System.out and System.err are printed to catalina.out. Catalina.out does not rotate. Generally speaking, after the deployment of Tomcat, after running for a long time, the catalina.out file will become larger and larger, which has a certain impact on the stability of the system.
1. You can mask this part of the log information by modifying the conf/logging.properties log configuration file.
[root@localhost conf] # pwd/usr/local/tomcat/conf [root@localhost conf] # cp logging.properties logging.propertiesbak [root@localhost conf] # vim logging.properties 25 1catalina.org.apache.juli.FileHandler.level = FINE 26 1catalina.org.apache.juli.FileHandler.directory = ${catalina.base} / logs 27 1catalina.org.apache.juli.FileHandler.prefix = catalina.
Setting the level level to WARNING can greatly reduce log output, or you can set it to OFF and disable it directly.
The general log levels are as follows:
SEVERE (highest value) > WARNING > INFO > CONFIG > FINE > FINER > FINEST (lowest value)
2. Use cronolog tool to split the catalina.out log file of Tomcat.
Download and install cronolog
[root@localhost src] # rpm-qa | grep cronolog [root@localhost src] # tar zxvf cronolog-1.6.2.tar.gz [root@localhost src] # cd cronolog-1.6.2 [root@localhost cronolog-1.6.2] #. / configure [root@localhost cronolog-1.6.2] # make & & make install [root@localhost cronolog-1.6.2] # which cronolog/usr/local/sbin/cronolog [root@localhost cronolog-1.6.2] #
The installation path can be found with which cronolog, which will be used later when modifying catalina.sh.
Modify catalina.sh to change 183lines to 184lines, commenting out 355 lines, replacing lines 368,369 with lines 370,371, lines 379,380 with lines 381,382
[root@localhost cronolog-1.6.2] # cp / usr/local/tomcat/bin/catalina.sh / usr/local/tomcat/bin/catalina.shbak [root@localhost cronolog-1.6.2] # vim / usr/local/tomcat/bin/catalina.sh182 if [- z "$CATALINA_OUT"] Then183 # CATALINA_OUT= "$CATALINA_BASE" / logs/catalina.out184 CATALINA_OUT= "$CATALINA_BASE" / logs/catalina.%Y-%m-%d.out185 fi.355 # touch "$CATALINA_OUT" .363-Djava.security.manager\ 364-Djava.security.policy== "$CATALINA_BASE" / conf/catalina.policy\ 365-Dcatalina.base= "$CATALINA_BASE"\ 366-Dcatalina.home= "$CATALINA_HOME"\ 367 -Djava.io.tmpdir= "$CATALINA_TMPDIR"\ 368 # org.apache.catalina.startup.Bootstrap "$@" start\ 369 # > > "$CATALINA_OUT" 2 > & 1 & 370 org.apache.catalina.startup.Bootstrap "$@" start 2 > & 1\ 371 | / usr/local/sbin/cronolog "$CATALINA_OUT" > > / dev/null & 372373 else374 "$_ RUNJAVA"$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS\ 375-Djava.endorsed .dirs = "$JAVA_ENDORSED_DIRS"-classpath "$CLASSPATH"\ 376-Dcatalina.base= "$CATALINA_BASE"\ 377-Dcatalina.home= "$CATALINA_HOME"\ 378-Djava.io.tmpdir= "$CATALINA_TMPDIR"\ 379 # org.apache.catalina.startup.Bootstrap "$@" start\ 380 # > "$CATALINA_OUT" 2 > & 1 & 381 org.apache.catalina.startup.Bootstrap "$@" start 2 > & 1\ 382 | / usr/local/ Sbin/cronolog "$CATALINA_OUT" > > / dev/null & 383 384 fi [root@localhost bin] #. / catalina.sh startUsing CATALINA_BASE: / app/apache-tomcat-7.0.61Using CATALINA_HOME: / app/apache-tomcat-7.0.61Using CATALINA_TMPDIR: / app/apache-tomcat-7.0.61/tempUsing JRE_HOME: / app/jdk1.7.0_79Using CLASSPATH: / app/apache-tomcat-7.0.61/bin/bootstrap .jar: / app/apache-tomcat-7.0.61/bin/tomcat-juli.jarTomcat started. [root@localhost bin] # service tomcat stop [root@localhost bin] # service tomcat start
You can check whether the configuration file is correct through. / catalina.sh start; this will automatically generate catalina.%Y-%m-%d.out files in / usr/local/tomcat/logs every day. The next thing we need to do is to clean up these expired files on a regular basis, which we can do through crontab.
[root@localhost logs] # crontab-eno crontab for root-using an empty onecrontab: installing new crontab [root@localhost logs] # crontab-l305 * * 6 / bin/find / usr/local/tomcat/logs/-mtime + 7-type f-name "catalina.*.out"-exec / bin/rm-f {}\ [root@localhost logs] # cat/ var/spool/cron/root 30 5 * * 6 / bin/find / usr/local/tomcat/logs/-mtime + 7-type f-name "catalina.*.out"-exec / bin/rm-f {}\; [root@localhost logs] #
Date format string:
% a Local short week name (e.g.: Sun..Sat)% A Local full week name (e.g.: Sunday. Saturday)% b local short month name (e.g.: Jan. Dec)% B local full month name (e.g.: January. December)% c local date and time (e.g.: "Sun Dec 15 14:12:47 GMT 1996")% d the day of the month (01.. 31)% j the day of the year (001.. 366) the numerical representation of m month name (01.. 12)% U the number of weeks calculated with Sunday as the first day of the week (00. 53, the first week includes the first Sunday of the New year)% W the week of the year with Monday as the first day of the week (00. 53, the first week includes the first Monday of the New year)% w week name (0.. 6, 0 is Sunday)% x local date (e.g. Today in Beijing is: "15-12-96")% y year without century (00.. 99)% Y belt century year (1970.. 2038)
Time format string:
% H 24-hour (00.23)% I 12hourly (01.12)% p local AM/PM indicator% M minutes (00.59)% s seconds (00.61)% X local time (e.g.: "15:12:47")% Z time zone (e.g. GMT) if the time zone cannot be detected Value is empty
Special format string:
% character% n new line% t tab character thank you for reading this article carefully. I hope the article "how to regularly cut Tomcat logs and delete log records before a specified number of days under Linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.