Logstash 日志存储SQL Server数据导入

Logstash 日志存储SQL Server数据导入,logstash,logstash-configuration,Logstash,Logstash Configuration,输入{ jdbc{ jdbc_驱动程序_库=>“sqljdbc4.jar” jdbc_驱动程序_类=>“com.microsoft.sqlserver.jdbc.SQLServerDriver” jdbc_连接_字符串=>“jdbc:sqlserver://192.168.2.126\\SQLEXPRESS2014:1433;数据库名称=测试 jdbc_密码=>”sa@sa2015" 附表=>“0-59 0-23***” 语句=>“从dbo.Shops中选择ID、名称、城市、州、店名” jdbc

输入{
jdbc{
jdbc_驱动程序_库=>“sqljdbc4.jar”
jdbc_驱动程序_类=>“com.microsoft.sqlserver.jdbc.SQLServerDriver”
jdbc_连接_字符串=>“jdbc:sqlserver://192.168.2.126\\SQLEXPRESS2014:1433;数据库名称=测试
jdbc_密码=>”sa@sa2015"
附表=>“0-59 0-23***”
语句=>“从dbo.Shops中选择ID、名称、城市、州、店名”
jdbc_paging_enabled=>“true”
jdbc_页面_大小=>“50000”
}
}
滤器{
}
输出{
stdout{codec=>rubydebug}
弹性搜索{
协议=>“http”
索引=>“商店”
文档id=>“%{id}”
}
}
我认为“sqljdbc4.jar”文件的路径不正确。下面是我用来将数据从sql db查询到elasticsearch(logstash.conf)的配置:

我从这里下载了用于SQL Server的Microsoft JDBC驱动程序: “”

将文件提取到“jdbc_驱动程序_库”中指定的路径

然后我运行plugin命令:“plugininstalllogstashinputjdbc”来安装logstashinputjdbc插件

最后运行logstash:“logstash-f logstash.conf”

顺便说一句:我还在.Net服务应用程序中使用Elasticsearch.Net来刷新数据 “”

这段视频:“将Elasticsearch添加到现有的.NET/SQL Server应用程序”“”讨论了如何使用Service Broker队列从SQL中获取数据。我们目前正在对此进行探索

编辑-更新主机到主机,如此处的文档所示

您需要从下载sqljdbc驱动程序 无论在哪里解压这些驱动程序,只需在jdbc_driver_库中给出该路径。尝试将这些驱动程序解压到代码中所示的相同路径中。

按如下方式执行:-

input {
  jdbc {
    jdbc_driver_library => "sqljdbc4.jar"
    jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    jdbc_connection_string => "jdbc:sqlserver://192.168.2.126:1433;databaseName=test
    jdbc_password => "sa@sa2015"
    schedule => "0 0-59 0-23 * * *"
    statement => "SELECT ID , Name, City, State,ShopName FROM dbo.Shops"
    jdbc_paging_enabled => "true"
    jdbc_page_size => "50000"
  }
}
filter {
}
output {
  stdout { codec => rubydebug }
    elasticsearch { 
        protocol => "http"
        index => "shops"
        document_id => "%{id}"
        hosts => "your_host_here"

    }
}

你能提供你的logstash配置吗?很难理解你想要实现什么。@我试图使用logstash将ms sql中的数据获取到elasticsearch中,但问题是数据在elasticsearch中插入和更新,但没有删除。你还可以放入JDBC驱动程序文件(在我的例子中是sqljdbc42.jar)在Logstash安装的根文件夹中。这对我来说适用于Logstash 2.4.0。更正:以上语句是正确的,只要它是启动Logstash的位置(bin\Logstash--config myconfigfile.conf)。
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 }
}
input {
  jdbc {
    jdbc_driver_library => "sqljdbc4.jar"
    jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    jdbc_connection_string => "jdbc:sqlserver://192.168.2.126:1433;databaseName=test
    jdbc_password => "sa@sa2015"
    schedule => "0 0-59 0-23 * * *"
    statement => "SELECT ID , Name, City, State,ShopName FROM dbo.Shops"
    jdbc_paging_enabled => "true"
    jdbc_page_size => "50000"
  }
}
filter {
}
output {
  stdout { codec => rubydebug }
    elasticsearch { 
        protocol => "http"
        index => "shops"
        document_id => "%{id}"
        hosts => "your_host_here"

    }
}