日志分析与调试技巧
日志配置
正确配置日志对于问题排查至关重要:
[common]
# 日志文件路径
log_file = /var/log/frps.log
# 日志级别: trace, debug, info, warn, error
log_level = info
# 日志最大天数
log_max_days = 3
# 是否开启详细日志
detailed_errors_to_client = true
常见错误码分析
理解FRP常见错误码:
- error code 0: 成功
- error code 1: 服务器内部错误
- error code 2: 无效的参数
- error code 3: 无权访问
- error code 7: 资源不可用
- error code 8: 资源已存在
调试模式
开启调试模式获取更多信息:
[common]
log_level = debug
使用tcpdump分析
使用tcpdump分析网络流量:
tcpdump -i any port 7000 -vv
定位性能瓶颈
使用性能分析工具:
# 检查CPU和内存使用情况
top -p $(pgrep frps)
# 检查网络状态
ss -tuln | grep frps
配置Prometheus监控
启用Prometheus指标收集:
[common]
enable_prometheus = true
metrics_port = 8099