如何在CentOS系统中后台运行Prefect Agent并完成健康检查
Prefect Agent 健康检查无返回问题解决方案
1. 修正健康检查请求地址
你启动Agent时指定的监听端口为8081,但执行curl时未携带端口,默认访问的是80端口,无法命中Agent服务,直接修改请求地址即可:
curl --fail --silent "http://100.64.114.291:8081/api/health"
2. 修正Agent启动配置
- 首先确认你使用的是Prefect 1.x版本(你当前的启动命令为1.x语法,2.x版本已无local Agent相关参数)
- 启动时
--agent-address建议绑定0.0.0.0,避免仅绑定本地回环地址导致其他机器无法访问,调整后的启动命令如下:
prefect agent local start -f --agent-address http://0.0.0.0:8081
- 如果你仅在本机做健康检查,可直接用回环地址访问,降低网卡绑定影响:
curl --fail --silent "http://127.0.0.1:8081/api/health"
3. 验证IP地址合法性
你使用的100.64.114.291属于非法IP地址,IPv4单段最大值为255,请确认Agent部署的实际服务器IP,替换后再测试。
4. 后台常驻运行配置
如需将Agent作为后台进程运行,推荐使用systemd做进程管理,配置步骤如下:
新建service配置文件
/etc/systemd/system/prefect-agent.service,内容参考:[Unit] Description=Prefect Local Agent After=network.target [Service] User=替换为实际运行服务的用户 ExecStart=prefect agent local start --agent-address http://0.0.0.0:8081 Restart=always RestartSec=10 [Install] WantedBy=multi-user.target执行命令启动服务并设置开机自启:
systemctl daemon-reload systemctl enable --now prefect-agent.service
内容的提问来源于stack exchange,提问作者PRAVEEN RAJPUT
相关产品推荐
相关产品推荐

