最好是在数据库中新建一个只有要采集数据表的查看权限的用户来读取日志 CREATE USER ‘es‘@’localhost’ IDENTIFIED BY ‘密码’; GRANT SELECT ON [数据库名].[日志表名称] to ‘es‘@’localhost’; 将mysql的连接jar包放到logstash的根目录下 这里以mysql-connector-java-5.1.13-bin.jar为例 编辑log.conf,加入如下内容
filter { #Only matched data are send to output. if [type] == "log"{ grok { match => { "message" => "%{TIMESTAMP_ISO8601:time}\s\[%{LOGLEVEL:level}\]\[(?<threadName>([\s\S]*))\]\s%{NOTSPACE:loggerName}\s(?<info>([\s\S]*))"} } date { match => [ "time", "yyyy-MM-dd HH:mm:ss.SSS" ] } } }
Output修改为
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
if [type] == "log"{ elasticsearch { action => "index"#The operation on ES hosts => "[es的地址]"#ElasticSearch host, can be array. index => "systemlog"#The index to write data to. } } else { elasticsearch { hosts => "[es的地址]" index => "数据库采集的index" document_id => "%{id}" } stdout { codec => json_lines } }