Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux log management tools Logrotate     - Help you make Git Bisect (Linux)

- Linux Network Security: nmap port scanning software (Linux)

- APR for Tomcat installation under Linux (Server)

- JavaScript property of checkbox.disabled (Programming)

- How to choose the correct HTTP status code (Server)

- MySQL error: ERROR 1175: You are using safe update mode solution (Database)

- Correlation Analysis: FP-Growth algorithm (Programming)

- Ubuntu configuration SVN and http mode access (Server)

- Ubuntu treated with cue file to ape and wav files automatically track points (Linux)

- Linux system security (Linux)

- Autojump: an advanced cd command in the Linux file system fast navigation (Linux)

- Zabbix monitors the status of TCP connections (Server)

- Linux device driver development small example --LED lights (Programming)

- Linux Study of --CentOS create local yum repository (Linux)

- VMware6 achieve nat Internet (Linux)

- Binary Tree Traversal (Linux)

- How to configure Ceph stored on CentOS 7.0 (Server)

- GitHub multiplayer co-development configuration (Linux)

- Ubuntu file security removal tool (Linux)

- Ubuntu 12.04 installation NVIDIA GTX750 graphics driver (Linux)

 
         
  Linux log management tools Logrotate
     
  Add Date : 2017-04-13      
         
         
         
  1 Operating principle

Logrotate is based on the CRON to run, the script is /etc/cron.daily/logrotate

#! / Bin / sh

/ Usr / sbin / logrotate /etc/logrotate.conf

EXITVALUE = $?

if [! $ EXITVALUE = 0]; then

    / Usr / bin / logger -t logrotate "ALERT exited abnormally with [$ EXITVALUE]"

fi

exit 0

/etc/cron.daily directory all scripts run by CRON frequency by / etc / crontab control,

There are two operation modes: 1. Direct execute a single command; 2 directory planning, only include the following directory configuration planning

SHELL = / bin / bash

PATH = / sbin: / bin: / usr / sbin: / usr / bin

MAILTO = root

HOME = /

# Run-parts

* / 1 * * * * root run-parts /etc/cron.min

01 * * * * root run-parts /etc/cron.hourly

59 23 * * * root run-parts /etc/cron.daily

22 4 * * 0 root run-parts /etc/cron.weekly

42 4 1 * * root run-parts /etc/cron.monthly

2 Profiles

/etc/logrotate.conf global default file

/etc/logrotate.d/ directory included former subordinate files include

 

Common options

weekly < == default one week to perform a rotate work

rotate 4 < == retained many log files default to retain four.

create < == create a new file, because the log is renamed, so to create a new store before continuing to log

dateext < == file suffix is the date format, that is, after cutting file is: xxx.log-20131216, if commented out, cutting out is by increasing numbers, which said earlier xxx.log-1

compress < == Compress log.

include /etc/logrotate.d # /etc/logrotate.d/ directory of all the files are loaded to come

/ Var / log / wtmp {< == only parameter for / var / log / wtmp set

    monthly < == cut once a month, replace the default week

    minsize 1M < == file size exceeds 1M until after the cut

    create 0664 root utmp < == specify the new log file permissions and user and group belongs

    rotate 1 < == only keep a log.

}

By loading file examples include the following

[Root @ www ~] # vi /etc/logrotate.d/syslog

/ Var / log / messages / var / log / secure / var / log / maillog / var / log / spooler /var/log/boot.log / var / log / cron

{

  sharedscripts

  prerotate

    / Usr / bin / chattr -a / var / log / messages

  endscript

  sharedscripts

  postrotate

    / Bin / kill -HUP `cat /var/run/syslogd.pid 2> / dev / null` 2> / dev / null || true

    / Bin / kill -HUP `cat /var/run/rsyslogd.pid 2> / dev / null` 2> / dev / null || true

    / Usr / bin / chattr + a / var / log / messages

  endscript

}

Log File: Log absolute path is processed using a space delimited multiple file names;

Execute the script:

Can call external commands to perform additional commands, this setting need to be set in combination with sharedscripts .... endscript job. Commands:

prerotate: Before starting logrotate carried out instructions, such as modifying the properties files and other actions;

postrotate: After doing logrotate start instruction, for example, to restart (kill -HUP) a service;

So /etc/logrotate.d/syslog cutting function within the set of six files becomes:

1. This setting only messages to / var / log / inside, secure, maillog, spooler, boot.log, cron effective;

2. Logging cut once a week, to retain four, and cut down the log files are not compressed (not change the preset value);

3. After cutting is completed (postrotate) made syslog of PID, to kill -HUP syslogd restart

Cutting Case: Nginx

============================

In /etc/logrotate.d New nginx

/usr/local/nginx/logs/*.log {

daily

rotate 5

dateext

compress

sharedscripts

postrotate

    if [-f /usr/local/nginx/logs/nginx.pid]; then

        kill -USR1 `cat / usr / local / nginx / logs / nginx.pid`

    fi

endscript

}
     
         
         
         
  More:      
 
- Linux, C programming language library file handling and preparation of Makefile (Programming)
- Security Features Linux and Unix operating system, programming (Linux)
- Ubuntu root user profiles (Programming)
- Tomcat itself through simple movement separation (Server)
- Two programs HAProxy + Heartbeat (note, the secondary server vip, normal HAProxy boot method) (Server)
- Tecplot Installation under Linux (Linux)
- Create the best introductory tutorial REST API (Linux)
- Build your own CA services: OpenSSL command line CA Quick Guide (Server)
- Virtualization and IT cooperation (Linux)
- RedHat Linux 6.4 installation RTL8188CUS wireless network card driver (Linux)
- Oracle Linux 7.1 install Oracle 12C RAC (Database)
- C ++ casts New Standard Comments (Programming)
- Use the DBMS_SCHEDULER package to manage scheduled tasks (Database)
- Lenovo E431 notebook CentOS system is installed wireless network card driver (Linux)
- Nginx Module Development - get user ip (Server)
- Linux upgrade Glibc (Linux)
- Android project using the command to create and install the package (Programming)
- Java learning problems encountered (Programming)
- Shell scripts get a snapshot of the page and generates thumbnails (Linux)
- Hibernate Search 5.5 in the search results sorted (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.