{"id":7250,"date":"2018-03-08T00:51:25","date_gmt":"2018-03-07T16:51:25","guid":{"rendered":"http:\/\/rmohan.com\/?p=7250"},"modified":"2018-03-08T00:52:12","modified_gmt":"2018-03-07T16:52:12","slug":"7250","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7250","title":{"rendered":"Tomcat log cutting and regular deletion"},"content":{"rendered":"<p>Tomcat log cutting and regular deletion<\/p>\n<p>In Tomcat&#8217;s software environment, if we allow log files to grow indefinitely, one day the disk is full (crap).<br \/>\nEspecially in the case of log file growth is very fast, cutting log files by log and delete, is a very necessary work, the following describes the method of cutting log files.<\/p>\n<p>[root@server1 ~]# cat \/etc\/RedHat-release<br \/>\nCentOS release 6.5 (Final)<br \/>\n[root@server1 ~]# uname -r<br \/>\n2.6.32-431.el6.x86_64<br \/>\n[root@server1 ~]# uname -m<br \/>\nx86_64<\/p>\n<p>[root@server1 ~]# java -version<br \/>\njava version &#8220;1.7.0_67&#8221;<br \/>\nJava(TM) SE Runtime Environment (build 1.7.0_67-b01)<br \/>\nJava HotSpot(TM) Server VM (build 24.65-b04, mixed mode)<\/p>\n<p>[root@server1 ~]# \/opt\/gw\/tomcat7\/bin\/catalina.sh version<br \/>\nUsing CATALINA_BASE: \/opt\/gw\/tomcat7<br \/>\nUsing CATALINA_HOME: \/opt\/gw\/tomcat7<br \/>\nUsing CATALINA_TMPDIR: \/opt\/gw\/tomcat7\/temp<br \/>\nUsing JRE_HOME: \/usr\/local\/jdk1.7<br \/>\nUsing CLASSPATH: \/opt\/gw\/tomcat7\/bin\/bootstrap.jar:\/opt\/gw\/tomcat7\/bin\/tomcat-juli.jar<br \/>\nServer version: Apache Tomcat\/7.0.57<br \/>\nServer built: Nov 3 2014 08:39:16 UTC<br \/>\nServer number: 7.0.57.0<br \/>\nOS Name: Linux<br \/>\nOS Version: 2.6.32-431.el6.x86_64<br \/>\nArchitecture: i386<br \/>\nJVM Version: 1.7.0_67-b01<br \/>\nJVM Vendor: Oracle Corporation<\/p>\n<p>cd \/usr\/local\/src<br \/>\nwget https:\/\/files.cnblogs.com\/files\/crazyzero\/cronolog-1.6.2.tar.gz<br \/>\n[root@mohan src]# md5sum cronolog-1.6.2.tar.gz<br \/>\na44564fd5a5b061a5691b9a837d04979 cronolog-1.6.2.tar.gz<\/p>\n<p>[root@mohan src]# tar xf cronolog-1.6.2.tar.gz<br \/>\n[root@mohan src]# cd cronolog-1.6.2<br \/>\n[root@mohan cronolog-1.6.2]# .\/configure<br \/>\n[root@mohan cronolog-1.6.2]# make &amp;&amp; make install<br \/>\n[root@mohan cronolog-1.6.2]# which cronolog<br \/>\n\/usr\/local\/sbin\/cronolog<\/p>\n<p>[root@server1 ~]# which cronolog<br \/>\n\/usr\/local\/sbin\/cronolog<\/p>\n<p>Chapter 3 configuration tomcat log cutting<br \/>\nConfiguration log cutting, simply modify the configuration file catalina.sh (if windows is catalina.bat, here does not introduce the case of windows) can be.<br \/>\nProbably in the catalina file on the 380th and 390th lines, amended as follows:<\/p>\n<p>org.apache.catalina.startup.Bootstrap &#8220;$@&#8221; start \\<br \/>\n&gt;&gt; &#8220;$CATALINA_OUT&#8221; 2&gt;&amp;1 &#8220;&amp;&#8221;<\/p>\n<p>org.apache.catalina.startup.Bootstrap &#8220;$@&#8221; start \\<br \/>\n2&gt;&amp;1 |\/usr\/local\/sbin\/cronolog &#8220;$CATALINA_BASE\/logs\/catalina-%Y-%m-%d.out&#8221; &amp;<\/p>\n<p>org.apache.catalina.startup.Bootstrap &#8220;$@&#8221; start \\<br \/>\n&gt;&gt; &#8220;$CATALINA_OUT&#8221; 2&gt;&amp;1 &#8220;&amp;&#8221;<\/p>\n<p>org.apache.catalina.startup.Bootstrap &#8220;$@&#8221; start \\<br \/>\n2&gt;&amp;1 |\/usr\/local\/sbin\/cronolog &#8220;$CATALINA_BASE\/logs\/catalina-%Y-%m-%d.out&#8221; &amp;<\/p>\n<p>00 00 * * * \/bin\/find \/opt\/gdyy\/tomcat7\/logs\/ -type f -mtime +7 | xargs rm -f &amp;&gt;\/dev\/null<\/p>\n<p>remove gw log 7 days ago by liutao at 2018-02-08<br \/>\n00 00 * * * \/bin\/find \/opt\/gw\/tomcat7\/logs\/ -type f -mtime +7 | xargs -i mv {} \/data\/bak\/gw_log\/ &amp;&gt;\/dev\/null<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tomcat log cutting and regular deletion<\/p>\n<p>In Tomcat&#8217;s software environment, if we allow log files to grow indefinitely, one day the disk is full (crap). Especially in the case of log file growth is very fast, cutting log files by log and delete, is a very necessary work, the following describes the method of cutting [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7250"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7250"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7250\/revisions"}],"predecessor-version":[{"id":7252,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7250\/revisions\/7252"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}