【问题标题】:Prometheus PostgreSQL server exporter example not working on MacOS?Prometheus PostgreSQL 服务器导出器示例无法在 MacOS 上运行?
【发布时间】:2020-02-02 03:43:34
【问题描述】:

我想在 MacOS 主机设备上试用https://github.com/wrouesnel/postgres_exporter 的快速入门示例。在一个终端中,我在主机网络上以交互模式运行postgres 图像:

> docker run --network=host -it --rm --env POSTGRES_PASSWORD=password postgres
Unable to find image 'postgres:latest' locally
latest: Pulling from library/postgres
8f91359f1fff: Pull complete 
c6115f5efcde: Pull complete 
28a9c19d8188: Pull complete 
2da4beb7be31: Pull complete 
fb9ca792da89: Pull complete 
cedc20991511: Pull complete 
b866c2f2559e: Pull complete 
5d459cf6645c: Pull complete 
cf66247ad881: Pull complete 
35e29440d9da: Pull complete 
362779251360: Pull complete 
fb82d778d08d: Pull complete 
b1f8d21ff25d: Pull complete 
6d49eb0e8dd0: Pull complete 
Digest: sha256:be456a40361cd836e0e1b35fc4d872e20e138f214c93138425169c4a2dfe1b0e
Status: Downloaded newer image for postgres:latest
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Etc/UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start

waiting for server to start....2019-10-03 19:06:10.222 UTC [42] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019-10-03 19:06:10.235 UTC [43] LOG:  database system was shut down at 2019-10-03 19:06:10 UTC
2019-10-03 19:06:10.239 UTC [42] LOG:  database system is ready to accept connections
 done
server started

/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

waiting for server to shut down....2019-10-03 19:06:10.320 UTC [42] LOG:  received fast shutdown request
2019-10-03 19:06:10.322 UTC [42] LOG:  aborting any active transactions
2019-10-03 19:06:10.325 UTC [42] LOG:  background worker "logical replication launcher" (PID 49) exited with exit code 1
2019-10-03 19:06:10.325 UTC [44] LOG:  shutting down
2019-10-03 19:06:10.338 UTC [42] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2019-10-03 19:06:10.436 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2019-10-03 19:06:10.438 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2019-10-03 19:06:10.440 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019-10-03 19:06:10.450 UTC [51] LOG:  database system was shut down at 2019-10-03 19:06:10 UTC
2019-10-03 19:06:10.453 UTC [1] LOG:  database system is ready to accept connections

在另一个终端中,我运行 postgres_exporter 并将其连接到该数据库:

> docker run --net=host --env DATA_SOURCE_NAME="postgresql://postgres:password@localhost:5432/postgres?sslmode=disable" wrouesnel/postgres_exporter
Unable to find image 'wrouesnel/postgres_exporter:latest' locally
latest: Pulling from wrouesnel/postgres_exporter
0d6d2d2516f9: Pull complete 
e9d7b571ef5e: Pull complete 
Digest: sha256:aeea975f0efeacb49c170f0f7c4a4000d3f0099cc33437aedd3f276e628cde1c
Status: Downloaded newer image for wrouesnel/postgres_exporter:latest
time="2019-10-03T19:09:20Z" level=info msg="Established new database connection to \"localhost:5432\"." source="postgres_exporter.go:778"
time="2019-10-03T19:09:20Z" level=info msg="Semantic Version Changed on \"localhost:5432\": 0.0.0 -> 11.5.0" source="postgres_exporter.go:1238"
time="2019-10-03T19:09:20Z" level=info msg="Starting Server: :9187" source="postgres_exporter.go:1459"

据我了解,我应该可以在浏览器中访问 localhost:9187 并查看导出的指标。然而,我得到的是连接被拒绝:

> curl http://localhost:9187
curl: (7) Failed to connect to localhost port 9187: Connection refused

我怀疑这是因为,如 https://docs.docker.com/network/host/ 所述,

主机网络驱动程序仅适用于 Linux 主机,不支持 Docker Desktop for Mac、Docker Desktop for Windows 或 Docker EE for Windows Server。

这是导致问题的原因吗?如果是,我如何调整此快速入门示例以使用 Docker Desktop for Mac?

【问题讨论】:

    标签: postgresql docker prometheus docker-networking


    【解决方案1】:

    有点晚了,但也许对未来的某个人来说。我在 Docker Desktop for Windows 上遇到了同样的问题。为了让它工作,我使用了以下命令:

    docker run -p 9187:9187 -e DATA_SOURCE_NAME="postgresql://postgres:password@localhost:5432/postgres?sslmode=disable" wrouesnel/postgres_exporter
    

    【讨论】:

      猜你喜欢
      • 2011-12-20
      • 1970-01-01
      • 1970-01-01
      • 2017-10-30
      • 2014-05-04
      • 2010-12-09
      • 2017-11-23
      • 2016-07-22
      • 1970-01-01
      相关资源
      最近更新 更多