【问题标题】:Postgres, RHEL and DockerPostgres、RHEL 和 Docker
【发布时间】:2021-01-26 13:08:32
【问题描述】:

在我生命的最后 4 天里,我一直在与这个问题作斗争,这让我发疯。 我正在尝试在 RHEL 8 中部署使用 postgres 数据库的服务。为此,我使用 docker-compose 部署它们。

问题是我可以从服务容器ping postgres容器,但服务无法连接数据库...

我简化了用例,并使用了一个 docker compose,它使用管理员 docker 映像来连接任何列出的数据库管理器,包括 postgres。它在我的机器和使用 ubuntu 20 的测试服务器上运行良好,但是当我在 RHEL 8 中尝试时,我也无法访问数据库!

这是 docker 和 docker-compose 版本: 码头工人:

Client: Docker Engine - Community
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 17:02:36 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46d9d
  Built:            Wed Sep 16 17:01:11 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Docker 编写

docker-compose version 1.25.5, build 8a1c60f6
docker-py version: 4.1.0
CPython version: 3.7.5
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

操作系统

Red Hat Enterprise Linux release 8.1 (Ootpa)

我正在使用的实际 docker-compose 是这样的:

version: '3.1'

services:

  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: example

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

与我在其他两个系统中获得的日志相比,postgres 容器的日志似乎还不错:

db_1       | The files belonging to this database system will be owned by user "postgres".
db_1       | This user must also own the server process.
db_1       | 
db_1       | The database cluster will be initialized with locale "en_US.utf8".
db_1       | The default database encoding has accordingly been set to "UTF8".
db_1       | The default text search configuration will be set to "english".
db_1       | 
db_1       | Data page checksums are disabled.
db_1       | 
db_1       | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1       | creating subdirectories ... ok
db_1       | selecting dynamic shared memory implementation ... posix
db_1       | selecting default max_connections ... 100
db_1       | selecting default shared_buffers ... 128MB
db_1       | selecting default time zone ... Etc/UTC
db_1       | creating configuration files ... ok
db_1       | running bootstrap script ... ok
db_1       | performing post-bootstrap initialization ... ok
db_1       | syncing data to disk ... ok
db_1       | 
db_1       | 
db_1       | Success. You can now start the database server using:
db_1       | 
db_1       |     pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1       | 
db_1       | initdb: warning: enabling "trust" authentication for local connections
db_1       | You can change this by editing pg_hba.conf or using the option -A, or
db_1       | --auth-local and --auth-host, the next time you run initdb.
db_1       | waiting for server to start....2020-10-12 08:18:28.489 UTC [46] LOG:  starting PostgreSQL 12.4 (Debian 12.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1       | 2020-10-12 08:18:28.499 UTC [46] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1       | 2020-10-12 08:18:28.545 UTC [47] LOG:  database system was shut down at 2020-10-12 08:18:25 UTC
db_1       | 2020-10-12 08:18:28.557 UTC [46] LOG:  database system is ready to accept connections
db_1       |  done
db_1       | server started
db_1       | 
db_1       | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1       | 
db_1       | waiting for server to shut down...2020-10-12 08:18:28.572 UTC [46] LOG:  received fast shutdown request
db_1       | .2020-10-12 08:18:28.581 UTC [46] LOG:  aborting any active transactions
db_1       | 2020-10-12 08:18:28.582 UTC [46] LOG:  background worker "logical replication launcher" (PID 53) exited with exit code 1
db_1       | 2020-10-12 08:18:28.583 UTC [48] LOG:  shutting down
db_1       | 2020-10-12 08:18:28.648 UTC [46] LOG:  database system is shut down
db_1       |  done
db_1       | server stopped
db_1       | 
db_1       | PostgreSQL init process complete; ready for start up.
db_1       | 
db_1       | 2020-10-12 08:18:28.693 UTC [1] LOG:  starting PostgreSQL 12.4 (Debian 12.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1       | 2020-10-12 08:18:28.694 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1       | 2020-10-12 08:18:28.694 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1       | 2020-10-12 08:18:28.712 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1       | 2020-10-12 08:18:28.751 UTC [55] LOG:  database system was shut down at 2020-10-12 08:18:28 UTC
db_1       | 2020-10-12 08:18:28.764 UTC [1] LOG:  database system is ready to accept connections

以前有人遇到过这个问题吗?你有什么建议我可以试试吗?

编辑: adminer 容器日志与其他机器相同。他们只是在尝试连接时抛出这个错误,而不是一个 ok 消息:

Is the server running on host "postgres" (10.10.10.2) and accepting TCP/IP connections on port 5432?

【问题讨论】:

  • 实际错误是什么?你能显示连接到数据库的代码吗?
  • 我可以给你看代码,是的,但它也用不同的语言(Php 和 Python)显示同样的错误,这让我相信这与代码无关

标签: postgresql docker docker-compose rhel


【解决方案1】:

我猜你是从某个站点安装 docker 的。对于 RHEL 8,尝试使用 Podman 和 Buildah - OCI 兼容的替代方案,不需要守护程序。这个article 解释了它。这些是 RHEL 8 中的默认容器工具。

【讨论】:

  • 你恰到好处。负责安装 docker 的人是从 Docker-CE 存储库中完成的。我不允许在此服务器上安装任何新工具。我认为这个问题肯定会使用 podman 来解决。非常感谢这篇文章。我有一个想法,但我认为这对我来说更清楚。我将尝试说服“上面的人”改用 podman。至少在 RHEL 8 中 :)
  • 很高兴为您提供帮助。这里有一些其他的参考。在 RHEL 8 中构建和运行容器:access.redhat.com/documentation/en-us/red_hat_enterprise_linux/…
【解决方案2】:

在您的 RHEL 8 环境中检查来自管理员容器的日志,您将能够从那里发现问题。

命令将是 docker logs adminer-container-name

【讨论】:

  • 是的,我试过了,我得到的只是一个错误:“服务器是否在主机“postgres”(10.10.10.2)上运行并接受端口 5432 上的 TCP/IP 连接? ”。我会把它添加到帖子中。感谢您的检查! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-21
  • 1970-01-01
  • 2018-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多