Linux Server log Dump

Source: Internet
Author: User

After the project is configured, Apache,mysql and so on will generate a log, in order to facilitate management, it is at a certain interval of time to dump

1.Apache log

Add the following two sentences to the configuration file:

Customlog "|/usr/sbin/rotatelogs/var/log/httpd/access-80.log.%y%m%d 86400 540" combined

Errorlog "|/usr/sbin/rotatelogs/var/log/httpd/error-80.log.%y%m%d 86400 540"

After restarting Apache, you can see the corresponding logs under/VAR/LOG/HTTPD.

The/usr/sbin/rotatelogs used in the above statement is a program that works with the Apache pipeline Log feature.

rotatelogs[-L] [-f] LogFile Rotationtime|filesizem [offset]

Parameter explanation:

- L: represents using local time instead of GMT time as the time Datum

Logfile: indicates that the base time is the log file name.

Rotationtime: indicates the interval of time in seconds for log file scrolling

Filesizem: indicates that the specified Filesizem file size is scrolled instead of scrolling by time or slack

Offset: represents the number of minutes of the time difference relative to UTC. If omitted, it is assumed to be "0" and UTC time is used. For example, to specify local time for a region with a UTC difference of "-5 hours", this parameter should be " -300"

For example, the following:

Customlog "|/usr/sbin/rotatelogs/var/log/httpd/access-80.log.%y%m%d 86400 540" combined

This configuration will establish the/var/log/httpd/access-80.log file, the following%y%m%d represents the current system time at the start of the log, 86400s represents 24 hours, that is, after these times will produce a new log file, 540 for 9 hours, Time offset.

The following combined represents a composite format

Errorlog "|/usr/sbin/rotatelogs/var/log/httpd/error-80.log.%y%m%d 5M"

Indicates that the log is scrolled when error_log grows to 5M

2.MySQL log

In the MySQL configuration file, specify the location of the corresponding file

[Mysqld]log-bin=mysql-binport=3306datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysqllog=/var/log /mysql/mysql.log# disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# slow_ Querieslong-query-time=1slow_query_log =/var/log/mysql/slow.log[mysqld_safe]log-error=/var/log/mysql/mysql_ Error.logpid-file=/var/run/mysqld/mysqld.pid

Edit File/etc/logrotate.d/mysqld,

/var/log/mysql/*.log {        daily         rotate 14        missingok         compress        delaycompress         notifempty        create  0640 mysql root        postrotate         if [ -x /usr/bin/mysqladmin ]; then                 mysqladmin= "/usr/bin/mysqladmin  --defaults-file=/etc/mysql/myadmin.cnf "                 if [ -z  "' $mysqladmin  ping 2> /dev/null '"  ]; then                         if ps cax | grep -q mysqld; then                                  exit 1                          fi                else                           $mysqladmin  flush-logs                 fi        fi         endscript} 

Use Logrotate/etc/logrotate.conf–f to make it work, and then in/var/log/mysql (the directory you specify, you can see the corresponding format of the log)

The meaning of the parameter:

Compress: Post -dump logs with gzip compression,

nocompress : Use this parameter when compression is not required

copytruncate : for log files that are still open, truncate the current log backup

nocopytruncate: back up log files but not truncate

Create mode Ownergroup: dump file, creating a new log file with the specified file mode

nocreate: do not create a new log file

delaycompress : When used in conjunction with compress, the dump log file is compressed until the next dump

nodelaycompress : Overwrite delaycompress option, dump simultaneous compression

Errors Address : The error message generated when the dump is sent to the specified email address

Ifempty : Even empty files are dumped, which is the default option for Logrotate

Notifempty: if it is an empty file, do not dump

Mail Address : Sends the dump log file to the specified e-mail

Nomail: dump when not developed send log file Daily: Specify a dump cycle of daily Weekly: Specify a dump cycle of weekly

Monthly: specify a staging period of monthly

Rotate Count: specifies the number of times a log file was dumped before it was deleted, 0 means no backup, 5 means 5 backups reserved

Size Size: Dumps are not dumped when the log file reaches the specified size, size can specify bytes (default) and KB or MB

Dateext: Add a date as a suffix after the dump log file. For example, if the log name is: Log. Then the dump is: log-20140929. If a file named log-20140929 is already in the directory, the dump will fail.

Reference Link: http://zhumeng8337797.blog.163.com/blog/static/10076891420121951235106/








This article is from "The girl said" blog, please be sure to keep this source http://sugarlovecxq.blog.51cto.com/6707742/1559284

Linux Server log Dump

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.