mysql error log, slow log의 경우에는 log rotate가 되지 않기 때문에 로그량이 많을 경우 파일을 열기 힘들어질 수 있다.
이에 대비하여 log rotate 설정을 한다.
샘플 파일은 $MYSQL_HOME/support-files/mysql-log-rotate 이다.
1. mysql-log-rotate 파일을 작성하고 /etc/logrotate.d 에 복사한다.
여기서는 error log 와 slow log 두가지를 rotate 할 것이므로 로그 위치에 따라 두번 작성하였다.
필요에 따라 rotate 보관 및 삭제 주기, 파일 위치 등 상세 설정은 변경해주어야 한다.
vi /etc/logrotate.d/mysql-log-rotate
-------------------------------------------------------------------
# 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=/usr/local/mysql/data/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 =
# user= root
#
# where "" is the password.
#
# ATTENTION: This /root/.my.cnf should be readable ONLY
# for root !
/mysql_log01/error/mysqld.err {
# create 600 mysql mysql
notifempty
monthly
rotate 13
missingok
# compress
postrotate
# just if mysqld is really running
if test -x /mw/mysql/mysql/bin/mysqladmin && \
/mw/mysql/mysql/bin/mysqladmin ping &>/dev/null
then
/mw/mysql/mysql/bin/mysqladmin --local flush-error-log \
flush-slow-log
fi
endscript
}
/mysql_log01/slow/mysvc01-slow.log {
# create 600 mysql mysql
notifempty
monthly
rotate 13
missingok
# compress
postrotate
# just if mysqld is really running
if test -x /mw/mysql/mysql/bin/mysqladmin && \
/mw/mysql/mysql/bin/mysqladmin ping &>/dev/null
then
/mw/mysql/mysql/bin/mysqladmin --local flush-error-log \
flush-slow-log
fi
endscript
}
-------------------------------------------------------------------
2. root 계정에서 DB 접속을 위한 정보 파일을 만든다.
vi /root/.my.cnf
------------------------
[mysqladmin]
password = ******
user= root
------------------------
3. 파일의 권한을 확인한다.
샘플 파일을 복사하여 작성한 경우에는 파일 권한이 755 이므로 이를 644 로 변경해주어야 한다.
ls -al /etc/logrotate.d/mysql-log-rotate
chmod -x /etc/logrotate.d/mysql-log-rotate
4. log rotate 가 정상적으로 되는지 확인한다.
logrotate -v /etc/logrotate.d/mysql-log-rotate
(또는 강제로 rotate 를 시키고 싶을 경우에는 -f 옵션을 추가하여 실행한다.)
'Database & SQL > MariaDB & MySQL' 카테고리의 다른 글
metadata_lock_info (0) | 2022.05.23 |
---|---|
MariaDB 10.2 vs MySQL 8.0 SQL_MODE 비교 (0) | 2019.07.23 |