我需要从PostgreSQL数据库获取数据并将其编入Elasticsearch。 https://www.elastic.co/blog/logstash-jdbc-input-plugin
当我运行/opt/logstash-2.3.3/bin/logstash -v -f es_table.logstash.conf
时
我收到以下错误:
Pipeline aborted due to error
{:exception=>#<LogStash::ConfigurationError: org.postgres.Driver not loaded.
Are you sure you've included the correct jdbc driver in :jdbc_driver_library?>, :backtrace=>["/opt/logstash-2.3.3/vendor/bundle/jruby/1.9/gems/logstash-input-jdbc-3.0.2/lib/logstash/plugin_mixins/jdbc.rb:156:in `prepare_jdbc_connection'", "/opt/logstash-2.3.3/vendor/bundle/jruby/1.9/gems/logstash-input-jdbc-3.0.2/lib/logstash/plugin_mixins/jdbc.rb:148:in `prepare_jdbc_connection'", "/opt/logstash-2.3.3/vendor/bundle/jruby/1.9/gems/logstash-input-jdbc-3.0.2/lib/logstash/inputs/jdbc.rb:167:in `register'", "/opt/logstash-2.3.3/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.3-java/lib/logstash/pipeline.rb:330:in `start_inputs'", "org/jruby/RubyArray.java:1613:in `each'", "/opt/logstash-2.3.3/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.3-java/lib/logstash/pipeline.rb:329:in `start_inputs'", "/opt/logstash-2.3.3/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.3-java/lib/logstash/pipeline.rb:180:in `start_workers'", "/opt/logstash-2.3.3/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.3-java/lib/logstash/pipeline.rb:136:in `run'", "/opt/logstash-2.3.3/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.3-java/lib/logstash/agent.rb:473:in `start_pipeline'"], :level=>:error}
以下是我的Logstash配置:
input {
jdbc {
jdbc_user => 'user'
jdbc_driver_class => 'org.postgresql.Driver'
jdbc_connection_string => 'jdbc:postgresql://1.1.1.1:5432/db'
lowercase_column_names => false
clean_run => false
jdbc_driver_library => '/usr/share/java/postgresql-jdbc4.jar'
jdbc_password => 'pass'
jdbc_validate_connection => true
jdbc_page_size => 1000
jdbc_paging_enabled => true
statement => 'SELECT * FROM "table"'
type => 'table'
}
...
jdbc4驱动程序存在。我也尝试了jdbc3而没有成功。
ls /usr/share/java | grep postgresql-jdbc
postgresql-jdbc3-9.2.jar
postgresql-jdbc3.jar
postgresql-jdbc4-9.2.jar
postgresql-jdbc4.jar
Driver类在里面:
jar tf /usr/share/java/postgresql-jdbc4.jar | grep -i driver
org/postgresql/Driver$1.class
org/postgresql/Driver$ConnectThread.class
org/postgresql/Driver.class
org/postgresql/util/PSQLDriverVersion.class
META-INF/services/java.sql.Driver
端口5432已打开:
telnet 192.168.109.108 5432
Trying 192.168.109.108...
Connected to 192.168.109.108.
Escape character is '^]'.
对数据库的身份验证有效。
答案 0 :(得分:3)
问题是因为我在驱动程序名称中出错了。
我写了class Person
{
public string name;
public string alias;
public Person(string _name, string _alias = "")
{
name = _name;
alias = _alias;
}
}
class House
{
public string name;
public string id;
public string alias;
public List<Person> people = new List<Person>();
public House(string _name, string _id, string _alias = "")
{
name = _name;
id = _id;
alias = _alias;
}
}
class Program
{
static List<House> houses = new List<House>();
static void Main(string[] args)
{
// Add houses here
foreach (House house in FindHouses("criteria"))
{
// Do stuff
}
}
// Find all the houses in which the criteria exists
static List<House> FindHouses(string criteria)
{
// Return the list of all houses in which the criteria exists
return houses.Where(h =>
h.name.Contains(criteria) ||
h.id == criteria ||
h.alias.Contains(criteria) ||
h.people.Any(p =>
p.name.Contains(criteria) ||
p.alias.Contains(criteria))).ToList();
}
}
正确的名称是jdbc_driver_class => 'org.postgres.Driver'
答案 1 :(得分:0)
我按照此 issue
中建议的解决方法解决了此问题原因:
<块引用>这是我们在 JDK 9 (Jigsaw) 中模块更改时遇到的一个已知问题。类加载器已经看到了一些变化,我们之前添加到一些驱动程序加载的解决方法现在失败了。 jdbc 输入在 JDK 11 (9+) 中也有同样的失败。我们正在努力修复。
对我有用的解决方法:
<块引用>一个“极端”的解决方法是将驱动程序文件复制到 /logstash-core/lib/jars/ 目录。当通过 java 启动 logstash 时,这些 jar 被添加到正确的 JDK 类路径中。