Logstash PostgreSQL无法连接数据库错误(Docker)

e5njpo68  于 2023-02-03  发布在  Docker
关注(0)|答案(1)|浏览(189)

Logstash(Docker)无法连接数据库。错误=〉无法连接数据库。已尝试1次{:message=〉Java::OrgPostgresqlUtil::PSQLException:与localhost:5432的连接被拒绝。请检查主机名和端口是否正确,以及邮局主管是否接受TCP/IP连接。,:exception=〉Sequel::DatabaseConnectionError
配置文件:

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

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

jk9hmnmh

jk9hmnmh1#

我修复了这个问题如下=〉
1-)我的PostgreSQL端口是“2022”,所以我在pg_hba.conf文件中更改了IPV4端口= 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

相关问题