Logrotate's log rotation Linux

Source: Internet
Author: User

Case: Logrotate's log rotation

For admin.log files, set logrotate

Rotate once a day

Keep 3 Backups

File larger than 100k Auto rotate

On the finished file compression Create permission 0600, owner Root belongs to group root

Steps:

1. First check if the Logrotate package is installed

[Email protected] log]# rpm-q logrotate

Logrotate-3.7.8-17.el6.x86_64

Create log Admin.log because I don't have admin.log this file in my virtual machine

[Email protected] log]# Mkair Admin.log

2. Setting up the configuration file

[Email protected] log]# vim/etc/logrotate.d/admin

/var/log/admin.log {

Missingok

Daily

Size 100k

Rotate 3

Create 0600 root root

Compress

3. Testing

Here because the log is more than 100K automatic rotation, we can manually rotate

Find a file larger than 100k in the system file and copy it to Admin.log

[Email protected] log]# Cp/etc/ssh/moduli/var/log/admin.log

[Email protected] log]# logrotate/etc/logrotate.conf

[Email protected] log]# ls-l/var/log/admin.log*

-RW-------. 1 root root 125811 February 16:10/var/log/admin.log

-RW-------. 1 root root 127214 February 15:59 /var/log/admin.log-20170228.gz

can look at a. GZ end of the compressed file, indicating that the rotation log file settings are successful

You can also force rotation through the logrotate-f command. But it doesn't make much sense, because it doesn't make sense to detect whether our settings are successful, regardless of whether the set conditions will be rotated.

This article is from the "12619984" blog, please be sure to keep this source http://12629984.blog.51cto.com/12619984/1902073

Logrotate's log rotation Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.