Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use the logrotate tool to cut MySQL logs and send slow log analysis to mailboxes

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Install logrotate and percona-toolkit

Yum install logrotate-y

Yum install https://www.percona.com/redir/downloads/percona-release/redhat/percona-release-0.1-4.noarch.rpm

Yum install percona-toolkit

two。 Create a logrotate profile

Create a new 3306_error file in the / etc/logrotate.d/ directory

Vim / etc/ogrotate.d/3306_error / data/mysql/3306/error.log {# write down the specific location of your log file monthly # cut rotate 13 # once a month to save 13 logs and rotate 13 months can be compared with the same month last year compared with the same month last year. The file cut by dateext # is named compress # with a similar format of "original file name + 20171230". The file delaycompress # cut using gzip compression is the most The last split file is not compressed (convenient for analysis) missingok # during log rotation Any errors, such as "File cannot be found", will be ignored. Notifempty # if no new log is generated after the last split, the operation performed after postrotate mysql-login-path=3306-e 'flush error logs;' # is not split again. MySQL needs to execute this command to refresh the log handle endscript}

Create a new 3306_slow file in the / etc/logrotate.d/ directory

Vim / etc/logrotate.d/3306_error / data/mysql/3306/slow.log {daily rotate 13 dateext compress delaycompress missingok notifemptypostrotate mysql-- login-path=3306-e 'flush slow logs;' # use the pt-query-digest tool to analyze the sliced slow log and send it to the mailbox pt-query-digest / data/mysql/3306/slow.log- `log +% Y% m% d` | mail-s' 4Saving log log}

3. Manual cutting log

Logrotate-f / etc/logrotate.d/3306_error

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report