From 239d805ea3253d0bb4ae7473787e6042a3c26f42 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Fri, 6 Nov 2026 18:23:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20=E5=8A=A0=E9=80=9F=20GeoIP=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E8=87=AA=E5=8A=A8=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/.env.prod.example | 2 +- deploy/scripts/deploy.sh | 33 +++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/deploy/.env.prod.example b/deploy/.env.prod.example index 3dd2780..4421f63 100644 --- a/deploy/.env.prod.example +++ b/deploy/.env.prod.example @@ -33,7 +33,7 @@ CORS_ALLOW_ORIGINS=https://你的域名 # 可选:离线 GeoIP City 数据库(挂载自 deploy/geoip/) # GEOIP_DB_PATH=/app/geoip/GeoLite2-City.mmdb # GEOIP_DB_FILE=./deploy/geoip/GeoLite2-City.mmdb -# GEOIP_DB_URL=https://raw.githubusercontent.com/P3TERX/GeoLite.mmdb/download/GeoLite2-City.mmdb +# GEOIP_DB_URL=https://gh-proxy.com/https://raw.githubusercontent.com/P3TERX/GeoLite.mmdb/download/GeoLite2-City.mmdb # ========== MinIO 对象存储 ========== STORAGE_ACCESS_KEY=kefu_minio diff --git a/deploy/scripts/deploy.sh b/deploy/scripts/deploy.sh index 785fff0..7c4d579 100755 --- a/deploy/scripts/deploy.sh +++ b/deploy/scripts/deploy.sh @@ -99,7 +99,7 @@ check_http_port() { ensure_geoip() { local db_file="${GEOIP_DB_FILE:-deploy/geoip/GeoLite2-City.mmdb}" - local db_url="${GEOIP_DB_URL:-https://raw.githubusercontent.com/P3TERX/GeoLite.mmdb/download/GeoLite2-City.mmdb}" + local override_url="${GEOIP_DB_URL:-}" local refresh=0 if [[ ! -s "$db_file" ]] || [[ "$(wc -c < "$db_file" | tr -d ' ')" -lt 1000000 ]] \ @@ -113,17 +113,30 @@ ensure_geoip() { need_cmd curl mkdir -p "$(dirname "$db_file")" local tmp="${db_file}.download.$$" - log "下载 GeoIP 城市库: $db_url" - rm -f "$tmp" - if curl -fL --retry 3 --connect-timeout 15 --max-time 300 -o "$tmp" "$db_url" \ - && [[ "$(wc -c < "$tmp" | tr -d ' ')" -gt 1000000 ]] \ - && tail -c 131072 "$tmp" | grep -aq 'MaxMind.com'; then - mv "$tmp" "$db_file" - log "GeoIP 数据库已更新: $db_file" + local -a urls + if [[ -n "$override_url" ]]; then + urls=("$override_url") else - rm -f "$tmp" - warn "GeoIP 自动下载失败,服务将降级为 CDN 国家头/未知地区" + urls=( + "https://gh-proxy.com/https://raw.githubusercontent.com/P3TERX/GeoLite.mmdb/download/GeoLite2-City.mmdb" + "https://raw.githubusercontent.com/P3TERX/GeoLite.mmdb/download/GeoLite2-City.mmdb" + ) fi + + local db_url + for db_url in "${urls[@]}"; do + log "下载 GeoIP 城市库: $db_url" + rm -f "$tmp" + if curl -fL --retry 2 --connect-timeout 15 --max-time 180 -o "$tmp" "$db_url" \ + && [[ "$(wc -c < "$tmp" | tr -d ' ')" -gt 1000000 ]] \ + && tail -c 131072 "$tmp" | grep -aq 'MaxMind.com'; then + mv "$tmp" "$db_file" + log "GeoIP 数据库已更新: $db_file" + return 0 + fi + done + rm -f "$tmp" + warn "GeoIP 自动下载失败,服务将降级为 CDN 国家头/未知地区" } ensure_env() {