feat(deploy): add redis compose uninstall; require Redis in install wizard

Step 2 blocks until Redis connects; uninstall-redis-compose.sh removes legacy
nexus-prod-redis container without touching host/1Panel Redis.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nexus Deploy
2026-06-06 02:51:52 +08:00
parent 536d520744
commit e42dc77127
6 changed files with 169 additions and 12 deletions
+8 -1
View File
@@ -32,7 +32,14 @@ curl -fsSL "http://66.154.115.8:3000/admin/Nexus/raw/branch/main/deploy/quick-in
Docker 栈仅含 **MySQL + Nexus**。Redis 请在宿主机或 1Panel 应用商店单独安装,监听 `127.0.0.1:6379`(或改 `docker/.env.prod``NEXUS_REDIS_URL`)。 Docker 栈仅含 **MySQL + Nexus**。Redis 请在宿主机或 1Panel 应用商店单独安装,监听 `127.0.0.1:6379`(或改 `docker/.env.prod``NEXUS_REDIS_URL`)。
安装向导步骤 3Docker 部署时 Redis 主机填 **`host.docker.internal`**,端口 `6379` 安装向导步骤 2**必须先连通 Redis** 才能进入步骤 3。步骤 3 Redis 主机填 **`host.docker.internal`**,端口 `6379`
卸载旧 Compose Redis 容器:
```bash
bash /opt/nexus/deploy/uninstall-redis-compose.sh
bash /opt/nexus/deploy/uninstall-redis-compose.sh --purge-volume # 连数据卷一并删除
```
## 1Panel 反代(必须在面板 UI 操作) ## 1Panel 反代(必须在面板 UI 操作)
+4 -2
View File
@@ -123,7 +123,8 @@ install_root_commands() {
chmod +x "${NEXUS_ROOT}/deploy/nx" \ chmod +x "${NEXUS_ROOT}/deploy/nx" \
"${NEXUS_ROOT}/deploy/install-nexus-fresh.sh" \ "${NEXUS_ROOT}/deploy/install-nexus-fresh.sh" \
"${NEXUS_ROOT}/deploy/nexus-1panel.sh" \ "${NEXUS_ROOT}/deploy/nexus-1panel.sh" \
"${NEXUS_ROOT}/deploy/sync-install-wizard-to-container.sh" 2>/dev/null || true "${NEXUS_ROOT}/deploy/sync-install-wizard-to-container.sh" \
"${NEXUS_ROOT}/deploy/uninstall-redis-compose.sh" 2>/dev/null || true
ln -sf "${NEXUS_ROOT}/deploy/nx" /usr/local/bin/nx ln -sf "${NEXUS_ROOT}/deploy/nx" /usr/local/bin/nx
ln -sf "${NEXUS_ROOT}/deploy/nexus-1panel.sh" /usr/local/bin/nexus-1panel ln -sf "${NEXUS_ROOT}/deploy/nexus-1panel.sh" /usr/local/bin/nexus-1panel
ln -sf "${NEXUS_ROOT}/deploy/install-nexus-fresh.sh" /usr/local/bin/nexus-fresh ln -sf "${NEXUS_ROOT}/deploy/install-nexus-fresh.sh" /usr/local/bin/nexus-fresh
@@ -132,7 +133,8 @@ install_root_commands() {
info "已注册全局命令(root 直接输入即可):" info "已注册全局命令(root 直接输入即可):"
info " nexus-1panel-docker — 重装服务器(1Panel + Docker + Nexus" info " nexus-1panel-docker — 重装服务器(1Panel + Docker + Nexus"
info " nexus-install — 仅 Nexus Dockercurl 入口)" info " nexus-install — 仅 Nexus Dockercurl 入口)"
info " nx — 主菜单 / 上帝菜单" info " nexus-1panel — 底层 install/upgrade 脚本"
info " nx — 主菜单 / nx god 上帝菜单"
info " nexus-fresh — 全新安装脚本" info " nexus-fresh — 全新安装脚本"
} }
+116
View File
@@ -0,0 +1,116 @@
#!/usr/bin/env bash
# =============================================================================
# 卸载 Nexus 旧版 Compose 内置 Redis 容器
#
# 适用:已从 docker-compose.prod.yml 移除 redis 服务,改用宿主机/1Panel 自建 Redis。
# 不会卸载 apt/1Panel 安装的 Redis,仅删除 Docker 容器与(可选)数据卷。
#
# bash deploy/uninstall-redis-compose.sh
# bash deploy/uninstall-redis-compose.sh --purge-volume # 同时删 redis-data 卷
# =============================================================================
set -euo pipefail
NEXUS_ROOT="${NEXUS_ROOT:-/opt/nexus}"
COMPOSE_FILE="${COMPOSE_FILE:-docker/docker-compose.prod.yml}"
PURGE_VOLUME=false
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
usage() {
cat <<EOF
卸载 Nexus Compose 遗留 Redis 容器
bash deploy/uninstall-redis-compose.sh [--purge-volume]
选项:
--purge-volume 删除 nexus-prod_redis-data 数据卷(不可恢复)
-h, --help 显示帮助
说明:
- 不卸载宿主机 redis-server / 1Panel 应用商店 Redis
- 卸载后请在宿主机安装 Redis,安装向导步骤 2 须能 ping 通
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help) usage; exit 0 ;;
--purge-volume) PURGE_VOLUME=true; shift ;;
*) error "未知参数: $1"; usage; exit 1 ;;
esac
done
if [[ "$(id -u)" -ne 0 ]]; then
error "请使用 root 执行"
exit 1
fi
removed=0
stop_rm_container() {
local name="$1"
if docker ps -a --format '{{.Names}}' | grep -qx "$name"; then
info "停止并删除容器: $name"
docker stop "$name" >/dev/null 2>&1 || true
docker rm "$name" >/dev/null 2>&1 || true
removed=$((removed + 1))
fi
}
# 常见 Compose 命名
for pattern in nexus-prod-redis-1 nexus-prod-redis nexus-redis-1; do
stop_rm_container "$pattern"
done
# 名称含 nexus 且含 redis 的容器
while IFS= read -r c; do
[[ -z "$c" ]] && continue
stop_rm_container "$c"
done < <(docker ps -a --format '{{.Names}}' | grep -iE 'nexus.*redis|redis.*nexus' || true)
# 若旧 compose 仍定义 redis 服务
if [[ -f "${NEXUS_ROOT}/${COMPOSE_FILE}" ]]; then
if grep -q '^ redis:' "${NEXUS_ROOT}/${COMPOSE_FILE}" 2>/dev/null; then
warn "compose 仍含 redis 服务,尝试 compose rm..."
local_env=()
[[ -f "${NEXUS_ROOT}/docker/.env.prod" ]] && local_env+=(--env-file "${NEXUS_ROOT}/docker/.env.prod")
prof="${NEXUS_ROOT}/docker/.host-profile"
if [[ -f "$prof" ]]; then
p="$(tr -d '\r\n' <"$prof")"
[[ -f "${NEXUS_ROOT}/docker/profiles/${p}.env" ]] && local_env+=(--env-file "${NEXUS_ROOT}/docker/profiles/${p}.env")
fi
(cd "$NEXUS_ROOT" && docker compose -f "$COMPOSE_FILE" "${local_env[@]}" stop redis 2>/dev/null || true)
(cd "$NEXUS_ROOT" && docker compose -f "$COMPOSE_FILE" "${local_env[@]}" rm -f redis 2>/dev/null || true)
removed=$((removed + 1))
fi
fi
if [[ "$PURGE_VOLUME" == true ]]; then
while IFS= read -r vol; do
[[ -z "$vol" ]] && continue
info "删除数据卷: $vol"
docker volume rm "$vol" 2>/dev/null || warn "无法删除卷 $vol(可能被占用)"
done < <(docker volume ls -q | grep -iE 'nexus.*redis|redis.*nexus' || true)
fi
echo ""
if [[ "$removed" -gt 0 ]]; then
info "Compose Redis 容器已卸载。"
else
info "未发现 Nexus Compose Redis 容器(可能已删除)。"
fi
echo ""
info "下一步:在宿主机或 1Panel 安装 Redis,确认监听 6379"
echo " apt install -y redis-server && systemctl enable --now redis-server"
echo " redis-cli ping # 期望 PONG"
echo ""
info "Docker 内 Nexus 连接宿主机 Redis:安装向导 / .env 使用 host.docker.internal:6379"
@@ -0,0 +1,26 @@
# 2026-06-05 — Redis 强制连通 + Compose Redis 卸载脚本
## 摘要
- 恢复安装向导步骤 2:**Redis 未连接则不可进入步骤 3**
- 新增 `deploy/uninstall-redis-compose.sh` 卸载遗留 `nexus-prod-redis` 容器
## 动机
用户自行安装 Redis,但环境检测必须验证连通;旧 Compose Redis 容器需单独卸载。
## 涉及文件
- `server/api/install.py` — Redis `pass: redis_ok`
- `web/app/install.html` — 步骤 2「下一步」在 `!envAllPass` 时禁用
- `deploy/uninstall-redis-compose.sh` — 新脚本
- `deploy/README-1panel.md` — 文档
## 服务器操作
```bash
cd /opt/nexus && git pull
bash deploy/uninstall-redis-compose.sh
apt install -y redis-server && systemctl enable --now redis-server
bash deploy/sync-install-wizard-to-container.sh
```
+11 -8
View File
@@ -99,7 +99,7 @@ def _build_redis_url(req: InitDbRequest) -> str:
def _resolve_redis_probe() -> tuple[str, int, str | None]: def _resolve_redis_probe() -> tuple[str, int, str | None]:
"""Redis target for install wizard health check (Docker uses redis:6379, not host loopback).""" """Redis target for install wizard (Docker: host.docker.internal → 宿主机自建 Redis)."""
url = os.environ.get("NEXUS_REDIS_URL", "").strip() url = os.environ.get("NEXUS_REDIS_URL", "").strip()
if url: if url:
parsed = urlparse(url) parsed = urlparse(url)
@@ -442,9 +442,9 @@ async def env_check():
"pass": False, "pass": False,
}) })
# Redis — 用户自行安装(1Panel/宿主机),不阻塞安装向导 # Redis — 须先安装并连通(宿主机/1Panel);Docker 默认 host.docker.internal:6379
redis_ok = False redis_ok = False
redis_msg = "检测" redis_msg = "连接"
rh, rp, rpass = _resolve_redis_probe() rh, rp, rpass = _resolve_redis_probe()
redis_label = f"{rh}:{rp}" redis_label = f"{rh}:{rp}"
try: try:
@@ -454,20 +454,23 @@ async def env_check():
host=rh, host=rh,
port=rp, port=rp,
password=rpass or None, password=rpass or None,
socket_timeout=0.5, socket_timeout=2.0,
) )
r.ping() r.ping()
redis_ok = True redis_ok = True
redis_msg = f"✓ 已连接 {redis_label}" redis_msg = f"✓ 已连接 {redis_label}"
except Exception as e: except Exception as e:
redis_msg = f"未连接 {redis_label}(可继续,步骤3配置或稍后安装 Redis)— {e}" redis_msg = (
f"连接失败: {e}(请先在宿主机/1Panel 安装 Redis"
f"Docker 部署须监听宿主机 6379 且 NEXUS_REDIS_URL 指向 {redis_label}"
)
except ImportError: except ImportError:
redis_msg = "redis 库未安装(可继续)" redis_msg = "redis 库未安装"
checks.append({ checks.append({
"name": "Redis", "name": "Redis",
"required": "自行安装(步骤3配置)", "required": "已连接",
"current": redis_msg, "current": redis_msg,
"pass": True, "pass": redis_ok,
}) })
# MySQL database — user configures in step 3 # MySQL database — user configures in step 3
+4 -1
View File
@@ -128,7 +128,10 @@
</div> </div>
<div x-show="!envLoading" class="flex gap-3 mt-4"> <div x-show="!envLoading" class="flex gap-3 mt-4">
<button @click="step = 3" class="bg-blue-500 hover:bg-blue-600 text-white px-5 py-2.5 rounded-lg font-semibold transition"> <button @click="step = 3"
:disabled="!envAllPass"
:class="envAllPass ? 'bg-blue-500 hover:bg-blue-600' : 'bg-slate-300 cursor-not-allowed'"
class="text-white px-5 py-2.5 rounded-lg font-semibold transition">
下一步:数据库配置 → 下一步:数据库配置 →
</button> </button>
<button @click="checkEnv()" class="bg-slate-200 hover:bg-slate-300 text-slate-700 px-5 py-2.5 rounded-lg font-semibold transition"> <button @click="checkEnv()" class="bg-slate-200 hover:bg-slate-300 text-slate-700 px-5 py-2.5 rounded-lg font-semibold transition">