Files
AI-document/学习笔记/rclone代理配置问题总结.md
T
2026-05-07 15:32:42 +08:00

118 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# rclone 同步代理配置问题总结
## 问题描述
rclone bisync 在同步时无法连接到 Google API 服务器(googleapis.com),
导致同步失败,错误信息如下:
```
CRITICAL: Failed to create file system for destination "gdrive:学习笔记":
couldn't find root directory ID: dial tcp 142.250.204.42:443: i/o timeout
```
系统使用 Clash Verge 作为代理工具,代理端口为 7897,但 rclone 无法通过
代理访问 googleapis.com。
---
## 根本原因
rclone 访问 Google Drive 依赖 `googleapis.com` 这个域名,但该域名在
Clash 的规则配置中没有被正确路由到代理节点,导致走了直连并超时。
同时,同步脚本中的网络检测函数 `check_network` 也在检测 googleapis.com
所以网络检测始终失败,触发重试逻辑,最终放弃同步。
---
## 尝试过但未成功的方法
### 方法一:直接用 curl 测试代理端口
```bash
curl -sf --max-time 10 --proxy http://127.0.0.1:7897 https://www.googleapis.com
```
**结果**:不可用
**原因**Clash 规则模式下 googleapis.com 没有匹配到代理规则,走了直连。
---
### 方法二:在 Clash Verge 全局扩展覆写配置(Merge)中添加规则,策略组写为 PROXY
```yaml
prepend-rules:
- DOMAIN-SUFFIX,googleapis.com,PROXY
```
**结果**:不可用
**原因**:配置里不存在叫 `PROXY` 的策略组,实际策略组名称是 `OK CLOUD`
规则匹配后找不到对应出口,流量仍然直连。
---
### 方法三:将策略组改为 `OK CLOUD` 后重新加载
```yaml
prepend-rules:
- DOMAIN-SUFFIX,googleapis.com,OK CLOUD
```
**结果**:不可用
**原因**googleapis.com 这个域名通过代理节点也无法访问,是域名层面的限制。
而 google.com 和 drive.google.com 可以正常访问,说明节点对该域名有特殊限制。
---
### 方法四:设置环境变量让 rclone 走系统代理,但未修改检测函数
```bash
export HTTPS_PROXY=http://127.0.0.1:7897
~/gdrive_sync.sh
```
**结果**:不可用
**原因**:脚本中 `check_network` 函数仍检测 `googleapis.com`
该域名不可达导致网络检测失败,脚本在进入 rclone 同步之前就已放弃。
---
## 最终解决方案
修改同步脚本,做两处调整:
**1. 在配置区加入代理环境变量:**
```bash
export HTTPS_PROXY="http://127.0.0.1:7897"
export HTTP_PROXY="http://127.0.0.1:7897"
```
**2. 将 `check_network` 的检测目标改为 `drive.google.com`**
```bash
curl -sf --max-time 10 --proxy "$HTTPS_PROXY" https://drive.google.com > /dev/null 2>&1
```
**原因**`drive.google.com` 可以通过代理正常访问,用它作为网络检测目标更可靠。
rclone 通过代理访问 Google Drive API 也能成功,说明 googleapis.com
仅在直接 curl 测试时不可达,rclone 内部的请求路径略有不同。
---
## 关键教训
| 问题 | 教训 |
|------|------|
| 策略组名称写错 | Clash 规则中策略组名称必须与配置完全一致,不能用通用名如 `PROXY` |
| 网络检测域名选择不当 | 检测域名应选择实际可达且与业务相关的域名,而非 API 端点 |
| googleapis.com 不可直接访问 | 应以 drive.google.com 等用户端域名作为连通性判断依据 |
---
*记录日期:2026-05-07*