MySQLログローテーション設定について - CentOS|Systems Engineer Wiki

Systems Engineer Wiki

訪問者:23,224,415 人目

<< 2024年03月 

12
3456789
10111213141516
17181920212223
24252627282930
31
お知らせ・メンテナンス情報
  >  
  >  
MySQLログローテーション設定について

MySQLログローテーション設定について

投稿日:2015-01-25 01:09:32

MySQLログローテーション設定について

MySQLのログローテーション設定について紹介します。 前提条件としては、MySQLのログ出力が設定されている事が前提になります。 ログローテート設定は下記ディレクトリに設定を行います。 /etc/logrotate.d/

# ll /etc/logrotate.d/

MySQLのログローテート設定はデフォルト下記のようになっています。

# vi /etc/logrotate.d/mysqld # This logname can be set in /etc/my.cnf # by setting the variable "err-log" # in the [safe_mysqld] section as follows: # # [safe_mysqld] # err-log=/var/log/mysqld.log # # If the root user has a password you have to create a # /root/.my.cnf configuration file with the following # content: # # [mysqladmin] # password = [secret] # user= root # # where "[secret]" is the password. # # ATTENTION: This /root/.my.cnf should be readable ONLY # for root ! # Then, un-comment the following lines to enable rotation of mysql's log file: /var/log/mysqld.log {   create 640 mysql mysql   notifempty   daily   rotate 3   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 }

なるほど〜。 初期設定では、/var/log/ の直下にログファイルが出力されているみたいです。 でも・・・・・ Queryログは? Slowログは? Errorログは? ログローテートの初期値では、上記の3つのログのログローテート設定はされていません。 ・・・そうだよね・・・ この3種類のログ出力設定は、任意設定を行わなければ出力されない物になります。 まず、ログ出力ディレクトリを作成します。 ログ出力ディレクトリ名は、/var/log/mysql とします。

# mkdir /var/log/mysql

次に、フォルダーの所有者を変更します。

# chown mysql:mysql /var/log/mysql

MySQLの出力は、mysqlユーザが行うので諸湯者変更が必要になると思います。 続いて、ログローテート設定を行います。 ログローテート対象のファイルは、下記のファイルになります。 /var/log/mysql/mysql-error.log /var/log/mysql/mysql-query.log /var/log/mysql/mysql-slow.log

# vi /etc/logrotate.d/mysqld # This logname can be set in /etc/my.cnf # by setting the variable "err-log" # in the [safe_mysqld] section as follows: # # [safe_mysqld] # err-log=/var/log/mysqld.log # # If the root user has a password you have to create a # /root/.my.cnf configuration file with the following # content: # # [mysqladmin] # password = [secret] # user= root # # where "[secret]" is the password. # # ATTENTION: This /root/.my.cnf should be readable ONLY # for root ! # Then, un-comment the following lines to enable rotation of mysql's log file: #/var/log/mysqld.log { #  create 640 mysql mysql #  notifempty #  daily #  rotate 3 #  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 #} /var/log/mysql/mysql-error.log {   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 } /var/log/mysql/mysql-query.log {   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 } /var/log/mysql/mysql-slow.log {   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 }