{"id":5391,"date":"2023-07-31T09:56:14","date_gmt":"2023-07-31T14:56:14","guid":{"rendered":"https:\/\/www.incredigeek.com\/home\/?p=5391"},"modified":"2023-07-31T09:56:19","modified_gmt":"2023-07-31T14:56:19","slug":"log-rotation-for-rsyslog-using-fixed-size","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/log-rotation-for-rsyslog-using-fixed-size\/","title":{"rendered":"Log rotation for rsyslog using fixed size"},"content":{"rendered":"\n<p>We&#8217;ll follow the documentation from <a href=\"https:\/\/www.rsyslog.com\/files\/temp\/doc-indent\/tutorials\/log_rotation_fix_size.html\">here<\/a>.  <\/p>\n\n\n\n<p>Changes are made to the \/etc\/rsyslog.conf config file.<\/p>\n\n\n\n<p>For this example, we will be configuring our named.log file to not exceed 50MiB, and then we&#8217;ll have a rotated log &#8220;.1&#8221; that is also 50MiB.  Total it should not exceed 100BMiB.<\/p>\n\n\n\n<p>First we need to create an out channel, and then we assign the out channel to a logging channel.  We also need a script that rotates the logs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create the Output Channel<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">$outchannel log_rotation,\/var\/log\/named.log, 52428800,\/home\/user\/log_rotation.sh<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Assign Output Channel to Logging Channel<\/h2>\n\n\n\n<p>On our line that is logging named, at the end add :$log_rotation<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">local0.*                   \/var\/log\/named.log:$log_rotation<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Script to Rotate Log<\/h2>\n\n\n\n<p>Somewhere on the system, create a rotate.sh script.  Name it whatever you want, just be sure the path and name in the rsyslog.conf is the same.<\/p>\n\n\n\n<p>Add the following one line to move the current log to a rotate log.  <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mv -f \/var\/log\/named.log \/var\/log\/named.log.1<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>As the log fills up and hits ~50MiB, the named.sh script will run which rotates(moves) the log file to logfile.log.1.  This will keep our usage for named.log to 100MiB.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ll follow the documentation from here. Changes are made to the \/etc\/rsyslog.conf config file. For this example, we will be configuring our named.log file to not exceed 50MiB, and then we&#8217;ll have a rotated log &#8220;.1&#8221; that is also 50MiB. &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/log-rotation-for-rsyslog-using-fixed-size\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[7,234,424,564],"class_list":["post-5391","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux-2","tag-log","tag-named","tag-syslog"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=5391"}],"version-history":[{"count":4,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5391\/revisions"}],"predecessor-version":[{"id":5395,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5391\/revisions\/5395"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=5391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=5391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=5391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}