문제가 해결되었지만 나중에 참조 할 수 있도록 작성 중입니다.
/root/.my.cnf
[mysqladmin]
user = root
password = pa$$w0rd
/etc/logrotate.d/mysql
/var/log/mysql-slow.log /var/log/mysqld.log {
daily
rotate 7
dateext
compress
missingok
#notifempty
sharedscripts
create 644 mysql mysql
postrotate
/usr/bin/mysqladmin flush-logs
endscript
}
logrotate
명령 행에서 실행할 때 제대로 작동합니다.
# logrotate -v -f /etc/logrotate.d/mysql
cron에서 오전 4시에 실행될 때 작동하지 않습니다. logs 파일이 회전되었지만 MySQL은 새로 작성된 파일에 오류를 기록하지 않습니다.
-rw-r--r-- 1 mysql mysql 0 Aug 7 10:13 /var/log/mysqld.log
-rw-r--r-- 1 mysql mysql 20 Aug 4 04:04 /var/log/mysqld.log-20120804.gz
-rw-r--r-- 1 mysql mysql 20 Aug 5 04:04 /var/log/mysqld.log-20120805.gz
-rw-r--r-- 1 mysql mysql 20 Aug 6 16:28 /var/log/mysqld.log-20120806.gz
답변
에서 postrotate
stderr과 stdout을 로그 파일로 리디렉션하여 어떤 일이 발생하는지 확인합니다.
postrotate
/usr/bin/mysqladmin flush-logs > /var/log/mysqladmin.flush-logs 2>&1
endscript
내가 얻는 것은 :
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
로그 회전 중에 mysqladmin
읽지 않는 것 같습니다 /root/.my.cnf
.
따라서 이것을 시도하십시오 :
postrotate
env HOME=/root/ /usr/bin/mysqladmin flush-logs > /var/log/mysqladmin.flush-logs 2>&1
endscript
출처:
답변
나는 비슷한 문제가 있었다.
추가 후 MySQL을 다시 시작하지 않았 /root/.my.cnf
으므로 postrotate flush 명령이 실행되지 않았습니다.
MySQL을 다시 시작하면 루트 my.cnf 파일을 읽고 예상대로 작동했습니다.
답변
제 경우에는 블록 /etc/logrotate.d/mysql
이 약간 다르게 보였습니다.
postrotate
test -x /usr/bin/mysqladmin || exit 0
if [ -f `my_print_defaults --mysqld | grep -oP "pid-file=\K[^$]+"` ]; then
# If this fails, check debian.conf!
mysqladmin --defaults-file=/etc/mysql/debian.cnf flush-logs
fi
endscript
“이것이 실패하면 debian.conf를 확인하십시오!”라는 주석을 참고하십시오. 그리고 매개 변수가있는 명령 --defaults-file=/etc/mysql/debian.cnf
. 이 파일은 빈 암호로 [client]
사용자 root
를 정의하는 매우 동일한 섹션을가 집니다. 따라서 분명히 사용 된 것과 동일한 암호 /root/.my.cnf
를 해당 파일에 배치해야합니다. 보안 현명한, /etc/mysql/debian.cnf
유사합니다 /root/.my.cnf
: 소유 root:root
, 및에 chmodded 0600
.
답변
따라서 제 경우에는 각 노드마다 데비안 사용자가 개별적으로 설치하지만 구성 파일은 각 노드마다 동일한 무결성을 debian-sys-maint
갖기 때문에 사용자 에게 권한 문제 galera-cluster
가 있습니다./etc/mysql/debian.cnf
따라서 logrotate
파일에는 다음이 있습니다.
postrotate
test -x /usr/bin/mysqladmin || exit 0
if [ -f `my_print_defaults --mysqld | grep -oP "pid-file=\K[^$]+"` ]; then
# If this fails, check debian.conf!
mysqladmin --defaults-file=/etc/mysql/debian.cnf --local flush-error-log \
flush-engine-log flush-general-log flush-slow-log
fi
endscript
해결책은 간단하므로 debian-sys-maint
한 노드에서 사용자 의 비밀번호를 변경하고 모든 노드의 ‘/etc/mysql/debian.cnf’파일에서 비밀번호를 설정하십시오.
SET PASSWORD FOR 'debian-sys-maint'@'localhost' = password('YOUR PASSWORD');
나는 그것이 유용하기를 바랍니다.