From d7c2a9cfad7eecb263d430cc8b33fc5bbe56bf0c Mon Sep 17 00:00:00 2001 From: admin <362324317@qq.com> Date: Mon, 18 May 2026 06:03:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=99=BA=E8=83=BD=E9=83=A8=E7=BD=B2=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=EF=BC=9A=E8=87=AA=E5=8A=A8=E6=A3=80=E6=B5=8BRedis?= =?UTF-8?q?=EF=BC=8C=E6=9C=89=E5=88=99=E8=B7=B3=E8=BF=87=E6=97=A0=E5=88=99?= =?UTF-8?q?=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source_clean/deploy.sh | 38 +++++++++++++++++++++++++++++++++ source_clean/docker-compose.yml | 14 ++++++------ 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100755 source_clean/deploy.sh diff --git a/source_clean/deploy.sh b/source_clean/deploy.sh new file mode 100755 index 0000000..66d9a80 --- /dev/null +++ b/source_clean/deploy.sh @@ -0,0 +1,38 @@ +#!/bin/bash +set -e + +echo "🔍 检测 Redis..." + +# 查找当前 docker-compose 网络内或全局已运行的 Redis 容器 +EXISTING_REDIS=$(docker ps --format '{{.Names}}' | grep -i redis | head -1) + +if [ -n "$EXISTING_REDIS" ]; then + # 检查它是否已在 cloudsearch-net 网络中 + if docker network inspect cloudsearch-net --format '{{range .Containers}}{{.Name}} {{end}}' 2>/dev/null | grep -qw "$EXISTING_REDIS"; then + echo "✅ 已有 Redis: $EXISTING_REDIS (已加入 cloudsearch-net),跳过创建" + else + echo "✅ 已有 Redis: $EXISTING_REDIS,正在加入网络..." + docker network connect cloudsearch-net "$EXISTING_REDIS" 2>/dev/null || true + echo " ✅ 已加入 cloudsearch-net" + fi + REDIS_HOST="$EXISTING_REDIS" + PROFILE="" +else + echo "📦 未检测到 Redis,将自动创建..." + REDIS_HOST="CloudSearch_Redis" + PROFILE="--profile full" +fi + +echo "REDIS_URL=redis://${REDIS_HOST}:6379" > .env +echo "CORS_ORIGIN=https://zy.hk.timxx.cn" >> .env +echo "JWT_SECRET=cloudsearch-jwt-secret-2024" >> .env +echo "ADMIN_PASSWORD=0nL5kLhMIJ1121PYmQb25A" >> .env +echo "LOG_LEVEL=info" >> .env + +echo "" +echo "🚀 启动服务..." +docker compose $PROFILE up -d + +echo "" +echo "✅ 部署完成" +docker compose ps diff --git a/source_clean/docker-compose.yml b/source_clean/docker-compose.yml index 14811f6..929b222 100644 --- a/source_clean/docker-compose.yml +++ b/source_clean/docker-compose.yml @@ -6,14 +6,14 @@ services: restart: unless-stopped ports: ["9527:9527"] environment: - CORS_ORIGIN: "https://zy.hk.timxx.cn" - JWT_SECRET: "cloudsearch-jwt-secret-2024" - ADMIN_PASSWORD: "0nL5kLhMIJ1121PYmQb25A" - LOG_LEVEL: info - REDIS_URL: redis://redis:6379 + REDIS_URL: ${REDIS_URL} PANSOU_URL: http://pansou:8888 + CORS_ORIGIN: ${CORS_ORIGIN:-https://zy.hk.timxx.cn} + JWT_SECRET: ${JWT_SECRET:-cloudsearch-jwt-secret-2024} + ADMIN_PASSWORD: ${ADMIN_PASSWORD:-0nL5kLhMIJ1121PYmQb25A} + LOG_LEVEL: ${LOG_LEVEL:-info} volumes: ["cloudsearch-data:/app/data"] - depends_on: [redis, pansou] + depends_on: [pansou] networks: [cloudsearch-net] pansou: @@ -23,6 +23,7 @@ services: networks: cloudsearch-net: { aliases: [pansou] } + # Redis — 仅当系统没有现成 Redis 时才启动 redis: image: redis:7-alpine container_name: CloudSearch_Redis @@ -30,6 +31,7 @@ services: command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru volumes: ["redis-data:/data"] networks: [cloudsearch-net] + profiles: [full] volumes: cloudsearch-data: