我的MariaDB服务器之一的logrotate出现问题。 Logrotate在运行时没有(正确地)引发任何错误。旋转mariadb-slow.log文件后,MariaDB不会在新日志文件中写入任何消息。
该问题仅影响mariadb-slow.log。

当我从logrotate配置文件的postrotate部分运行mysqladmin命令时,maraidb-slow.log再次被写入。

mysqladmin --defaults-file="/etc/mysql/debian.cnf" --local flush-error-log flush-engine-log flush-general-log flush-slow-log


手动运行logrotate也会导致此问题。

logrotate /etc/logrotate.d/mysql-server


添加-v参数显示不明显

logrotate -v /etc/logrotate.d/mysql-server
reading config file /etc/logrotate.d/mysql-server
Reading state from file: /var/lib/logrotate/status
Allocating hash table for state file, size 64 entries
Creating new state
...
Creating new state

Handling 1 logs

rotating pattern: /var/log/mysql/mysql.log /var/log/mysql/mysql-slow.log /var/log/mysql/mariadb-slow.log /var/log/mysql/error.log  1024 bytes (7 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/mysql/mysql.log
  log /var/log/mysql/mysql.log does not exist -- skipping
considering log /var/log/mysql/mysql-slow.log
  log /var/log/mysql/mysql-slow.log does not exist -- skipping
considering log /var/log/mysql/mariadb-slow.log
  Now: 2017-11-15 15:02
  Last rotated at 2017-11-15 13:54
  log needs rotating
considering log /var/log/mysql/error.log
  Now: 2017-11-15 15:02
  Last rotated at 2017-11-15 13:54
  log needs rotating
rotating log /var/log/mysql/mariadb-slow.log, log->rotateCount is 7
dateext suffix '-20171115'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/mysql/mariadb-slow.log.7.gz to /var/log/mysql/mariadb-slow.log.8.gz (rotatecount 7, logstart 1, i 7),
renaming /var/log/mysql/mariadb-slow.log.6.gz to /var/log/mysql/mariadb-slow.log.7.gz (rotatecount 7, logstart 1, i 6),
old log /var/log/mysql/mariadb-slow.log.6.gz does not exist
renaming /var/log/mysql/mariadb-slow.log.5.gz to /var/log/mysql/mariadb-slow.log.6.gz (rotatecount 7, logstart 1, i 5),
renaming /var/log/mysql/mariadb-slow.log.4.gz to /var/log/mysql/mariadb-slow.log.5.gz (rotatecount 7, logstart 1, i 4),
renaming /var/log/mysql/mariadb-slow.log.3.gz to /var/log/mysql/mariadb-slow.log.4.gz (rotatecount 7, logstart 1, i 3),
renaming /var/log/mysql/mariadb-slow.log.2.gz to /var/log/mysql/mariadb-slow.log.3.gz (rotatecount 7, logstart 1, i 2),
renaming /var/log/mysql/mariadb-slow.log.1.gz to /var/log/mysql/mariadb-slow.log.2.gz (rotatecount 7, logstart 1, i 1),
renaming /var/log/mysql/mariadb-slow.log.0.gz to /var/log/mysql/mariadb-slow.log.1.gz (rotatecount 7, logstart 1, i 0),
old log /var/log/mysql/mariadb-slow.log.0.gz does not exist
rotating log /var/log/mysql/error.log, log->rotateCount is 7
dateext suffix '-20171115'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/mysql/error.log.7.gz to /var/log/mysql/error.log.8.gz (rotatecount 7, logstart 1, i 7),
renaming /var/log/mysql/error.log.6.gz to /var/log/mysql/error.log.7.gz (rotatecount 7, logstart 1, i 6),
renaming /var/log/mysql/error.log.5.gz to /var/log/mysql/error.log.6.gz (rotatecount 7, logstart 1, i 5),
renaming /var/log/mysql/error.log.4.gz to /var/log/mysql/error.log.5.gz (rotatecount 7, logstart 1, i 4),
renaming /var/log/mysql/error.log.3.gz to /var/log/mysql/error.log.4.gz (rotatecount 7, logstart 1, i 3),
renaming /var/log/mysql/error.log.2.gz to /var/log/mysql/error.log.3.gz (rotatecount 7, logstart 1, i 2),
renaming /var/log/mysql/error.log.1.gz to /var/log/mysql/error.log.2.gz (rotatecount 7, logstart 1, i 1),
renaming /var/log/mysql/error.log.0.gz to /var/log/mysql/error.log.1.gz (rotatecount 7, logstart 1, i 0),
old log /var/log/mysql/error.log.0.gz does not exist
renaming /var/log/mysql/mariadb-slow.log to /var/log/mysql/mariadb-slow.log.1
creating new /var/log/mysql/mariadb-slow.log mode = 0640 uid = 110 gid = 4
renaming /var/log/mysql/error.log to /var/log/mysql/error.log.1
creating new /var/log/mysql/error.log mode = 0640 uid = 110 gid = 4
running postrotate script
compressing log with: /bin/gzip
removing old log /var/log/mysql/mariadb-slow.log.8.gz
compressing log with: /bin/gzip
removing old log /var/log/mysql/error.log.8.gz


logrotate配置文件是软件包维护者提供的文件。我没有做任何修改。我还尝试了其他一些东西。

/var/log/mysql/mysql.log /var/log/mysql/mysql-slow.log /var/log/mysql/mariadb-slow.log /var/log/mysql/error.log {
        # daily
        size 1k
        rotate 7
        missingok
        create 640 mysql adm
        compress
        sharedscripts
        postrotate
          test -x /usr/bin/mysqladmin || exit 0
          if [ -f `my_print_defaults --mysqld | grep -m 1 -oP "pid-file=\K.+$"` ]; then
            # If this fails, check debian.conf!
            mysqladmin --defaults-file=/etc/mysql/debian.cnf -v --local flush-error-log \
              flush-engine-log flush-general-log flush-slow-log >> /var/log/mysql-logrotate.log 2>&1
          fi
        endscript
}


了解该问题后,我刚刚添加了

>> /var/log/mysql-logrotate.log 2>&1


但是mysql-logrotate.log保持为空。

使用的软件:
操作系统:Debian 9.1
DB:MariaDB 10.1
对数旋转:3.11.0

最佳答案

好的,当我将以下内容放入mysqladmin命令之前的postrotate中时

test -x /usr/bin/mysql || exit 0
          mysql --defaults-file=/etc/mysql/debian.cnf -e "FLUSH SLOW LOGS;"


mariadb-slow.log已旋转并且可以在旋转后写入。

关于mysql - logrotate后未写入MariaDB慢日志,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47310021/

10-11 20:58