MySQL error log(PLC)

Rsyslog : MySQL Error ๋กœ๊ทธ์™€ Slow-Query ์ทจํ•ฉ์„ ์œ„ํ•œ ์„ค์ •

1. rsyslog conf ์„ค์ •

1-1. ์„ค์ •

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โ€ ~

1-2. rsyslog ๋ฐ๋ชฌ ์žฌ์‹œ์ž‘

systemctl restart rsyslog

1-3. PLURA V5 repo ์—์„œ ๋‹ค์šด๋กœ๋“œ ๋ฐ›๊ธฐ

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

2. MySQL โ€“ SLOW QUERY ์„ค์ •

2-1. ์„ค์ •

vi /etc/my.cnf

[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql-slow.log
long_query_time = 3

2-2. ๋กœ๊ทธ ํŒŒ์ผ ์ƒ์„ฑ ๋ฐ ๊ถŒํ•œ ์„ค์ •

touch /var/log/mysql-slow.log
chown mysql.mysql /var/log/mysql-slow.log

2-3. ๊ถŒํ•œ ํ™•์ธ

ls -aZ /var/log/mysql*

2-4. mysql ๋ฐ๋ชฌ ์žฌ์‹œ์ž‘

systemctl restart mysqld

2-5. ํ™œ์„ฑํ™” ํ™•์ธ

mysql> show variables like โ€˜slow_query_%โ€™;

3. ๋กœ๊ทธ ํ™•์ธ

์ฐธ๊ณ  ์‚ฌ์ดํŠธ

https://www.rsyslog.com/doc/v8-stable/configuration/modules/imfile.html

Last updated