- Changed docker-compose.yml to mount OrbStack Docker socket path (/Users/brunogao/.orbstack/run/docker.sock) - Updated GITEA_INSTANCE_URL to use 192.168.1.83:33000 instead of gitea:3000 for proper DNS resolution - Both runner-docker and runner-k8s now correctly point to OrbStack Docker daemon - This resolves the 'Cannot connect to the Docker daemon' error and DNS resolution failures
231 lines
7.5 KiB
Bash
Executable File
231 lines
7.5 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# GitHub 访问诊断脚本
|
||
# 用于诊断 GitHub 访问慢的问题
|
||
|
||
set -e
|
||
|
||
# 颜色定义
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'
|
||
NC='\033[0m'
|
||
|
||
print_header() {
|
||
echo -e "\n${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||
echo -e "${BLUE}$1${NC}"
|
||
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"
|
||
}
|
||
|
||
print_success() {
|
||
echo -e "${GREEN}✓${NC} $1"
|
||
}
|
||
|
||
print_error() {
|
||
echo -e "${RED}✗${NC} $1"
|
||
}
|
||
|
||
print_warning() {
|
||
echo -e "${YELLOW}⚠${NC} $1"
|
||
}
|
||
|
||
print_info() {
|
||
echo -e "${BLUE}ℹ${NC} $1"
|
||
}
|
||
|
||
# 1. 检查 WireGuard 状态
|
||
check_wireguard() {
|
||
print_header "1. WireGuard 隧道状态"
|
||
|
||
if ifconfig wg0 &>/dev/null; then
|
||
WG_IP=$(ifconfig wg0 | grep "inet " | awk '{print $2}')
|
||
print_success "WireGuard 已连接"
|
||
print_info " 隧道 IP: $WG_IP"
|
||
|
||
# 检查路由
|
||
if route -n get github.com | grep -q "interface: wg0"; then
|
||
print_success " GitHub 流量经过 WireGuard"
|
||
else
|
||
GITHUB_ROUTE=$(route -n get github.com | grep "interface:" | awk '{print $2}')
|
||
print_warning " GitHub 流量未经过 WireGuard (当前接口: $GITHUB_ROUTE)"
|
||
fi
|
||
else
|
||
print_error "WireGuard 未连接"
|
||
print_info " 请在 WireGuard App 中启动隧道"
|
||
return 1
|
||
fi
|
||
}
|
||
|
||
# 2. 检查 /etc/hosts
|
||
check_hosts_file() {
|
||
print_header "2. /etc/hosts 配置检查"
|
||
|
||
if grep -q "github.com" /etc/hosts 2>/dev/null; then
|
||
print_warning "/etc/hosts 中存在 GitHub 条目(可能导致问题):"
|
||
grep "github.com\|githubusercontent.com" /etc/hosts | while read -r line; do
|
||
echo " $line"
|
||
done
|
||
print_info " 建议:删除这些静态 IP,让 DNS 自动解析最优节点"
|
||
else
|
||
print_success "/etc/hosts 中没有 GitHub 静态条目"
|
||
fi
|
||
}
|
||
|
||
# 3. 检查 ClashX Meta 状态
|
||
check_clash() {
|
||
print_header "3. ClashX Meta 状态"
|
||
|
||
# 检查 ClashX 是否运行
|
||
if pgrep -x "ClashX Meta" >/dev/null; then
|
||
print_success "ClashX Meta 正在运行"
|
||
|
||
# 检查端口
|
||
if lsof -nP -iTCP:7890 | grep -q LISTEN; then
|
||
print_success " 混合端口 7890 正在监听"
|
||
else
|
||
print_warning " 混合端口 7890 未监听"
|
||
fi
|
||
|
||
# 检查配置文件
|
||
if [ -f "clash/wg-config.yaml" ]; then
|
||
print_info " 检查配置文件..."
|
||
if grep -q "proxies: \[\]" clash/wg-config.yaml; then
|
||
print_error " 配置文件中代理列表为空!"
|
||
print_info " 这会导致所有流量走 DIRECT,不使用 WireGuard 代理"
|
||
else
|
||
print_success " 配置文件包含代理定义"
|
||
fi
|
||
fi
|
||
else
|
||
print_warning "ClashX Meta 未运行"
|
||
fi
|
||
}
|
||
|
||
# 4. DNS 解析测试
|
||
check_dns_resolution() {
|
||
print_header "4. GitHub DNS 解析测试"
|
||
|
||
print_info "测试 github.com 解析..."
|
||
GITHUB_IPS=$(dig +short github.com @1.1.1.1 | grep -E '^[0-9]+\.')
|
||
if [ -n "$GITHUB_IPS" ]; then
|
||
print_success "DNS 解析成功 (使用 1.1.1.1):"
|
||
echo "$GITHUB_IPS" | while read -r ip; do
|
||
echo " $ip"
|
||
done
|
||
else
|
||
print_error "DNS 解析失败"
|
||
fi
|
||
|
||
echo ""
|
||
print_info "测试 raw.githubusercontent.com 解析..."
|
||
RAW_IPS=$(dig +short raw.githubusercontent.com @1.1.1.1 | grep -E '^[0-9]+\.')
|
||
if [ -n "$RAW_IPS" ]; then
|
||
print_success "DNS 解析成功:"
|
||
echo "$RAW_IPS" | while read -r ip; do
|
||
echo " $ip"
|
||
done
|
||
fi
|
||
}
|
||
|
||
# 5. 连接速度测试
|
||
check_connection_speed() {
|
||
print_header "5. GitHub 连接速度测试"
|
||
|
||
print_info "测试 HTTPS 连接延迟..."
|
||
GITHUB_TIME=$(curl -o /dev/null -s -w '%{time_total}\n' https://github.com 2>/dev/null || echo "失败")
|
||
if [ "$GITHUB_TIME" != "失败" ]; then
|
||
TIME_MS=$(echo "$GITHUB_TIME * 1000" | bc)
|
||
if (( $(echo "$GITHUB_TIME < 1" | bc -l) )); then
|
||
print_success "连接延迟: ${TIME_MS}ms (正常)"
|
||
elif (( $(echo "$GITHUB_TIME < 3" | bc -l) )); then
|
||
print_warning "连接延迟: ${TIME_MS}ms (较慢)"
|
||
else
|
||
print_error "连接延迟: ${TIME_MS}ms (很慢)"
|
||
fi
|
||
else
|
||
print_error "连接测试失败"
|
||
fi
|
||
|
||
echo ""
|
||
print_info "测试小文件下载速度..."
|
||
TMP_FILE="/tmp/github_test_$$"
|
||
START_TIME=$(date +%s.%N)
|
||
if curl -s -o "$TMP_FILE" "https://raw.githubusercontent.com/github/gitignore/main/README.md" 2>/dev/null; then
|
||
END_TIME=$(date +%s.%N)
|
||
DURATION=$(echo "$END_TIME - $START_TIME" | bc)
|
||
FILE_SIZE=$(wc -c < "$TMP_FILE")
|
||
SPEED=$(echo "scale=2; $FILE_SIZE / $DURATION / 1024" | bc)
|
||
print_success "下载速度: ${SPEED} KB/s"
|
||
rm -f "$TMP_FILE"
|
||
else
|
||
print_error "下载测试失败"
|
||
fi
|
||
}
|
||
|
||
# 6. Git 克隆测试
|
||
check_git_clone() {
|
||
print_header "6. Git 克隆速度测试"
|
||
|
||
print_info "测试克隆小型仓库..."
|
||
TMP_DIR="/tmp/git_test_$$"
|
||
|
||
START_TIME=$(date +%s)
|
||
if timeout 30 git clone --depth 1 https://github.com/github/gitignore.git "$TMP_DIR" 2>&1 | tail -5; then
|
||
END_TIME=$(date +%s)
|
||
DURATION=$((END_TIME - START_TIME))
|
||
print_success "克隆完成,耗时: ${DURATION}秒"
|
||
rm -rf "$TMP_DIR"
|
||
else
|
||
print_error "克隆超时或失败"
|
||
rm -rf "$TMP_DIR" 2>/dev/null || true
|
||
fi
|
||
}
|
||
|
||
# 7. 当前网络出口检查
|
||
check_network_exit() {
|
||
print_header "7. 网络出口检查"
|
||
|
||
print_info "检测当前出口 IP..."
|
||
EXIT_IP=$(curl -s --max-time 10 https://api.ipify.org 2>/dev/null || echo "检测失败")
|
||
if [ "$EXIT_IP" != "检测失败" ]; then
|
||
print_success "出口 IP: $EXIT_IP"
|
||
|
||
# 获取位置信息
|
||
LOCATION_DATA=$(curl -s --max-time 10 "https://ipapi.co/$EXIT_IP/json/" 2>/dev/null)
|
||
if [ -n "$LOCATION_DATA" ]; then
|
||
COUNTRY=$(echo "$LOCATION_DATA" | python3 -c "import sys, json; print(json.load(sys.stdin).get('country_name', '未知'))" 2>/dev/null || echo "未知")
|
||
CITY=$(echo "$LOCATION_DATA" | python3 -c "import sys, json; print(json.load(sys.stdin).get('city', '未知'))" 2>/dev/null || echo "未知")
|
||
print_info " 位置: $COUNTRY, $CITY"
|
||
fi
|
||
else
|
||
print_error "无法检测出口 IP"
|
||
fi
|
||
}
|
||
|
||
# 主函数
|
||
main() {
|
||
echo ""
|
||
echo "╔════════════════════════════════════════════════════╗"
|
||
echo "║ GitHub 访问问题诊断工具 ║"
|
||
echo "╚════════════════════════════════════════════════════╝"
|
||
|
||
check_wireguard
|
||
check_hosts_file
|
||
check_clash
|
||
check_dns_resolution
|
||
check_connection_speed
|
||
check_git_clone
|
||
check_network_exit
|
||
|
||
print_header "诊断总结"
|
||
echo "诊断完成!请查看上述结果。"
|
||
echo ""
|
||
echo "常见问题和解决方案:"
|
||
echo " 1. 如果 ClashX Meta 配置为空,需要重新配置代理"
|
||
echo " 2. 如果 /etc/hosts 有 GitHub 条目,建议删除"
|
||
echo " 3. 如果连接很慢,可能需要优化路由或 DNS"
|
||
echo ""
|
||
}
|
||
|
||
main "$@" |