Admin... by accident!

You may have chosen to be an admin. I didn't!

  • Home
  • FreeBSD
  • GNU/Linux
  • Security
  • Network
  • Virtualization
  • Politics
  • Github
  • Donate
  • Me

How to enable log rotation on FreeBSD

May 5, 2018 by Albert Valbuena

This is a very short simple entry but it may help you. As many others you may be running a web server, or any other service that creates some logging information. Enable log rotation on FreeBSD will keep those log files in a manageable size (at least more readable) and they won’t grow and expand eternally in your /var/log directory.

For this case we’ll see how to rotate logs for the Apache web server but you may adapt this information to your particular needs. To enable log rotation on FreeBSD there is a very useful utility called newsyslog. In order to get a deeper knowledge on how to set the tool and the configuration requirements you may take a look at this other man page.

As you may already know configuration files for the FreeBSD operating system are located in the /etc directory. As a reminder, application configuration files are not set at the same path but rather on /usr/local/etc. For the sake of clarity FreeBSD does differentiate base system configuration files from third party applications such as Apache, MySQL and the rest of the other more than twenty four thousand ports available to this date.

If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.

In order to enable log rotation on FreeBSD we will edit the /etc/newsyslog.conf file. You may encounter entries in the file similar to these:

# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num]

/var/log/all.log 600 7 * @T00 J

/var/log/amd.log 644 7 100 * J

/var/log/auth.log 600 7 100 @0101T JC

/var/log/console.log 600 5 100 * J

/var/log/cron 600 3 100 * JC

/var/log/daily.log 640 7 * @T00 JN

/var/log/debug.log 600 7 100 * JC

/var/log/init.log 644 3 100 * J

/var/log/kerberos.log 600 7 100 * J

/var/log/lpd-errs 644 7 100 * JC

/var/log/maillog 640 7 * @T00 JC

/var/log/messages 644 5 100 @0101T JC

/var/log/monthly.log 640 12 * $M1D0 JN

And you have to add the following lines to successfully rotate your Apache logs in FreeBSD.

/var/log/httpd-access.log www:www 644 9 * $W1D4 J /var/run/httpd.pid 30

/var/log/httpd-error.log www:www 644 9 * $W1D4 J /var/run/httpd.pid 30

What does all this mean?

/var/log/httpd-access.log – You first set the file name you want to rotate.

www:www – Afterwards you give the user and group owners of the file in question.

644 – Then you set the right permissions. You can set them at your own discretion, so for example you can set them at 440 so they become read only for the www user and group and no one else.

9 – By setting a number in the next column you set the number of files that will be kept excluding the current one. Therefore you will have the last 10 log files. The rest will be discarded. Depending on the time frame you set this to happen you will have more or less days or weeks of files available for your inspection if needed.

* – the wild card here states not to rotate the files based on their size.

$W1D4 – This sets the time frame rotation. This simply tells the system to rotate the above mentioned file to be rotated every Monday at 04.00 am.

The “J” option tells the program to archive the logs with bzip2 compression.

/var/run/httpd.pid – This states the process ID, in this case for the httpd server.

30 – This sends a signal to gracefully restart the httpd server.

If you enable log rotation on FreeBSD you are not only following good practice guidelines, you will also have a cleaner and clearer environment to work on. And that is always something nice to have.

Use this link to get 100 $ credit at DOcean and support Adminbyaccident.com hosting costs.

Filed Under: FreeBSD, How To's

Recent Posts

  • How to install Mate on FreeBSD 12/13
  • How to install Nessus 10 on FreeBSD 12
  • How to enable TLS traffic from the origin server on Cloudflare Argo Tunnel
  • How to use Cloudflare’s Argo Tunnel service to publish a website on FreeBSD 12/13
  • How to setup MariaDB master-slave replication on FreeBSD
  • How to upload a FreeBSD custom image on DigitalOcean
  • How to install Drupal 9 on FreeBSD 13.0
  • How to manage site visitors based on IP Geolocation
  • How to enable Geolocation in AWStats on FreeBSD 13.0
  • How to install AWStats on FreeBSD 13.0
  • How to configure Modsecurity 3 for WordPress on FreeBSD
  • How to configure Apache HTTP with a TLS reverse proxy backend on FreeBSD
  • How to detect a WAF – Web Application Firewall
  • How to install Matomo 4 on FreeBSD
  • How to test SSL/TLS configurations
  • How to configure Apache HTTP as a reverse proxy on FreeBSD
  • How to install Nextcloud on FreeBSD 12
  • How to install ModSecurity 3 on FreeBSD
  • How to replace a disk on a ZFS mirror pool
  • How to install Webmin on FreeBSD 12

Archives

  • February 2023
  • January 2023
  • December 2022
  • April 2022
  • March 2022
  • October 2021
  • September 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • September 2018
  • June 2018
  • May 2018
  • April 2018
  • February 2018
  • January 2018
  • November 2017
  • April 2017

RSS Admin… by accident!

  • How to install Mate on FreeBSD 12/13
  • How to install Nessus 10 on FreeBSD 12
  • How to enable TLS traffic from the origin server on Cloudflare Argo Tunnel
  • How to use Cloudflare’s Argo Tunnel service to publish a website on FreeBSD 12/13
  • How to setup MariaDB master-slave replication on FreeBSD
  • How to upload a FreeBSD custom image on DigitalOcean
  • How to install Drupal 9 on FreeBSD 13.0
  • How to manage site visitors based on IP Geolocation
  • How to enable Geolocation in AWStats on FreeBSD 13.0
  • How to install AWStats on FreeBSD 13.0

Copyright © 2023 · Magazine Pro Theme on Genesis Framework · WordPress · Log in