gpt4 book ai didi

jdbc - logstash jdbc 上的多个输入

转载 作者:行者123 更新时间:2023-11-29 02:44:22 26 4
gpt4 key购买 nike

我正在使用 logstash jdbc 来保持 mysql 和 elasticsearch 之间的同步。它在一张 table 上工作正常。但现在我想为多个表做这件事。我需要在终端中打开多个

logstash  agent -f /Users/logstash/logstash-jdbc.conf 

每个都有一个选择查询,或者我们是否有更好的方法来更新多个表。

我的配置文件

input {
jdbc {
jdbc_driver_library => "/Users/logstash/mysql-connector-java-5.1.39-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://localhost:3306/database_name"
jdbc_user => "root"
jdbc_password => "password"
schedule => "* * * * *"
statement => "select * from table1"
}
}
output {
elasticsearch {
index => "testdb"
document_type => "table1"
document_id => "%{table_id}"
hosts => "localhost:9200"
}
}

最佳答案

你绝对可以在一个配置中包含多个 jdbc输入然后参数化 indexdocument_type在你的elasticsearch输出取决于事件来自哪个表。

input {
jdbc {
jdbc_driver_library => "/Users/logstash/mysql-connector-java-5.1.39-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://localhost:3306/database_name"
jdbc_user => "root"
jdbc_password => "password"
schedule => "* * * * *"
statement => "select * from table1"
type => "table1"
}
jdbc {
jdbc_driver_library => "/Users/logstash/mysql-connector-java-5.1.39-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://localhost:3306/database_name"
jdbc_user => "root"
jdbc_password => "password"
schedule => "* * * * *"
statement => "select * from table2"
type => "table2"
}
# add more jdbc inputs to suit your needs
}
output {
elasticsearch {
index => "testdb"
document_type => "%{type}" # <- use the type from each input
hosts => "localhost:9200"
}
}

关于jdbc - logstash jdbc 上的多个输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37613611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com