[GH-ISSUE #2794] 如何检测 frpc 宕机从而重启服务保证 365x24 稳定运行 #2235

Closed
opened 2026-05-05 13:26:11 -06:00 by gitea-mirror · 9 comments
Owner

Originally created by @rimelink-lorawan on GitHub (Feb 11, 2022).
Original GitHub issue: https://github.com/fatedier/frp/issues/2794

Bug Description

在 OpenWrt 21.02 上安装了 frpc,运行 20 天左右,发现 frpc 已经宕机了。查看服务 service frpc status 显示 running,查看日志 logread -e frpc 没有信息。当然,手动重启 service frpc restart 可以继续工作。

痛点是:部署 frpc 在 OpenWrt 是嵌入式设备,数量众多,且无人值守。手动重启 frpc 不现实。

能检测 frpc 是否正常运行吗?如果有,可以 crontab 添加一个 watch_frpc.sh 脚本,当发现 frpc 宕机时重启 frpc 服务。

frpc Version

0.34.3

frps Version

0.37.1

System Architecture

Linux/amd64

Configurations

[common]
server_addr = server_public_ip
server_port = 7000
token = my_token
protocol = kcp

[web]
type = http
local_ip = 192.168.2.10
local_port = 80
custom_domains = server_public_ip
http_user = my_user
http_pwd = my_pwd
use_encryption = true
use_compression = true

Logs

No response

Steps to reproduce

...

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @rimelink-lorawan on GitHub (Feb 11, 2022). Original GitHub issue: https://github.com/fatedier/frp/issues/2794 ### Bug Description 在 OpenWrt 21.02 上安装了 frpc,运行 20 天左右,发现 frpc 已经宕机了。查看服务 service frpc status 显示 running,查看日志 logread -e frpc 没有信息。当然,手动重启 service frpc restart 可以继续工作。 痛点是:部署 frpc 在 OpenWrt 是嵌入式设备,数量众多,且无人值守。手动重启 frpc 不现实。 能检测 frpc 是否正常运行吗?如果有,可以 crontab 添加一个 watch_frpc.sh 脚本,当发现 frpc 宕机时重启 frpc 服务。 ### frpc Version 0.34.3 ### frps Version 0.37.1 ### System Architecture Linux/amd64 ### Configurations [common] server_addr = server_public_ip server_port = 7000 token = my_token protocol = kcp [web] type = http local_ip = 192.168.2.10 local_port = 80 custom_domains = server_public_ip http_user = my_user http_pwd = my_pwd use_encryption = true use_compression = true ### Logs _No response_ ### Steps to reproduce 1. 2. 3. ... ### Affected area - [ ] Docs - [ ] Installation - [x] Performance and Scalability - [ ] Security - [ ] User Experience - [ ] Test and Release - [ ] Developer Infrastructure - [ ] Client Plugin - [ ] Server Plugin - [ ] Extensions - [ ] Others
gitea-mirror 2026-05-05 13:26:11 -06:00
Author
Owner

@fatedier commented on GitHub (Feb 11, 2022):

理论上不会退出,建议先排查故障原因。

<!-- gh-comment-id:1035852487 --> @fatedier commented on GitHub (Feb 11, 2022): 理论上不会退出,建议先排查故障原因。
Author
Owner

@rimelink-lorawan commented on GitHub (Feb 11, 2022):

理论上不会退出,建议先排查故障原因。

谢谢您的回复。

排查故障原因很难实现:因为运行 20 天后,在 OpenWrt 的 logread 日志没有 frpc 任何信息,失去了线索。

有办法检测 frpc 还在工作不?如果有,那就好办。

<!-- gh-comment-id:1035919858 --> @rimelink-lorawan commented on GitHub (Feb 11, 2022): > 理论上不会退出,建议先排查故障原因。 谢谢您的回复。 排查故障原因很难实现:因为运行 20 天后,在 OpenWrt 的 logread 日志没有 frpc 任何信息,失去了线索。 有办法检测 frpc 还在工作不?如果有,那就好办。
Author
Owner

@rimelink-lorawan commented on GitHub (Feb 11, 2022):

#!/bin/bash
/usr/bin/ping -c 1 192.168.12.1 &> /dev/null && (/usr/bin/logger "INFO: Wireguard alive") || (/usr/bin/logger "ERROR: Wireguard dead, restarting wg-quick@wg0" ; /usr/bin/systemctl restart wg-quick@wg0)

以 wireguard 为例,检测 virtual address 是否 ping 通,查看日志 Wireguard alive or dead,就可以判断 wiregurad 是否正常工作。

这样,就可以编写上面的 watch_wireguard.sh 再加载到 crontab 中当守护

sudo chmod +x /root/watch_wireguard.sh
sudo crontab -e

You will see an existing line in this file. Ignore it, and leave it alone. Add a new line which contains:

          • /root/watch_wireguard.sh > /dev/null
<!-- gh-comment-id:1035921654 --> @rimelink-lorawan commented on GitHub (Feb 11, 2022): #!/bin/bash /usr/bin/ping -c 1 192.168.12.1 &> /dev/null && (/usr/bin/logger "INFO: Wireguard alive") || (/usr/bin/logger "ERROR: Wireguard dead, restarting wg-quick@wg0" ; /usr/bin/systemctl restart wg-quick@wg0) 以 wireguard 为例,检测 virtual address 是否 ping 通,查看日志 Wireguard alive or dead,就可以判断 wiregurad 是否正常工作。 这样,就可以编写上面的 watch_wireguard.sh 再加载到 crontab 中当守护 sudo chmod +x /root/watch_wireguard.sh sudo crontab -e You will see an existing line in this file. Ignore it, and leave it alone. Add a new line which contains: * * * * * /root/watch_wireguard.sh > /dev/null
Author
Owner

@candivan commented on GitHub (Feb 15, 2022):

用supervisor 启动

<!-- gh-comment-id:1039819364 --> @candivan commented on GitHub (Feb 15, 2022): 用supervisor 启动
Author
Owner

@blockchain4trust commented on GitHub (Mar 3, 2022):

编写了一个脚本 watch_frpc.sh 并将它加载到 crontab 中 * * * * * /usr/local/bin/watch_frpc.sh >> /tmp/watch_frpc.log

要求在 frps 和 frpc 都开启 http 代理,这样,一旦发现 frpc 挂了,脚本 watch_frpc.sh 就能发现,它会重启 frpc

经历多种测试环境(模拟:frps 挂了,frpc 挂了,internet 中断,拨出网线。。。),验证该脚本稳定可靠。

#!/bin/sh

VPS_PORT=vhost_http_port
CONFIG_FILE=/usr/local/etc/frpc.ini
SYSTEMCTL=$(which systemctl)

vps_ip=$(awk '$1=="server_addr" {print $3}' $CONFIG_FILE)

curl $vps_ip:$VPS_PORT | grep -q -w Unauthorized
if [ $? -eq 1 ]
then
echo "$(date '+%Y-%m-%d %H:%M:%S') [error]: frpc dropped,restart it!"
$SYSTEMCTL restart frpc
fi

<!-- gh-comment-id:1057740859 --> @blockchain4trust commented on GitHub (Mar 3, 2022): 编写了一个脚本 watch_frpc.sh 并将它加载到 crontab 中 * * * * * /usr/local/bin/watch_frpc.sh >> /tmp/watch_frpc.log 要求在 frps 和 frpc 都开启 http 代理,这样,一旦发现 frpc 挂了,脚本 watch_frpc.sh 就能发现,它会重启 frpc 经历多种测试环境(模拟:frps 挂了,frpc 挂了,internet 中断,拨出网线。。。),验证该脚本稳定可靠。 #!/bin/sh VPS_PORT=vhost_http_port CONFIG_FILE=/usr/local/etc/frpc.ini SYSTEMCTL=$(which systemctl) vps_ip=$(awk '$1=="server_addr" {print $3}' $CONFIG_FILE) curl $vps_ip:$VPS_PORT | grep -q -w Unauthorized if [ $? -eq 1 ] then echo "$(date '+%Y-%m-%d %H:%M:%S') [error]: frpc dropped,restart it!" $SYSTEMCTL restart frpc fi
Author
Owner

@entrehuihui commented on GitHub (Mar 8, 2022):

docker

<!-- gh-comment-id:1061339981 --> @entrehuihui commented on GitHub (Mar 8, 2022): docker
Author
Owner

@github-actions[bot] commented on GitHub (Apr 8, 2022):

Issues go stale after 30d of inactivity. Stale issues rot after an additional 7d of inactivity and eventually close.

<!-- gh-comment-id:1092327396 --> @github-actions[bot] commented on GitHub (Apr 8, 2022): Issues go stale after 30d of inactivity. Stale issues rot after an additional 7d of inactivity and eventually close.
Author
Owner

@zsinba commented on GitHub (Aug 12, 2022):

没有更好办法, 怀疑没有挂,只是阻塞了不能再工作了。
我在NAS上面 的解决办法,是每天(周)重启一下。

<!-- gh-comment-id:1213224839 --> @zsinba commented on GitHub (Aug 12, 2022): 没有更好办法, 怀疑没有挂,只是阻塞了不能再工作了。 我在NAS上面 的解决办法,是每天(周)重启一下。
Author
Owner

@zsinba commented on GitHub (Aug 12, 2022):

理论上不会退出,建议先排查故障原因。

谢谢您的回复。

排查故障原因很难实现:因为运行 20 天后,在 OpenWrt 的 logread 日志没有 frpc 任何信息,失去了线索。

有办法检测 frpc 还在工作不?如果有,那就好办。
非Openwrt的原因,我的表现分为:

  1. 在Openwrt上面,如果不经常使用它,跑三个月也没挂,如果经常使用,估计也就十几天就挂了,挂的表现是它只是不工作了,进程还是正常的。
  2. 在Nas上面的表现比较容易复现,NAS的cpu比较好,加上每天晚上备份数据都要用,所以NAS也比较容易挂。
    解决办法: 定时 重启,通过服务重启。
    定时重启后,后来也没发现这类问题出来 。

楼上老铁写的脚本也不错,但是不好移植呀。 不如定时重启来得暴力和有效。

<!-- gh-comment-id:1213227557 --> @zsinba commented on GitHub (Aug 12, 2022): > > 理论上不会退出,建议先排查故障原因。 > > 谢谢您的回复。 > > 排查故障原因很难实现:因为运行 20 天后,在 OpenWrt 的 logread 日志没有 frpc 任何信息,失去了线索。 > > 有办法检测 frpc 还在工作不?如果有,那就好办。 非Openwrt的原因,我的表现分为: 1. 在Openwrt上面,如果不经常使用它,跑三个月也没挂,如果经常使用,估计也就十几天就挂了,挂的表现是它只是不工作了,进程还是正常的。 2. 在Nas上面的表现比较容易复现,NAS的cpu比较好,加上每天晚上备份数据都要用,所以NAS也比较容易挂。 解决办法: 定时 重启,通过服务重启。 定时重启后,后来也没发现这类问题出来 。 楼上老铁写的脚本也不错,但是不好移植呀。 不如定时重启来得暴力和有效。
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#2235
No description provided.