LoginSignup
6
4

More than 5 years have passed since last update.

MySQL5.7.18のログローテートの設定

Posted at

やること

CentOS7の上のMySQL5.7.18のログローテートの設定をします

以下のファイルがコメントアウトされているので、コメントをはずします

/etc/logrotate.d/mysql

/var/log/mysqld.log {
        create 640 mysql mysql
        dateext (追加)
        notifempty
        daily
        rotate 7
        missingok
        compress
    postrotate
       # just if mysqld is really running
       if test -x /usr/bin/mysqladmin && \
          /usr/bin/mysqladmin ping &>/dev/null
       then
          /usr/bin/mysqladmin flush-logs
       fi
    endscript
}

ユーザーとパスワードの設定をします。セキュリティ的にはrootユーザーではやらない方が良いです。

mysql_config_editor set --login-path=client --user=root --host=localhost --password

~/.mylogin.cnfに暗号化されたパスワードが設定されます。これでOK

テストだけする場合

# logrotate -dv /etc/logrotate.d/mysql

実際にローテートしてみる

# logrotate -v /etc/logrotate.d/mysql
reading config file /etc/logrotate.d/mysql
Allocating hash table for state file, size 15360 B

Handling 1 logs

rotating pattern: /var/log/mysqld.log  after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/mysqld.log
  log needs rotating
rotating log /var/log/mysqld.log, log->rotateCount is 7
dateext suffix '-20170529'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
renaming /var/log/mysqld.log to /var/log/mysqld.log-20170529
creating new /var/log/mysqld.log mode = 0640 uid = 27 gid = 27
running postrotate script
compressing log with: /bin/gzip

できました

-rw-r-----   1 mysql  mysql        0  5月 29 16:44 mysqld.log
-rw-r-----   1 mysql  mysql   159660  5月 29 16:12 mysqld.log-20170529.gz

ローテートしない場合はこのあたりの日付をバックデートして実行してみましょう

vi /var/lib/logrotate.status

logrotate state -- version 2
"/var/log/mysqld.log" 2017-5-29-16:44:32
"/var/log/nginx/access.log" 2017-5-14-8:50:42
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4