日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

利用logrotate對MySQL日志進行輪轉(zhuǎn)


利用logrotate對MySQL日志進行輪轉(zhuǎn)


日志輪轉(zhuǎn)特別適用于具有固定文件名的日志文件,比如MySQL的出錯日志、常規(guī)查詢?nèi)罩?、慢查詢?nèi)罩镜?。Linux系統(tǒng)有一個非常好用的根據(jù)logratate可以實現(xiàn)自動輪轉(zhuǎn),本文介紹它的原理和用法 。
默認情況下,logrotate部署為每天運行的cron job,你可以在目錄/etc/cron.daily里找到名為logrotate的配置文件 。那么它是在每天的上面時候運行的呢?打開文件/etc/crontab就知道了,下面是我機器上的情況:
雙擊代碼全選

1
2
3
4
5
6
7
8
9
10
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
從上面的配置我們可以知道,/etc/cron.daily是在每天凌晨4:02執(zhí)行 。也就是說,每天4:02分/etc/cron.daily/logrotate將會自動執(zhí)行,下面是它的內(nèi)容:
雙擊代碼全選

1
2
3
4
5
6
7
8
#!/bin/sh

/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=http://www.ljsggw.cn/internet/$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
從上面我們可以知道,logratate默認的配置文件是/etc/logratate.conf,下面是它的內(nèi)容:
雙擊代碼全選

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
EXITVALUE=http://www.ljsggw.cn/internet/$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
[root@lx202 /etc/cron.daily ]# cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
minsize 1M
create 0664 root utmp
rotate 1
}

/var/log/btmp {
missingok
monthly
minsize 1M
create 0600 root utmp
rotate 1
}

推薦閱讀