Rsyslog : MySQL Error 로그와 Slow-Query 취합을 위한 설정
# vi /etc/rsyslog.d/80-mysql.conf
#variables required for non-syslog log file forwarding – mysql error
#edit on your location
input(type=”imfile”
File=”/var/log/mysqld.log”
Tag=”mysqld-errors”
Severity=”error”
Facility=”local7″)
input(type=”imfile”
File=”/var/log/mysql-slow.log”
Tag=”mysql-slow”
Severity=”notice”
Facility=”local7″)
###### Creates a template for each log file in the Logentries UI
### logic to apply the relevant templates to the different log files
if $programname == ‘mysqld-errors’ then /var/log/plura/ceelog-127.0.0.1.log;CEETemplate
:programname, isequal, “mysqld-errors” ~
if $programname == ‘mysql-slow’ then /var/log/plura/ceelog-127.0.0.1.log;CEETemplate
:programname, isequal, “mysql-slow” ~
rsyslog restart
# systemctl restart rsyslog
# wget https://repo.plura.io/v5/module/rsyslog/80-mysql.conf
# curl https://repo.plura.io/v5/module/rsyslog/80-mysql.conf -o /etc/rsyslog.d/80-mysql.conf
# vi /etc/my.cnf
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql-slow.log
long_query_time = 3
# touch /var/log/mysql-slow.log
# chown mysql.mysql /var/log/mysql-slow.log
# ls -aZ /var/log/mysql*
# systemctl restart mysqld
mysql> show variables like ‘slow_query_%’;
Error 또는 Slow Query 발생 후 호스트 로그에서 MySQL 관련 로그를 확인
로그 예시 : 전체로그 > 호스트
외부 참고 사이트
https://www.rsyslog.com/doc/v8-stable/configuration/modules/imfile.html