HI everyone,
I am a beginner in logstash. I'm running Logstash version 7.4.1 on docker.
I want to create a pipeline as simple as possible to load my database in Postgresql installed in local but i find an error with logstash.
my logstash config file
input {
jdbc {
# Postgres jdbc connection string to our database, mydb
jdbc_connection_string => "jdbc:postgresql://127.0.0.1:5432/logstashtest"
# The user we wish to execute our statement as
jdbc_user => "xxx"
# The path to our downloaded jdbc driver
jdbc_driver_library => "/home/tnvan/postgresql-42.2.8.jar"
# The name of the driver class for Postgresql
jdbc_driver_class => "org.postgresql.Driver"
jdbc_password => "xxx"
# our query
statement => "SELECT * from contacts"
}
}
output {
stdout { codec => json_lines }
}
The error log:
[2019-11-26T15:47:53,810][ERROR][logstash.inputs.jdbc ] Unable to connect to database. Tried 1 times {:error_message=>"Java::OrgPostgresqlUtil::PSQLException: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."}
[2019-11-26T15:47:53,814][ERROR][logstash.javapipeline ] A plugin had an unrecoverable error. Will restart this plugin.
Pipeline_id:main
Plugin: <LogStash::Inputs::Jdbc jdbc_user=>"foo", jdbc_password=><password>, statement=>"SELECT * from contacts", jdbc_driver_library=>"/home/tnvan/postgresql-42.2.8.jar", jdbc_connection_string=>"jdbc:postgresql://127.0.0.1:5432/logstashtest", id=>"6c4aa1be1b9785f024f95401393707ac2c98b6f976b3f003aa849149ca667a74", jdbc_driver_class=>"org.postgresql.Driver", enable_metric=>true, codec=><LogStash::Codecs::Plain id=>"plain_67a76df9-f51f-4cea-8a3b-efc83eef8029", enable_metric=>true, charset=>"UTF-8">, jdbc_paging_enabled=>false, jdbc_page_size=>100000, jdbc_validate_connection=>false, jdbc_validation_timeout=>3600, jdbc_pool_timeout=>5, sql_log_level=>"info", connection_retry_attempts=>1, connection_retry_attempts_wait_time=>0.5, plugin_timezone=>"utc", last_run_metadata_path=>"/usr/share/logstash/.logstash_jdbc_last_run", use_column_value=>false, tracking_column_type=>"numeric", clean_run=>false, record_last_run=>true, lowercase_column_names=>true, use_prepared_statements=>false>
Error: Java::OrgPostgresqlUtil::PSQLException: Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Exception: Sequel::DatabaseConnectionError
Stack: org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(org/postgresql/core/v3/ConnectionFactoryImpl.java:280)
I do some google and have changed the config files of postgresql:
postgresql.conf
listen_addresses = '*'
pg_hba.conf
host all all 172.17.0.0/32 trust
host all all 10.0.2.15/32 trust
but still the same error.
More information:
ip addr show
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:19:49:0b:27 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:19ff:fe49:b27/64 scope link
valid_lft forever preferred_lft forever
Thank you all.