【发布时间】:2016-06-23 21:47:19
【问题描述】:
我正在尝试将 MySQL 表导入 Elasticsearch。它是一个包含 10 个不同列的表,其中一个 8 位 VARCHAR 设置为主键。 MySQL 数据库位于远程主机上。
为了将数据从 MySQL 传输到 Elasticsearch,我决定使用 Logstash 和 jdbc MySQL 驱动程序。
我假设 Logstash 会为我创建索引,如果它不存在的话。
这是我的 logstash.conf 脚本:
input{
jdbc {
jdbc_driver_library => "/home/user/logstash/mysql-connector-java-5.1.17-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://[remotehostipnumber]/databasename"
jdbc_validate_connection => true
jdbc_user => "username"
jdbc_password => "password"
schedule => "* * * * *"
statement => "select * from table"
}
}
output
{
elasticsearch
{
index => "tables"
document_type => "table"
document_id => "%{table_id}"
hosts => "localhost:9200"
}stdout { codec => json_lines }
}
在运行 logstash config test 时,它会输出“Configration OK”消息:
sudo /opt/logstash/bin/logstash --configtest -f /home/user/logstash/logstash.conf
同样在执行 logstash.conf 脚本时,Elasticsearch 会输出:
Settings: Default filter workers: 1
Logstash startup completed
但是当我去检查索引是否已经创建并且数据也已经添加时:
curl -XGET 'localhost:9200/tables/table/_search?pretty=true'
我明白了:
{
"error" : {
"root_cause" : [ {
"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "tables",
"index" : "table"
} ],
"type" : "index_not_found_exception",
"reason" : "no such index",
"resource.type" : "index_or_alias",
"resource.id" : "tables",
"index" : "tables"
},
"status" : 404
}
数据未被编入索引的潜在原因是什么?
附言。我让 Elasticsearch 服务器在单独的终端窗口中运行,以确保 Logstash 可以连接并与之交互。
【问题讨论】:
-
你能用
--debug运行logstash,这样你就可以看到更多的输出了吗?你能ping你的数据库主机remotehostipnumber吗? -
由于您使用的是 stdout 输出,您应该能够检查 Logstash 是否接收到数据,并知道问题是否在于 Logstash 检索日志或将它们发送到 Elasticsearch
-
查看 --debug 输出,它看起来像已连接,我还可以 ping 数据库主机。真的卡在这里
标签: mysql database jdbc elasticsearch logstash