fix(deploy): 加速 GeoIP 数据库自动下载
This commit is contained in:
@@ -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
|
||||
|
||||
+23
-10
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user