mirror of
https://github.com/fatedier/frp.git
synced 2026-05-15 08:05:49 -06:00
[GH-ISSUE #2794] 如何检测 frpc 宕机从而重启服务保证 365x24 稳定运行 #2235
Labels
No labels
In Progress
WIP
WaitingForInfo
bug
doc
duplicate
easy
enhancement
future
help wanted
invalid
lifecycle/stale
need-issue-template
need-usage-help
no plan
proposal
pull-request
question
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/frp#2235
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
@fatedier commented on GitHub (Feb 11, 2022):
理论上不会退出,建议先排查故障原因。
@rimelink-lorawan commented on GitHub (Feb 11, 2022):
谢谢您的回复。
排查故障原因很难实现:因为运行 20 天后,在 OpenWrt 的 logread 日志没有 frpc 任何信息,失去了线索。
有办法检测 frpc 还在工作不?如果有,那就好办。
@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:
@candivan commented on GitHub (Feb 15, 2022):
用supervisor 启动
@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
@entrehuihui commented on GitHub (Mar 8, 2022):
docker
@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.
@zsinba commented on GitHub (Aug 12, 2022):
没有更好办法, 怀疑没有挂,只是阻塞了不能再工作了。
我在NAS上面 的解决办法,是每天(周)重启一下。
@zsinba commented on GitHub (Aug 12, 2022):
解决办法: 定时 重启,通过服务重启。
定时重启后,后来也没发现这类问题出来 。
楼上老铁写的脚本也不错,但是不好移植呀。 不如定时重启来得暴力和有效。