如何修复 Portainer Edge Agent [message: an error occured during short poll] [error: short poll request failed]

问题:

你正在尝试运行 Portainer Edge Agent,但无法连接到 Portainer UI 中的端点,但你在日志中看到类似这样的错误消息:

error_log.txt
2020/10/24 13:58:23 [ERROR] [internal,edge,poll] [message: an error occured during short poll] [error: short poll request failed]

解决方案

首先,检查你的 EDGE_ID 和你的 EDGE_KEY。在大多数情况下,这些设置不正确,阻止了 Edge Agent 和 Portainer 实例之间的正确通信。

如果这没有帮助,检查你的防火墙。Portainer 实例的端口 8000。创建新端点时,Portainer 将显示类似这样的消息

portainer_agent_communication.txt
代理将通过 https://portainer.mydomain.com 和 tcp://portainer.mydomain.com:8000 与 Portainer 通信

根据你的系统配置,你需要在防火墙上启用端口 8000,例如使用

test_nc.sh
sudo ufw enable 8000/tcp

为了测试连接性,你可以使用 nc

test_nc.sh
echo -e "\n" |  nc portainer.techoverflow.net 8000

这是在正常工作的 Portainer 实例上的样子:

test_nc.sh
$ echo -e "\n" |  nc portainer.mydomain.com 8000
HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8
Connection: close

400 Bad Request

如果你没有看到任何响应,检查你的防火墙并检查你是否在 Portainer 容器上暴露了端口 8000。

此外,你可以在任何在线 base64 解码器(如 base64code.com)中解码你的 EDGE_KEY(使用 Portainer Edge Agent 实例中实际使用的那个):解码

edge_key_base64.txt
aHR0cHM6Ly9wb3J0YWluZXIubXlkb21haW4uY29tfHBvcnRhaW5lci5teWRvbWFpbi5jb206ODAwMHw3MTphNTpiYTpkMjo4MToxOToxMTo4NzplYTowZjo0NDo0YTpmYTo0Mjo4YTphNnwz

将产生此字符串:

edge_key_decoded.txt
https://portainer.mydomain.com|portainer.mydomain.com:8000|71:a5:ba:d2:81:19:11:87:ea:0f:44:4a:fa:42:8a:a6|3

你可以在其中检查 URL。例如,检查协议(http 或 https)是否与你用于配置主 Portainer 实例的不匹配。

最后,在运行 Portainer Edge Agent 的主机上,检查主机名是否正确解析:

check_hostname_resolution.sh
host portainer.mydomain.com

这应该至少显示 Portainer 实例的 IPv4 地址。如果不正确,这些是最可能的原因:

始终检查你从本地计算机获得的结果是否与从运行 Portainer Edge Agent 的主机获得的结果相同。


Check out similar posts by category: Container, Docker, Portainer