在公共服务器上,我有一个 Prometheus 导出器设置。这被防火墙故意阻止,因为信息不应该公开。
从一个单独的网络(我的具有动态 IP 的家庭网络),我希望抓取 Prometheus 导出器。这个想法是使用 autossh 来设置 SSH 隧道,以便能够以这种方式抓取端点。我更喜欢使用 docker 设置 autossh。
到目前为止,我已经设法使用以下 docker-compose 设置了一个autossh docker 容器:
remote-nodeexporter:
image: jnovack/autossh:latest
container_name: remote-nodeexporter
environment:
- SSH_HOSTNAME=PUBLIC_IP
- SSH_TUNNEL_REMOTE=19100
- SSH_TUNNEL_LOCAL=9100
- SSH_MODE=-L
restart: always
volumes:
- /path/to/id_rsa:/id_rsa
ports:
- "19100:19100"
在容器内,这可以正常工作:
/ # wget localhost:19100/metrics
Connecting to localhost:19100 (127.0.0.1:19100)
saving to 'metrics'
metrics 100% |**********************************************************************************************************************************************************************************************| 75595 0:00:00 ETA
'metrics' saved
但是从主机(或其他容器),我得到错误:
/ # wget localhost:19100/metrics
--2020-07-07 08:53:25-- http://localhost:19100/metrics
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:19100... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
如何正确公开此端点?