{"id":178,"date":"2024-05-07T10:09:28","date_gmt":"2024-05-07T10:09:28","guid":{"rendered":"https:\/\/www.rajeshkumar.xyz\/blog\/?p=178"},"modified":"2024-06-11T14:32:40","modified_gmt":"2024-06-11T14:32:40","slug":"how-to-install-and-configure-logroate-in-linux","status":"publish","type":"post","link":"https:\/\/www.rajeshkumar.xyz\/blog\/how-to-install-and-configure-logroate-in-linux\/","title":{"rendered":"How to Install and configure Logroate in Linux?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">almalinux os<\/h2>\n\n\n\n<p>To configure logrotate in AlmaLinux, you can follow these steps to ensure your system logs are properly managed and rotated. Logrotate is a system utility that manages the automatic rotation and compression of log files. If logrotate isn&#8217;t already installed, you can install it using the package manager, and then configure it by creating or editing configuration files.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Install Logrotate<\/h3>\n\n\n\n<p>First, make sure logrotate is installed on your system. You can install it using the <code>dnf<\/code> package manager:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">sudo dnf install logrotate<\/code><\/span><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Step 2: Create or Edit a Logrotate Configuration File<\/h3>\n\n\n\n<p>Logrotate configurations are usually stored in <code>\/etc\/logrotate.conf<\/code> for global settings, and additional custom settings can be placed in <code>\/etc\/logrotate.d\/<\/code>.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Edit the main configuration file:<\/strong> Open <code>\/etc\/logrotate.conf<\/code> in a text editor:bashCopy code<code>sudo nano \/etc\/logrotate.conf <\/code>This file contains global settings and defaults.<\/li>\n\n\n\n<li><strong>Create a custom logrotate file:<\/strong> It&#8217;s a common practice to create individual configuration files for different applications under <code>\/etc\/logrotate.d\/<\/code>. For example, to create a logrotate configuration for your custom application logs:<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">sudo nano \/etc\/logrotate.d\/myapp<\/code><\/span><\/pre>\n\n\n<p>Add configuration options like:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">\/<span class=\"hljs-keyword\">var<\/span>\/log\/myapp<span class=\"hljs-comment\">\/*.log {\n    daily\n    rotate 14\n    compress\n    delaycompress\n    missingok\n    notifempty\n    create 0640 root adm\n    sharedscripts\n    postrotate\n        \/usr\/bin\/systemctl reload myapp.service &gt; \/dev\/null\n    endscript\n}\n<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ol class=\"wp-block-list\">\n<li>Here\u2019s what each directive means:\n<ul class=\"wp-block-list\">\n<li><strong>daily<\/strong>: Rotate the logs daily.<\/li>\n\n\n\n<li><strong>rotate 14<\/strong>: Keep 14 copies of the log files.<\/li>\n\n\n\n<li><strong>compress<\/strong>: Compress (gzip) the log files.<\/li>\n\n\n\n<li><strong>delaycompress<\/strong>: Compress the previous day\u2019s log files.<\/li>\n\n\n\n<li><strong>missingok<\/strong>: Do not output an error if the log file is missing.<\/li>\n\n\n\n<li><strong>notifempty<\/strong>: Do not rotate the log if it is empty.<\/li>\n\n\n\n<li><strong>create 0640 root adm<\/strong>: Create new log files with set permissions\/owner\/group.<\/li>\n\n\n\n<li><strong>sharedscripts<\/strong>: Run the scripts at the end only once, not for each log file which is rotated.<\/li>\n\n\n\n<li><strong>postrotate\/end script<\/strong>: Commands inside this block are executed after the log file is rotated.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Test Your Configuration<\/h3>\n\n\n\n<p>To test your logrotate configuration:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">sudo logrotate --debug \/etc\/logrotate.conf\n<\/code><\/span><\/pre>\n\n\n<pre class=\"wp-block-preformatted\">This command will show you what logrotate will do, but it won\u2019t actually rotate the logs. It's useful for making sure your configurations are set up correctly.<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Manually Run Logrotate<\/h3>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">sudo logrotate -vf \/etc\/logrotate.conf\n\n-v (verbose) will give you detailed output.\n-f (force) will force the rotation.<\/code><\/span><\/pre>\n\n\n<p><strong>Step 4: Automate Logrotate<\/strong><\/p>\n\n\n\n<p><strong>Logrotate is typically automated as a daily cron job. Check the <code>\/etc\/cron.daily\/logrotate<\/code> script to ensure it\u2019s being run automatically by cron.<\/strong><\/p>\n\n\n\n<p>The logrotate process typically runs automatically on most Linux distributions, including AlmaLinux, as it is usually set up as a daily cron job during installation. However, if you need to ensure it is set up and running, or if you want to customize its schedule, here\u2019s a step-by-step guide on how to automate logrotate.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Verify Logrotate Installation<\/h3>\n\n\n\n<p>First, make sure logrotate is installed and check if the cron job is already in place:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">rpm -q logrotate\nls -l \/etc\/cron.daily\/logrotate<\/code><\/span><\/pre>\n\n\n<h3 class=\"wp-block-heading\">How to see all the log file which is being rotated with schedule\\<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">cat \/etc\/logrotate.conf\ncat \/etc\/logrotate.d\/&lt;file&gt;\n\ngrep -E <span class=\"hljs-string\">\"^\\s*&#91;^\\s#]\"<\/span> \/etc\/logrotate.conf\ngrep -E <span class=\"hljs-string\">\"^\\s*&#91;^\\s#]\"<\/span> \/etc\/logrotate.d<span class=\"hljs-comment\">\/*\n\nThis will list all non-commented lines, which typically include the log file paths and rotation settings.<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Understand the Default Automation<\/h3>\n\n\n\n<p>By default, logrotate is run by a script in <code>\/etc\/cron.daily\/<\/code>. This directory contains scripts that are run daily by <code>cron<\/code>. The <code>logrotate<\/code> script in this directory typically looks something like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\">$ vi <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">span<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">\"background-color: rgba(34, 34, 34, 0.2); font-family: inherit; color: var(--wp--preset--color--body-text); font-size: var(--wp--preset--font-size--normal); font-weight: var(--wp--custom--typography--font-weight--normal);\"<\/span>&gt;<\/span>\/etc\/cron.daily\/logrotate<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">span<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">span<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">\"background-color: rgba(34, 34, 34, 0.2); font-family: inherit; color: var(--wp--preset--color--body-text); font-size: var(--wp--preset--font-size--normal); font-weight: var(--wp--custom--typography--font-weight--normal);\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">span<\/span>&gt;<\/span> \n\n#!\/bin\/sh\n\n\/usr\/sbin\/logrotate \/etc\/logrotate.conf\nEXITVALUE=$?\nif &#91; $EXITVALUE != 0 ]; then\n    \/usr\/bin\/logger -t logrotate \"ALERT exited abnormally with &#91;$EXITVALUE]\"\nfi\nexit 0\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>Ensure the Cron Daemon is Running<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">sudo<\/span> <span class=\"hljs-selector-tag\">systemctl<\/span> <span class=\"hljs-selector-tag\">status<\/span> <span class=\"hljs-selector-tag\">crond<\/span><span class=\"hljs-selector-class\">.service<\/span>\n<span class=\"hljs-selector-tag\">sudo<\/span> <span class=\"hljs-selector-tag\">systemctl<\/span> <span class=\"hljs-selector-tag\">restart<\/span> <span class=\"hljs-selector-tag\">crond<\/span><span class=\"hljs-selector-class\">.service<\/span>\n<span class=\"hljs-selector-tag\">sudo<\/span> <span class=\"hljs-selector-tag\">systemctl<\/span> <span class=\"hljs-selector-tag\">enable<\/span> <span class=\"hljs-selector-tag\">crond<\/span><span class=\"hljs-selector-class\">.service<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Check Logrotate Status and Logs<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">sudo grep logrotate \/<span class=\"hljs-keyword\">var<\/span>\/log\/syslog\nsudo grep logrotate \/<span class=\"hljs-keyword\">var<\/span>\/log\/messages\n\ncat \/<span class=\"hljs-keyword\">var<\/span>\/lib\/logrotate\/status\nor\ncat \/<span class=\"hljs-keyword\">var<\/span>\/lib\/logrotate\/logrotate.status\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Check for Errors or Misconfigurations<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">Sometimes logrotate may not work due to errors in the configuration files. Validate the syntax:\n\nTest logrotate configuration:\n\nsudo logrotate --debug \/etc\/logrotate.conf\n\nThis command will perform a dry run <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-keyword\">print<\/span> out what logrotate would <span class=\"hljs-keyword\">do<\/span> without actually rotating the logs.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>OPTIONAL<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Customize the Automation (Optional)\nIf you want logrotate to run more frequently than once a day, you can create a custom cron job:\n\nOpen the cron table <span class=\"hljs-keyword\">for<\/span> editing:\n\nsudo crontab -e\nAdd a <span class=\"hljs-keyword\">new<\/span> line <span class=\"hljs-keyword\">for<\/span> your custom schedule:For example, to run logrotate every <span class=\"hljs-number\">12<\/span> hours, you could add:\n\n<span class=\"hljs-number\">0<\/span> *<span class=\"hljs-regexp\">\/12 * * * \/u<\/span>sr\/sbin\/logrotate \/etc\/logrotate.conf\nThis cron job runs at minute <span class=\"hljs-number\">0<\/span> every <span class=\"hljs-number\">12<\/span>th hour <span class=\"hljs-keyword\">of<\/span> every day.\nSave and exit the editor.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Permission Error<\/h2>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">&#91;root@ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> logrotate.d]<span class=\"hljs-comment\"># sudo grep logrotate \/var\/log\/messages<\/span>\nJun <span class=\"hljs-number\">11<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">01<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> logrotate&#91;<span class=\"hljs-number\">4063447<\/span>]: error: failed to open config file usertracker: Permission denied\nJun <span class=\"hljs-number\">11<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">01<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> logrotate&#91;<span class=\"hljs-number\">4063447<\/span>]: error: found error in file usertracker, skipping\nJun <span class=\"hljs-number\">11<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">01<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> systemd&#91;<span class=\"hljs-number\">1<\/span>]: logrotate.service: Main process exited, code=exited, status=<span class=\"hljs-number\">1<\/span>\/FAILURE\nJun <span class=\"hljs-number\">11<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">01<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> systemd&#91;<span class=\"hljs-number\">1<\/span>]: logrotate.service: Failed with result <span class=\"hljs-string\">'exit-code'<\/span>.\nJun  <span class=\"hljs-number\">9<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> logrotate&#91;<span class=\"hljs-number\">3950100<\/span>]: error: failed to open config file usertracker: Permission denied\nJun  <span class=\"hljs-number\">9<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> logrotate&#91;<span class=\"hljs-number\">3950100<\/span>]: error: found error in file usertracker, skipping\nJun  <span class=\"hljs-number\">9<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> systemd&#91;<span class=\"hljs-number\">1<\/span>]: logrotate.service: Main process exited, code=exited, status=<span class=\"hljs-number\">1<\/span>\/FAILURE\nJun  <span class=\"hljs-number\">9<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> systemd&#91;<span class=\"hljs-number\">1<\/span>]: logrotate.service: Failed with result <span class=\"hljs-string\">'exit-code'<\/span>.\nJun <span class=\"hljs-number\">10<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> logrotate&#91;<span class=\"hljs-number\">4007463<\/span>]: error: failed to open config file usertracker: Permission denied\nJun <span class=\"hljs-number\">10<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> logrotate&#91;<span class=\"hljs-number\">4007463<\/span>]: error: found error in file usertracker, skipping\nJun <span class=\"hljs-number\">10<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> systemd&#91;<span class=\"hljs-number\">1<\/span>]: logrotate.service: Main process exited, code=exited, status=<span class=\"hljs-number\">1<\/span>\/FAILURE\nJun <span class=\"hljs-number\">10<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> systemd&#91;<span class=\"hljs-number\">1<\/span>]: logrotate.service: Failed with result <span class=\"hljs-string\">'exit-code'<\/span>.\nJun <span class=\"hljs-number\">11<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">01<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> logrotate&#91;<span class=\"hljs-number\">4063447<\/span>]: error: failed to open config file usertracker: Permission denied\nJun <span class=\"hljs-number\">11<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">01<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> logrotate&#91;<span class=\"hljs-number\">4063447<\/span>]: error: found error in file usertracker, skipping\nJun <span class=\"hljs-number\">11<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">01<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> systemd&#91;<span class=\"hljs-number\">1<\/span>]: logrotate.service: Main process exited, code=exited, status=<span class=\"hljs-number\">1<\/span>\/FAILURE\nJun <span class=\"hljs-number\">11<\/span> <span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">00<\/span>:<span class=\"hljs-number\">01<\/span> ip<span class=\"hljs-number\">-172<\/span><span class=\"hljs-number\">-31<\/span><span class=\"hljs-number\">-14<\/span><span class=\"hljs-number\">-247<\/span> systemd&#91;<span class=\"hljs-number\">1<\/span>]: logrotate.service: Failed with result <span class=\"hljs-string\">'exit-code'<\/span>.\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Ensure that the log files and their directories have the correct permissions for logrotate to read and write.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Troubleshooting steps to ensure logrotate is functioning correctly<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Check Permissions<\/h3>\n\n\n\n<p>Ensure that the <code>usertracker<\/code> configuration file has the correct permissions, and logrotate can access it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo chmod 644 \/etc\/logrotate.d\/usertracker<br>sudo chown root:root \/etc\/logrotate.d\/usertracker<br><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Manually Trigger Log Rotation<\/h3>\n\n\n\n<p>You can manually trigger the logrotate to see if it works as expected:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo logrotate -f \/etc\/logrotate.conf<br><\/code><\/pre>\n\n\n\n<p>The <code>-f<\/code> flag forces the rotation, even if it would not normally rotate.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Verify Crontab for Logrotate<\/h3>\n\n\n\n<p>Ensure that logrotate is scheduled to run automatically. Check the crontab:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo crontab -l | grep logrotate<br><\/code><\/pre>\n\n\n\n<p>You should see an entry similar to:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>0 0 * * * \/usr\/sbin\/logrotate \/etc\/logrotate.conf<br><\/code><\/pre>\n\n\n\n<p>This entry schedules logrotate to run every day at midnight.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Check System Logs<\/h3>\n\n\n\n<p>After ensuring permissions and running the manual logrotate, check the system logs again to verify there are no errors:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo grep logrotate \/var\/log\/messages<br><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Validate Configuration Files<\/h3>\n\n\n\n<p>Ensure all logrotate configuration files are correctly set up and valid:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo logrotate --debug \/etc\/logrotate.conf<br><\/code><\/pre>\n\n\n\n<p>This command will show any potential issues with the logrotate configuration files.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Confirm Service Status<\/h3>\n\n\n\n<p>Make sure the logrotate service is active and running without issues:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo systemctl status logrotate<br><\/code><\/pre>\n\n\n\n<p>If it&#8217;s not running, start or restart the service:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo systemctl start logrotate<br><\/code><\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo systemctl restart logrotate<br><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 7: Review <code>logrotate<\/code> Status and Output<\/h3>\n\n\n\n<p>After confirming the service status and manual rotation, ensure no further errors are present in the logs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>almalinux os To configure logrotate in AlmaLinux, you can follow these steps to ensure your system logs are properly managed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-178","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/posts\/178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/comments?post=178"}],"version-history":[{"count":6,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/posts\/178\/revisions"}],"predecessor-version":[{"id":260,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/posts\/178\/revisions\/260"}],"wp:attachment":[{"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/media?parent=178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/categories?post=178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rajeshkumar.xyz\/blog\/wp-json\/wp\/v2\/tags?post=178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}