Files
Distributed-Prometheus/edge-agent/deploy.sh
root c4825c2d27 feat: 引入 vmauth 鉴权与严格多租户
- 对外端口统一为 18428(vmauth 入口),VM 不再直接暴露宿主机端口
- 边缘 vmagent 与中央 Prometheus remote_write 增加 basic auth
- 支持 tenants.csv 驱动的 per-tenant 写入/查询隔离,并提供管理员跨租户只读查询
- 更新 Grafana provisioning 与部署/文档

Made-with: Cursor
2026-04-22 11:41:13 +00:00

49 lines
2.1 KiB
Bash
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.
#!/bin/bash
# 边缘节点部署vmagent + 内存/磁盘缓存
# 用法: ./deploy.sh [--local] --local = 本机同机(中央与边缘同机)
#
# targets.csv部署时自动从 targets.csv 生成 target-onvif.json、target-ping.json
# 修改 targets.csv 后需手动执行 config/update-configs.sh或重新 deploy
# vmagent 每 5 分钟自动重载 JSON无需重启。
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
# --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=18428' >> .env
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; }
# 配置文件
[ -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 config/vmagent/vmagent-scrape.yml.template ] && { echo "❌ 缺少 config/vmagent/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 ""
echo "✅ 边缘已启动 http://localhost:9092 (Grafana 数据源选 VictoriaMetrics)"