Logstash SQL Server数据导入

时间:2015-07-28 11:10:40

标签: logstash logstash-configuration

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
	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}"
    }
}

我想使用JDBC SQL Server作为输入使用Logstash导入ElasticSearch中的数据,但我得到的错误类路径不正确。

有人知道如何使用Logstash连接sqljdbc FILE WITH CONFIG FILE的正确位置

3 个答案:

答案 0 :(得分:19)

我认为“sqljdbc4.jar”文件的路径不正确。这是我用来查询sql db中的数据到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 {
    hosts => "localhost"
    index => "INDEX_NAME"
    document_type => "DOCUMENT_TYPE"
    document_id => "%{id}"
    protocol => "http"
  }
  stdout { codec => rubydebug }
}

我从这里下载了用于SQL Server的Microsoft JDBC驱动程序: “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”。

暂且不说:我也在.Net服务应用中使用Elasticsearch.Net来刷新数据 “http://nest.azurewebsites.net/

这个视频:“将Elasticsearch添加到现有的.NET / SQL Server应用程序”“https://www.youtube.com/watch?v=sv-MflnT9qI”讨论使用Service Broker队列从sql中获取数据。我们目前正在探索这个选项。

编辑 - 更新主机的主机,如此处的文档https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-hosts

答案 1 :(得分:3)

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中提供该路径即可。尝试将这些驱动程序解压缩到代码中显示的相同路径。

答案 2 :(得分:0)

这样做:-

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"

    }
}