refactor: 边缘节点与配置精简

- 边缘: Prometheus 改为 vmagent,统一 docker-compose.yml,内存+磁盘缓存
- 边缘脚本: 合并为 deploy.sh [--local],删除 run-edge-local、quick-setup、run-edge-with-cache
- 配置: 合并为 update-configs.sh,统一 targets.csv,生成 target-onvif/target-ping/target-topology
- 删除 topology-editor、旧格式 devices.csv/ping-targets.csv、setup-remote-write、test-connection
- 文档: 更新 EDGE_CACHE、TIANDITU(瓦片改 4090 直连 tile-cache)

Made-with: Cursor
This commit is contained in:
User
2026-02-28 19:44:46 -05:00
parent 72a5bf30b4
commit 650e5145f1
35 changed files with 319 additions and 2774 deletions

View File

@@ -1,156 +1,44 @@
#!/bin/bash
# 分布式Prometheus边缘代理部署脚本
# 适用于Linux系统 (玩客云等设备)
# 边缘节点部署vmagent + 内存/磁盘缓存
# 用法: ./deploy.sh [--local] --local = 本机同机(中央与边缘同机)
set -e
echo "=== 分布式Prometheus边缘代理部署脚本 ==="
echo ""
cd "$(dirname "${BASH_SOURCE[0]}")"
# 检查Docker是否安装
if ! command -v docker &> /dev/null; then
echo "❌ Docker未安装请先安装Docker"
exit 1
# --local: 中央与边缘同机,使用 host.docker.internal
if [ "$1" = "--local" ]; then
[ ! -f .env ] && [ -f env.example ] && cp env.example .env
sed -i 's/^CENTRAL_SERVER_HOST=.*/CENTRAL_SERVER_HOST=host.docker.internal/' .env 2>/dev/null || \
echo 'CENTRAL_SERVER_HOST=host.docker.internal' >> .env
grep -q '^CENTRAL_SERVER_PORT=' .env || echo 'CENTRAL_SERVER_PORT=8428' >> .env
fi
# 检查Docker Compose (优先检查V2然后检查V1)
DOCKER_COMPOSE_CMD=""
if docker compose version &> /dev/null; then
DOCKER_COMPOSE_CMD="docker compose"
echo "✅ 检测到 Docker Compose V2"
elif command -v docker-compose &> /dev/null; then
DOCKER_COMPOSE_CMD="docker-compose"
echo "✅ 检测到 Docker Compose V1"
else
echo "❌ Docker Compose未安装请先安装Docker Compose"
exit 1
fi
# Docker 环境
DOCKER_CMD="docker compose"
docker compose version &>/dev/null || DOCKER_CMD="docker-compose"
command -v docker &>/dev/null || { echo "❌ 需要 Docker"; exit 1; }
$DOCKER_CMD version &>/dev/null || { echo "❌ 需要 Docker Compose"; exit 1; }
command -v jq &>/dev/null || { echo "❌ 需要 jq"; exit 1; }
echo "✅ Docker环境检查通过"
# 配置文件
[ -f config/targets.csv ] && (cd config && ./update-configs.sh) || true
[ ! -f config/target-onvif.json ] && echo '[]' > config/target-onvif.json
[ ! -f config/target-ping.json ] && echo '[]' > config/target-ping.json
[ ! -f prometheus-edge/vmagent-scrape.yml.template ] && { echo "❌ 缺少 vmagent-scrape.yml.template"; exit 1; }
# .env
[ ! -f .env ] && cp env.example .env
# targets.csv无则建最小示例
[ ! -f config/targets.csv ] && \
printf '%s\n' "type,ip,name,role,parent,uplink_type,network,device_type,model,location,username,password,onvif_port,lat,lon" \
"ping,8.8.8.8,google_dns,dns,,,external,,,,,,,,," \
"ping,1.1.1.1,cloudflare_dns,dns,,,external,,,,,,,,," > config/targets.csv
# 启动
$DOCKER_CMD down 2>/dev/null || true
$DOCKER_CMD up -d
sleep 5
$DOCKER_CMD ps
echo ""
# 检查jq是否安装
if ! command -v jq &> /dev/null; then
echo "❌ jq未安装请先安装jq:"
echo " Ubuntu/Debian: sudo apt-get install jq"
echo " CentOS/RHEL: sudo yum install jq"
echo " Alpine: apk add jq"
exit 1
fi
# 检查并生成配置文件
echo "🔄 检查并生成配置文件..."
if [ -f "config/devices.csv" ]; then
echo "📱 从CSV生成ONVIF设备配置..."
cd config
chmod +x *.sh
./update-configs.sh
cd ..
else
echo "⚠️ config/devices.csv 不存在使用默认JSON配置"
fi
if [ ! -f "config/onvif-targets.json" ]; then
echo "❌ 配置文件 config/onvif-targets.json 不存在"
exit 1
fi
if [ ! -f "config/ping-targets.json" ]; then
echo "❌ 配置文件 config/ping-targets.json 不存在"
exit 1
fi
if [ ! -f "prometheus-edge/prometheus.yml" ]; then
echo "❌ 配置文件 prometheus-edge/prometheus.yml 不存在"
exit 1
fi
echo "✅ 配置文件检查通过"
echo ""
# 创建环境变量文件
if [ ! -f ".env" ]; then
if [ -f "env.example" ]; then
cp env.example .env
echo "📝 已创建 .env 文件,请编辑其中的配置"
echo " 特别是 CENTRAL_SERVER_HOST 和 CENTRAL_SERVER_PORT"
echo ""
read -p "按回车键继续,或 Ctrl+C 取消..."
else
echo "❌ env.example 文件不存在"
exit 1
fi
fi
# 从 .env 生成 prometheus.yml使 remote_write 指向中央服务器)
if [ -f ".env" ]; then
set -a
source .env
set +a
CENTRAL_SERVER_HOST=${CENTRAL_SERVER_HOST:-192.168.1.10}
CENTRAL_SERVER_PORT=${CENTRAL_SERVER_PORT:-8428}
if [ -f "prometheus-edge/prometheus.yml.template" ]; then
echo "📝 根据 .env 生成 prometheus.yml (中央: ${CENTRAL_SERVER_HOST}:${CENTRAL_SERVER_PORT})..."
export CENTRAL_SERVER_HOST CENTRAL_SERVER_PORT
envsubst '${CENTRAL_SERVER_HOST} ${CENTRAL_SERVER_PORT}' < prometheus-edge/prometheus.yml.template > prometheus-edge/prometheus.yml
echo "✅ prometheus.yml 已生成"
fi
fi
# 创建数据目录
mkdir -p prometheus-edge/data
echo "✅ 数据目录创建完成"
echo ""
# 停止现有服务
echo "🛑 停止现有服务..."
$DOCKER_COMPOSE_CMD down 2>/dev/null || true
# 拉取最新镜像
echo "📥 拉取Docker镜像..."
if ! $DOCKER_COMPOSE_CMD pull; then
echo ""
echo "⚠️ 镜像拉取失败,尝试继续启动(如果本地已有镜像)..."
echo ""
fi
# 启动服务
echo "🚀 启动服务..."
$DOCKER_COMPOSE_CMD up -d
# 等待服务启动
echo "⏳ 等待服务启动..."
sleep 10
# 检查服务状态
echo ""
echo "📊 服务状态检查:"
$DOCKER_COMPOSE_CMD ps
echo ""
echo "📋 服务日志:"
$DOCKER_COMPOSE_CMD logs --tail=20
echo ""
echo "✅ 部署完成!"
echo ""
echo "🔗 访问地址:"
echo " - Prometheus UI: http://localhost:9092"
echo " - 目标状态: http://localhost:9092/targets"
echo ""
echo "📝 管理命令:"
echo " - 查看日志: $DOCKER_COMPOSE_CMD logs -f"
echo " - 重启服务: $DOCKER_COMPOSE_CMD restart"
echo " - 停止服务: $DOCKER_COMPOSE_CMD down"
echo ""
echo "🔄 配置更新:"
echo " - 编辑CSV: nano config/devices.csv"
echo " - 生成JSON: cd config && ./update-configs.sh"
echo " - 热重载: 等待5分钟自动重载或重启prometheus-edge"
echo ""
echo "⚠️ 请确保:"
echo " 1. 已正确配置 .env 文件中的服务器地址"
echo " 2. 已更新 config/devices.csv 中的设备信息"
echo " 3. 网络连接正常可以访问ONVIF设备"
echo "✅ 边缘已启动 http://localhost:9092 (Grafana 数据源选 VictoriaMetrics)"