【问题标题】:Logstash PostgreSQL Unable to Connect Database Error (Docker)Logstash PostgreSQL 无法连接数据库错误 (Docker)
【发布时间】:2023-02-02 23:10:45
【问题描述】:

Logstash(docker) 无法连接数据库。 错误 => 无法连接到数据库。尝试 1 次 {:message=>Java::OrgPostgresqlUtil::PSQLException: 连接到 localhost:5432 被拒绝。检查主机名和端口是否正确,以及 postmaster 是否正在接受 TCP/IP 连接。, :exception=>Sequel::DatabaseConnectionError

logstash.conf 文件:

input{
jdbc {
  jdbc_driver_library => '/usr/share/logstash/logstash-core/lib/jars/postgresql-42.5.0.jar'
  jdbc_driver_class => "org.postgresql.Driver"
  jdbc_connection_string => "jdbc:postgresql://localhost:2022/testdb"
  jdbc_user => "postgres"
  jdbc_password => "12345"
  statement => "SELECT * FROM users"
  schedule => "* * * * *"
}
}

output {
    elasticsearch {
         hosts => "elasticsearch:9200"
         index => "%{indexName}"
    }
}

logstash.yml 文件:

http.host: "0.0.0.0"
path.config: /usr/share/logstash/pipeline
xpack.monitoring.elasticsearch.hosts: ["localhost:9200"]
xpack.monitoring.enabled: true

我怎样才能连接到数据库?

【问题讨论】:

  • jdbc_connection_string 中,您需要使用数据库容器的名称。 localhost 是 logstash 容器并且没有运行数据库。
  • 我试过但出现此错误:无法连接到数据库。已尝试 1 次 {:message=>"Java::OrgPostgresqlUtil::PSQLException: 连接尝试失败。", :exception=>Sequel::DatabaseConnectionError, :cause=>org.postgresql.util.PSQLException: 连接尝试失败。

标签: postgresql docker jdbc logstash


【解决方案1】:

我按如下方式解决了这个问题=>

1-) 我的 postgreSQL 端口是“2022”,所以我在 pg_hba.conf 文件中更改了 IPV4 port=127.0.0.1/22。

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/22            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/22            trust
host    replication     all             ::1/128                 trust

host all all all md5

2-) 使用计算机 ip 地址 (ipconfig) 而不是 localhost=

old= jdbc:postgresql://localhost:2022/testdb 
new= jdbc:postgresql://192.168.1.83:2022/testdb  

【讨论】:

    猜你喜欢
    • 2018-04-08
    • 2019-07-04
    • 2019-11-25
    • 2022-01-04
    • 2021-04-05
    • 2020-05-14
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    相关资源
    最近更新 更多