【问题标题】:Logstash SQL Server Data ImportLogstash SQL Server 数据导入
【发布时间】:2015-07-28 11:10:39
【问题描述】:

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 的正确位置

【问题讨论】:

  • 能否提供您的logstash配置?很难理解您要达到的目标。
  • @herb 我正在尝试使用logstash将数据从ms sql获取到elasticsearch,但问题是数据正在插入和更新,但没有在elasticsearch中删除

标签: logstash logstash-configuration


【解决方案1】:

我认为“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 }
}

我从这里下载了 Microsoft JDBC Driver for SQL Server: "https://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx"

将文件解压到“jdbc_driver_library”中指定的路径

然后我运行插件命令:“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 中的文档中所述

【讨论】:

  • 您还可以将 JDBC 驱动程序文件(在我的例子中为 sqljdbc42.jar)放在 Logstash 安装的根文件夹中。这对我来说适用于 Logstash 2.4.0。
  • 更正:只要是您启动 Logstash 的位置(bin\logstash --config myconfigfile.conf),上述说法是正确的。
【解决方案2】:
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 中提供该路径即可。尝试将这些驱动程序解压缩到与代码所示相同的路径中。

【讨论】:

    【解决方案3】:

    这样做:-

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

    【讨论】:

      猜你喜欢
      • 2011-12-30
      • 1970-01-01
      • 1970-01-01
      • 2022-10-05
      • 1970-01-01
      • 2014-10-13
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多