今天 Windows 服务器上的 cloudflared 不知道为什么挂了,重新 cloudflared service install 报错:

1
cloudflared service is already installed at Cloudflared; if you are running a cloudflared tunnel, you can point it to multiple origins, avoiding the need to run more than one cloudflared service in the same machine; otherwise if you are really sure, you can do `cloudflared service uninstall` to clean up the existing service and then try again this command

执行 cloudflared service uninstall 也报错:

1
2
3
$ cloudflared service uninstall
2025-03-07T08:02:57Z INF Uninstalling cloudflared agent service windowsServiceName=Cloudflared
Cannot delete agent service: The specified service has been marked for deletion.

解决方法

手动删除服务后重新安装。

1
2
sc stop Cloudflared # 即使报错也不管它
sc delete Cloudflared # 即使报错也不管它

再次确认服务已移除:sc query Cloudflared

必须看到类似这样的报错:

1
2
[SC] EnumQueryServicesStatus:OpenService 失败 1060:
指定的服务未安装。
如果服务仍旧存在,解决方法

如果看到类似的信息:

1
2
3
4
5
6
7
8
9
10
$ sc query Cloudflared

SERVICE_NAME: Cloudflared
TYPE : 10 WIN32_OWN_PROCESS
STATE : 3 STOP_PENDING
(NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0

Ctrl-Shift-Esc,在 任务管理器→详细信息 找找有没有 cloudflared.exe,有的话杀掉。

此时再重新安装服务即可 cloudflared service install ...

¯\_(ツ)_/¯