用于Logstash输入插件JDBC的Mongodb驱动程序类

时间:2017-12-23 21:17:41

标签: java mongodb jdbc logstash logstash-input-jdbc

我使用Logstash使用Logstash 6.0.0将数据库从MongoDB复制到Elasticsearch,这是我的配置文件:

input{
    jdbc{
        jdbc_driver_library => "/usr/share/logstash/driver/mongodb-driver-3.6.1.jar"
        jdbc_driver_class => "mongodb.jdbc.MongoDriver"
        jdbc_connection_string => "jdbc:mongodb://mongo:27017/DevDb"
        jdbc_user => ""
        statement => "*"
    }
}

output {
  elasticsearch {
    hosts => 'http://user:xxxx@elasticsearch:9200'
    index => 'mongo'
 }
  stdout { codec => rubydebug }
}

我正在使用官方的MongoDB java驱动程序,从此链接下载:Mongo java driver,但我收到以下错误:

Error: mongodb.jdbc.MongoDriver not loaded. Are you sure you've included the correct jdbc driver in :jdbc_driver_library?
Exception: LogStash::ConfigurationError

那么我应该使用什么类名?

1 个答案:

答案 0 :(得分:2)

input {
  jdbc {
       jdbc_driver_library => "mongojdbc1.3.jar"
       jdbc_driver_class => "com.dbschema.MongoJdbcDriver"
       jdbc_connection_string => "jdbc:mongodb://username:password@mongourl:27017/database_name?authSource=admin"
       jdbc_user => ""
       jdbc_password => ""
       schedule => "* * * * * *"
       statement => "db.collection_name.find({},{'_id': false});"
  }
}
output {
  elasticsearch {
    hosts => ["http://elasticsearch:9200"]
    index => "vm_server_%{+YYYY.MM.dd}"
    user => "elastic"
    password => "changeme"
  }
}

此配置对我有用,并且配置文件中的驱动程序看起来与jdbc驱动程序不同。因此,寻找jdbc jar。 https://bitbucket.org/dbschema/mongodb-jdbc-driver/src/master/

如果从mongo中查询,则json格式可能与mongo中的格式不同。 为此,您可以检查链接 https://discuss.elastic.co/t/issue-using-logstash-input-jdbc-to-load-mongo-data/174914