• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » How to Manage Logfiles with Logrotate

By Abhishek Ghosh November 12, 2017 5:20 am Updated on November 12, 2017

How to Manage Logfiles with Logrotate

Advertisement

In many guides on this website, we talked about log rotation. Logrotate is Linux utility for automatic rotation, compression, mailing log files etc jobs. Here is how to manage logfiles with logrotate. Many common programs automatically setup Logrotate. Like when we install Apache2, that adds a configuration file used by Logrotate to rotate all apache access and error logs/etc/logrotate.d/apache2. In our other guides, we only mentioned about logrotate script when we built the software from source and/or was sure that the configuration file is not supplied. Logrotate is available on all Linux distributions but default configuration may vary. We are talking in context of Ubuntu 16.04 server. For the others, readers may need checking manual for minimal need of changes. First, we need to check whether logrotate is installed by running :

Vim
1
logrotate --version

If not installed, then we can run the below command(s) to install :

Vim
1
2
3
4
5
6
# Debian/Ubuntu
sudo apt update
sudo apt install logrotate
# Redhat/CentOS
sudo yum update
sudo yum install logrotate

Of course, there is manual of logrorate :

Advertisement

---

Vim
1
man logrotate

 

How to Manage Logfiles with Logrotate

 

/etc/logrotate.conf file contains default settings and includes statement to pull in configuration files from /etc/logrotate.d directory. /etc/logrotate.d/ directory contains the configuration files saved by various applications and utilities. Nothing existing files inside /etc/logrotate.d/ should be altered without knowing about that particular software.

How to Manage Logfiles with Logrotate

For the most daemon processes, logs would be rotated by the root user. logrotate usually invoked from a script in the /etc/cron.daily/ directory.

We can run logrotate as a cronjob to ensure that logs will be rotated as configured. If we configure logrotate to rotate logs every day, but logrotate actually runs every week, the logs will only be rotated every week.

If nothing exist inside /etc/cron.daily/ directory, we need to create a script named /etc/cron.daily/logrotate to do the job :

/etc/cron.daily/logrotate
Vim
1
2
#!/bin/sh
logrotate /etc/logrotate.conf

If I run cat on a server where Apache2 installed :

Vim
1
cat /etc/logrotate.d/apache2

I will get :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/var/log/apache2/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
                if invoke-rc.d apache2 status > /dev/null 2>&1; then
                    invoke-rc.d apache2 reload > /dev/null 2>&1;
                fi;
endscript
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then
run-parts /etc/logrotate.d/httpd-prerotate;
fi;
endscript
}

You need demystification of those phrases.

  • weekly: Rotate logs once per week
  • monthly: Rotate once a month
  • daily: Rotate once a day
  • missingok: Missing OK. If no log files are found, don’t debug or print error.
  • rotate 14: Keep 14 files before deleting old log files
  • compress: Compress (gzip) log files
  • delaycompress: Delays compression until 2nd time rotating.
  • compresscmd: Set which command to used to compress. Defaults to gzip.
  • uncompresscmd: Set the command to use to uncompress. Defaults to gunzip.
  • notifempty: Don’t rotate empty files
  • create 640 root adm: Create new log files with set permissions/owner/group, here user is root and group is adm, permission is 640
  • sharedscripts: Run postrotate script after all logs are rotated
  • postrotate: Scripts to run after rotating is done.
  • size=10M : command sets the minimum size for the rotation to take place to 10M.
  • dateext: This option appends a date instead (logs by default get a number appended to their filename)
  • dateformat: The format of the date appended to the log filename you want.
  • prerotate: Run before log rotating begins

You can run this to test :

Vim
1
2
3
4
# dry run
logrotate -d /etc/logrotate.d/apache2
#
# sudo logrotate /etc/logrotate.d/apache2 --debug

Check what ran by running :

Vim
1
cat /var/lib/logrotate/status

I got a big list like this :

Vim
1
2
3
4
5
6
7
8
9
logrotate state -- version 2
"/var/log/syslog" 2017-11-11-6:25:1
"/var/log/dpkg.log" 2017-11-1-6:25:3
"/var/log/unattended-upgrades/unattended-upgrades.log" 2017-11-1-6:25:3
"/var/log/unattended-upgrades/unattended-upgrades-shutdown.log" 2017-5-26-6:0:0
"/var/log/auth.log" 2017-11-5-6:25:2
"/var/log/apt/term.log" 2017-11-1-6:25:3
...
...

This Article Has Been Shared 803 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Orthopaedic Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to How to Manage Logfiles with Logrotate

  • Ubuntu with GUI on Rackspace Cloud Server as VNC Remote Desktop

    Ubuntu with GUI on Rackspace Cloud Server as VNC Remote Desktop is a guide to install and work on powerful server with up to 48 GB of RAM and GUI from devices.

  • Text Based User Interface (TUI) on SSH Environment

    Here is a Guide on Possibilities of Using Text Based User Interface (TUI) on SSH Environment. Number of Programs Currently is Few in Number.

  • Cloud Computing Jobs is Facing Deficit of Skilled Candidates

    Cloud Computing Jobs is Facing Deficit Skilled Candidates. Some Companies Having Difficulties to Get Candidates with Sufficient Knowledge.

  • Nginx WordPress : Redirect to Geographically Closer Server

    Here is How To Setup Nginx WordPress to Redirect to Geographically Closer Server. This is Called Geo Redundant Setup, Not Very Difficult.

  • How To Configure Nginx Access Log With GeoIP (Ubuntu 16.04)

    Here is How To Configure Nginx Access Log With GeoIP on Ubuntu 16.04. Usage Commands Also Shown. Access Log is Powerful & Configurable Tool.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

You can subscribe to our Free Once a Day, Regular Newsletter by clicking the subscribe button below.

Click To Subscribe

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (21K Followers)
  • Twitter (5.3k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Best Powerpoint Templates for Communicating IoT Concepts April 17, 2021
  • How to Build a DIY Water Level Indicator? April 16, 2021
  • How Startups Can Convince the Investors April 14, 2021
  • What to Know About the Cloud Storage Services for Smartphones April 13, 2021
  • WonderFox HD Video Converter Factory Pro Review April 10, 2021

 

About This Article

Cite this article as: Abhishek Ghosh, "How to Manage Logfiles with Logrotate," in The Customize Windows, November 12, 2017, April 19, 2021, https://thecustomizewindows.com/2017/11/manage-logfiles-with-logrotate/.

Source:The Customize Windows, JiMA.in

 

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Cookie Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2021 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy