Logstash SQL Server数据导入
input {
jdbc {
jdbc_driver_library => "sqljdbc4.jar"
jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
jdbc_connection_string => "jdbc:sqlserver://192.168.2.126\\SQLEXPRESS2014:1433;databaseName=test
\t jdbc_password => "[email protected]"
schedule => "0 0-59 0-23 * * *"
statement => "SELECT ID , Name, City, State,ShopName FROM dbo.Shops"
\t jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
}
}
filter {
}
output {
stdout { codec => rubydebug }
elasticsearch {
protocol => "http"
\t \t index => "shops"
\t \t document_id => "%{id}"
}
}
我想导入使用Logstash使用JDBC SQL Server作为输入ElasticSearch数据,但我得到错误的类路径是不正确的。
有人知道如何使用Logstash正确位置sqljdbc文件,CONFIG文件
我认为到“sqljdbc4.jar”文件路径不正确连接。下面是我使用从SQL数据库的数据查询到elasticsearch的配置(logstash.conf):
input {
jdbc {
jdbc_driver_library => "D:\temp\sqljdbc\sqljdbc_4.2\enu\sqljdbc42.jar"
jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
jdbc_connection_string => "jdbc:sqlserver://DBSVR_NAME;user=****;password=****;"
jdbc_user => "****"
jdbc_password => "****"
statement => "SELECT *
FROM [DB].[SCHEMA].[TABLE]"
}
}
filter {
}
output {
elasticsearch {
host => "localhost"
index => "INDEX_NAME"
document_type => "DOCUMENT_TYPE"
document_id => "%{id}"
protocol => "http"
}
stdout { codec => rubydebug }
}
我下载了微软JDBC驱动程序的SQL Server从这里: “https://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx”
提取将文件移动到“jdbc_driver_library”中指定的路径
然后我运行plugin命令:“plugin install logstash-input-jdbc”来安装logstash输入jdbc插件。
最后运行logstash:“logstash -f logstash.conf”。
顺便说一句:我也使用Elasticsearch.Net在.NET服务的应用程序来刷新数据 “http://nest.azurewebsites.net/”
这VID:“添加Elasticsearch到现有的.NET/SQL Server应用程序” “https://www.youtube.com/watch?v=sv-MflnT9qI”讨论使用Service Broker队列从sql中获取数据。我们目前正在探索这个选项。
您也可以将JDBC驱动程序文件(sqljdbc42.jar在我的情况)放在根目录Logstash安装的文件夹。这对Logstash 2.4.0有效。 –
更正:只要这是您从(bin \ logstash --config myconfigfile.conf)启动Logstash的位置,上述语句就是正确的。 –
input {
jdbc {
jdbc_driver_library => "C:\Program Files\Microsoft JDBC Driver 6.0 for SQL Server\sqljdbc_6.0\enu\jre8\sqljdbc42.jar"
jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
jdbc_connection_string => "jdbc:sqlserver://[SERVER NAME];databaseName=[DATABASE NAME];"
jdbc_user => "[USERNAME]"
jdbc_password => "[PASSWORD]"
statement => "SELECT eventId, sessionId FROM Events;"
}
}
output {
elasticsearch {
hosts => "http://localhost:9200"
index => "events3"
}
stdout { codec => rubydebug }
}
你需要从https://www.microsoft.com/en-au/download/details.aspx?id=11774 下载sqljdbc司机何地,你会解压缩这些驱动程序只给在jdbc_driver_library这条道路。尝试将这些驱动程序解压缩到代码中所示的相同路径中。
您能否提供您的logstash配置?很难理解你想达到的目标。 – hurb
@herb我想从ms sql的数据到使用logstash的elasticsearch,但问题是数据插入和更新,但没有在elasticsearch中删除 –