logstash通过mysql数据库多张表

Posted huangfeialllen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了logstash通过mysql数据库多张表相关的知识,希望对你有一定的参考价值。

1.下载logstash

https://www.elastic.co/cn/downloads/logstash

2.配置

input {
stdin {
}

jdbc {
type => "tb_role"
jdbc_connection_string => "jdbc:mysql://192.168.3.167:3306/zwls?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true"
jdbc_user => "root"
jdbc_password => "123456"
record_last_run => "true"
use_column_value => "true"
tracking_column => "id"
clean_run => "false"
jdbc_driver_library => "D:softsoftinstallapache-maven-3.3.9 espmysqlmysql-connector-java8.0.16mysql-connector-java-8.0.16.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_paging_enabled => "true"
jdbc_page_size => "500"
statement => "select * from tb_role"
schedule => "* * * * *"
}

jdbc {
type => "tb_order"
jdbc_connection_string => "jdbc:mysql://192.168.3.167:3306/zwls?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true"
jdbc_user => "root"
jdbc_password => "123456"
record_last_run => "true"
use_column_value => "true"
tracking_column => "order_id"
clean_run => "false"
jdbc_driver_library => "D:softsoftinstallapache-maven-3.3.9 espmysqlmysql-connector-java8.0.16mysql-connector-java-8.0.16.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_paging_enabled => "true"
jdbc_page_size => "500"
statement => "select * from tb_order"
schedule => "* * * * *"
}
}


output {

if [type]=="tb_order" {
elasticsearch {
#ESIP地址与端口
hosts => "localhost:9200"
#ES索引名称(自己定义的)
index => "order"
document_id => "%{order_id}"
}
}

if [type]=="tb_role" {
elasticsearch {
#ESIP地址与端口
hosts => "localhost:9200"
#ES索引名称(自己定义的)
index => "role"
document_id => "%{id}"
}
}

}

3.执行命令

logstash -f 配置文件地址



















































以上是关于logstash通过mysql数据库多张表的主要内容,如果未能解决你的问题,请参考以下文章

《果然新鲜》电商项目(45)- 利用Logstash自动同步数据库内容到ES(多文件方式)

mysql 从相同类型的多张表中提取到一张表中

MYSQL创建多张表,相同表结构,不同表名

mysql 多张表做左连接操作 SQL应该如何写

mysql有多张表如何快速复制表并把数据挪过去?

统计多张表的数据总量