我们需要下载相应的 JDBC connector。
解压,将mysql-connector-java-8.0.18.jar放到logstash的jars目录中
F:\ELK\ELK8.2.3\logstash-8.2.3\logstash-core\lib\jars
在bin同级目录下创建mysql.conf
input {
jdbc {
#链接字符串
jdbc_connection_string => "jdbc:mysql://localhost:3306/elk_01?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"
#用户
jdbc_user => "root"
#密码
jdbc_password => "123456"
jdbc_validate_connection => true
jdbc_driver_library => "F:/ELK/ELK8.2.3/logstash-8.2.3/logstash-core/lib/jars/mysql-connector-java-8.0.18.jar"
jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
parameters => { "Product_id" => "Product1" }
statement => "SELECT * FROM SalesJan2009 WHERE Product = :Product_id"
}
}
filter {
mutate {
rename => {
"longitude" => "[location][lon]"
"latitude" => "[location][lat]"
}
}
}
output {
stdout {
}
elasticsearch {
index => "sales"
hosts => "119.3.20.91:9200"
document_type => "_doc"
}
}
logstash.bat -f mysql.conf