• WordPress
  • cPanel
  • Softaculous
  • KVM Virtualization
  • Vmware Virtualization
  • Proxmox
Sunday, June 15, 2025
LinuxBoost
  • Home
  • Almalinux
  • CentOS
  • Debian
  • Fedora
  • Ubuntu
  • Red Hat Enterprise Linux
  • Rocky Linux
  • OpenSUSE
  • Arch Linux
  • Oracle Linux
No Result
View All Result
LinuxBoost
  • Home
  • Almalinux
  • CentOS
  • Debian
  • Fedora
  • Ubuntu
  • Red Hat Enterprise Linux
  • Rocky Linux
  • OpenSUSE
  • Arch Linux
  • Oracle Linux
LinuxBoost
  • Home
  • Almalinux
  • CentOS
  • Debian
  • Fedora
  • Ubuntu
  • Red Hat Enterprise Linux
  • Rocky Linux
  • OpenSUSE
  • Arch Linux
  • Oracle Linux

How to Install and Configure Logrotate on Rocky Linux

in Rocky Linux
How to Install and Configure Logrotate on Rocky Linux

Managing log files is an essential task for every system administrator. Log files can grow rapidly, consuming valuable disk space and making it difficult to search for relevant information. Logrotate is a utility that simplifies the management of log files on Linux systems by automatically rotating, compressing, and removing them as needed. In this comprehensive guide, we will cover how to install and configure logrotate on Rocky Linux.

Table of Contents

  1. Introduction to Logrotate
  2. Installing Logrotate
  3. Configuring Logrotate
  4. Creating Custom Logrotate Configurations
  5. Testing Logrotate Configuration
  6. Automating Logrotate with Cron
  7. Conclusion

How to Install and Configure Logrotate on Rocky Linux

Introduction to Logrotate

Logrotate is a Linux utility designed to help system administrators manage log files generated by various applications and services. It offers automatic rotation, compression, removal, and mailing of log files. By using logrotate, you can ensure that your log files are organized, up-to-date, and easy to manage. Logrotate is used in conjunction with other log management tools, such as Rsyslog and Fail2ban.

Installing Logrotate on Rocky Linux

Rocky Linux comes with logrotate pre-installed, but in case it’s missing, you can install it using the following command:

sudo dnf install logrotate

Configuring Logrotate on Rocky Linux

Logrotate’s main configuration file is located at /etc/logrotate.conf. This file contains global settings and includes additional configuration files from the /etc/logrotate.d directory.

To edit the main configuration file, open it with a text editor of your choice:

sudo nano /etc/logrotate.conf

The default configuration should look similar to this:

# see "man logrotate" for details
# rotate log files weekly
weekly

# use the syslog group by default, since this is the owning group
# of /var/log/syslog.
su root syslog

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    minsize 1M
    create 0664 root utmp
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}

# system-specific logs may be also be configured here.

Feel free to modify the settings according to your requirements. For example, you can uncomment the compress line to enable log file compression.

Creating Custom Logrotate Configurations in Linux

You can create custom logrotate configurations for specific applications by creating a new file in the /etc/logrotate.d directory. This is useful when you want to manage logs for applications that don’t have a default logrotate configuration, or if you want to override the default settings.

For example, let’s create a custom logrotate configuration for an application called my_app:

  1. Create a new configuration file for my_app:
sudo nano /etc/logrotate.d/my_app

Add the following content to the configuration file, adjusting the settings according to your requirements:

/var/log/my_app/*.log {
    daily
    rotate 7
    compress
    delaycompress
    missingok
    notifempty
    create 640 root root
    postrotate
        systemctl restart my_app.service
    endscript
}

This configuration will rotate logs for my_app daily, keeping 7 days of compressed log files. It will also restart the my_app service after rotating the logs.

Save the file and exit the text editor.

Test the new logrotate configuration:

sudo logrotate -d -f /etc/logrotate.d/my_app 

This command will display the actions logrotate would perform, without actually executing them.

If the test is successful, the custom logrotate configuration for my_app is now in place.

Monitoring Logrotate on Rocky Linux

To ensure that logrotate is running as expected, you can check its status by examining the /var/lib/logrotate/status file:

cat /var/lib/logrotate/status

This file contains information about the last rotation date for each log file managed by logrotate. If you notice any issues or inconsistencies, you can check the logrotate script for errors by running:

sudo logrotate -d /etc/logrotate.conf

This command will display the debug information for logrotate, helping you identify any issues with your configuration.

Conclusion

In this tutorial, we’ve covered how to install and configure logrotate on Rocky Linux. Logrotate is an essential tool for managing log files on your server, and by following these steps, you can ensure that your logs are properly rotated, compressed, and archived to save disk space and maintain system stability. For more tutorials on managing your Rocky Linux server, check out the following articles:

  • How to Install and Configure Rsyslog on Rocky Linux
  • How to Install and Configure Fail2Ban on Rocky Linux
  • How to Install and Configure Zabbix on Rocky Linux
  • How to Install and Configure Nagios on Rocky Linux
  • How to Install and Configure ProFTPD on Rocky Linux
ShareTweet
Previous Post

How to Install and Configure Rsyslog on Rocky Linux

Next Post

How to Install and Configure Elasticsearch on Rocky Linux

Related Posts

How to Install and Configure OpenVAS on Rocky Linux

How to Install and Configure OpenVAS on Rocky Linux

How to Install and Configure Nikto on Rocky Linux

How to Install and Configure Nikto on Rocky Linux

Set up FreeIPA on Rocky Linux

How to Install and Configure FreeIPA on Rocky Linux

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Golden Host VPS
  • Privacy Policy
  • Terms and Conditions
  • About Us
  • Contact Us

Copyright © 2023 linuxboost.com All Rights Reserved.

  • Privacy Policy
  • Terms and Conditions
  • About Us
  • Contact Us

Copyright © 2023 linuxboost.com All Rights Reserved.