feat(deploy): add 1Panel-style fresh install script for empty DB

install-nexus-fresh.sh with phased checks, install wizard URL, and nx god
menu hints; wired into nx install-fresh and install menu option 6.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nexus Deploy
2026-06-05 23:44:38 +08:00
parent 8ddcf2ad0d
commit 00f44032ff
4 changed files with 328 additions and 5 deletions
+13 -2
View File
@@ -1,6 +1,16 @@
# 1Panel + Docker 一键部署
## NX 菜单(推荐
## 全新安装(1Panel 风格,推荐新机
```bash
curl -sSL "http://66.154.115.8:3000/admin/Nexus/raw/branch/main/deploy/install-nexus-fresh.sh" -o /tmp/install-nexus-fresh.sh
sudo bash /tmp/install-nexus-fresh.sh
# 4核16G: sudo bash /tmp/install-nexus-fresh.sh --profile 4c16g
```
安装完成后浏览器打开 `https://api.synaglobal.vip/app/install.html` 完成向导。
## NX 菜单(日常运维)
```bash
bash deploy/nx
@@ -8,7 +18,8 @@ bash deploy/nx
```
- **主菜单** → 安装向导 / **上帝菜单**(重启 Python、升级、日志、备份)
- 非交互一键: `bash deploy/nx install-auto`
- 全新安装: `bash deploy/nx install-fresh`
- 迁机/已有密钥: `bash deploy/nx install-auto`
**先确保** `deploy/nexus-1panel.secrets.sh` 存在(本机已从 `SECRETS.md` 配好)。
+266
View File
@@ -0,0 +1,266 @@
#!/usr/bin/env bash
# =============================================================================
# Nexus 6.0 — 全新安装脚本(1Panel + Docker Compose
#
# 适用:新机已装 1Panel / Docker,空库,走 /app/install.html 安装向导
# 风格参考 1Panel quick_start.sh:分阶段检查 + 结束输出访问地址
#
# 用法:
# curl -sSL "http://66.154.115.8:3000/admin/Nexus/raw/branch/main/deploy/install-nexus-fresh.sh" -o /tmp/install-nexus-fresh.sh
# sudo bash /tmp/install-nexus-fresh.sh
#
# sudo bash /tmp/install-nexus-fresh.sh --profile 4c16g
# sudo bash /tmp/install-nexus-fresh.sh --domain nexus.example.com
#
# 凭据(任选其一,无需 export):
# - /root/.nexus-deploy.env
# - /root/.nexus-secrets/nexus.env
# - 仓库内 deploy/nexus-1panel.secrets.sh(私人仓库可 git add -f 后 push
# =============================================================================
set -euo pipefail
# ── 默认配置(与 SECRETS.md / nexus-1panel 一致)──
NEXUS_ROOT="${NEXUS_ROOT:-/opt/nexus}"
NEXUS_GITEA_HOST="${NEXUS_GITEA_HOST:-66.154.115.8:3000}"
NEXUS_GITEA_REPO="${NEXUS_GITEA_REPO:-admin/Nexus.git}"
NEXUS_DOMAIN="${NEXUS_DOMAIN:-api.synaglobal.vip}"
NEXUS_PROFILE="${NEXUS_PROFILE:-2c8g}"
NEXUS_GIT_BRANCH="${NEXUS_GIT_BRANCH:-main}"
NEXUS_RAW_BASE="${NEXUS_RAW_BASE:-http://66.154.115.8:3000/admin/Nexus/raw/branch/main}"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BLUE='\033[0;34m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
step() { echo -e "${CYAN}[STEP]${NC} $*"; }
usage() {
cat <<EOF
Nexus 6.0 全新安装(1Panel + Docker
sudo bash install-nexus-fresh.sh [选项]
选项:
--domain NAME 公网域名(默认: ${NEXUS_DOMAIN}
--profile NAME 资源档位 1c4g|2c8g|4c16g(默认: 2c8g
--root PATH 安装目录(默认: /opt/nexus
--skip-1panel-check 不检测 1Panel 是否已安装
-h, --help 显示帮助
安装后请用浏览器打开: https://域名/app/install.html
日常运维: nx 或 bash ${NEXUS_ROOT}/deploy/nx god
EOF
}
SKIP_1PANEL_CHECK=false
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help) usage; exit 0 ;;
--domain) NEXUS_DOMAIN="$2"; shift 2 ;;
--profile) NEXUS_PROFILE="$2"; shift 2 ;;
--root) NEXUS_ROOT="$2"; shift 2 ;;
--skip-1panel-check) SKIP_1PANEL_CHECK=true; shift ;;
*) error "未知参数: $1"; usage; exit 1 ;;
esac
done
banner() {
echo ""
echo -e "${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}${NC} Nexus 6.0 — 全新安装(1Panel + Docker Compose ${BLUE}${NC}"
echo -e "${BLUE}${NC} 域名: ${NEXUS_DOMAIN} ${BLUE}${NC}"
echo -e "${BLUE}${NC} 档位: ${NEXUS_PROFILE} 目录: ${NEXUS_ROOT} ${BLUE}${NC}"
echo -e "${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}"
echo ""
}
load_credentials() {
step "加载凭据..."
local f
for f in /root/.nexus-deploy.env /root/.nexus-secrets/nexus.env; do
if [[ -f "$f" ]]; then
# shellcheck disable=SC1090
set -a
source "$f"
set +a
info "已加载 $f"
fi
done
if [[ -f "${NEXUS_ROOT}/deploy/nexus-1panel.secrets.sh" ]]; then
# shellcheck disable=SC1090
set -a
source "${NEXUS_ROOT}/deploy/nexus-1panel.secrets.sh"
set +a
info "已加载 ${NEXUS_ROOT}/deploy/nexus-1panel.secrets.sh"
fi
}
phase_preflight() {
step "阶段 1/6 — 环境检查"
if [[ "$(id -u)" -ne 0 ]]; then
error "请使用 root 运行: sudo bash $0"
exit 1
fi
info "运行用户: root"
if [[ ! -f /etc/os-release ]]; then
error "无法识别操作系统"
exit 1
fi
# shellcheck disable=SC1091
source /etc/os-release
info "系统: ${NAME:-Linux} ${VERSION_ID:-}"
case "${ID:-}" in
ubuntu|debian) info "受支持的分支: Debian/Ubuntu ✓" ;;
centos|rhel|rocky|almalinux) info "受支持的分支: RHEL 系 ✓" ;;
*) warn "未在官方列表中测试,可能仍可运行" ;;
esac
local mem_kb
mem_kb="$(awk '/MemTotal/ {print $2}' /proc/meminfo 2>/dev/null || echo 0)"
if [[ "$mem_kb" -lt 3500000 ]]; then
warn "内存 < 4GB,建议档位 1c4g: --profile 1c4g"
else
info "内存: $((mem_kb / 1024 / 1024)) GiB 量级"
fi
}
phase_1panel() {
step "阶段 2/6 — 1Panel / Docker"
if [[ "$SKIP_1PANEL_CHECK" != true ]]; then
if command -v 1pctl >/dev/null 2>&1; then
info "检测到 1Panel (1pctl)"
if 1pctl version >/dev/null 2>&1; then
info "1Panel: $(1pctl version 2>/dev/null | head -1 || true)"
fi
else
warn "未检测到 1pctl — 若尚未安装 1Panel,可先执行:"
warn " curl -sSL https://resource.1panel.pro/v2/quick_start.sh -o quick_start.sh"
warn " bash quick_start.sh"
read -r -p "继续安装 Nexus? [y/N]: " cont
[[ "$cont" == "y" || "$cont" == "Y" ]] || exit 0
fi
fi
if ! docker compose version >/dev/null 2>&1; then
error "未检测到 docker compose"
error "请在 1Panel → 容器 中安装 Docker,或: apt install -y docker.io docker-compose-v2"
exit 1
fi
info "Docker Compose: $(docker compose version --short 2>/dev/null || docker compose version | head -1)"
}
phase_packages() {
step "阶段 3/6 — 依赖包"
if command -v apt-get >/dev/null 2>&1; then
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq
apt-get install -y -qq git curl openssl ca-certificates iproute2 >/dev/null 2>&1 || true
elif command -v dnf >/dev/null 2>&1; then
dnf install -y -q git curl openssl ca-certificates iproute >/dev/null 2>&1 || true
fi
info "git / curl 就绪"
}
git_clone_url() {
if [[ -z "${NEXUS_GITEA_TOKEN:-}" ]]; then
echo "http://${NEXUS_GITEA_HOST}/${NEXUS_GITEA_REPO}"
else
echo "http://admin:${NEXUS_GITEA_TOKEN}@${NEXUS_GITEA_HOST}/${NEXUS_GITEA_REPO}"
fi
}
phase_clone() {
step "阶段 4/6 — 获取 Nexus 代码"
load_credentials
if [[ -z "${NEXUS_GITEA_TOKEN:-}" ]]; then
error "缺少 Gitea 令牌,无法 clone 私人仓库"
error "请任选一种方式:"
error " echo 'NEXUS_GITEA_TOKEN=你的令牌' > /root/.nexus-deploy.env && chmod 600 /root/.nexus-deploy.env"
error " 或在仓库 push deploy/nexus-1panel.secrets.sh 后重新运行本脚本"
exit 1
fi
local url
url="$(git_clone_url)"
mkdir -p "$(dirname "$NEXUS_ROOT")"
if [[ -d "${NEXUS_ROOT}/.git" ]]; then
info "仓库已存在,同步 ${NEXUS_GIT_BRANCH}..."
git -C "$NEXUS_ROOT" remote set-url origin "$url" 2>/dev/null || true
git -C "$NEXUS_ROOT" fetch origin "$NEXUS_GIT_BRANCH" --prune
git -C "$NEXUS_ROOT" reset --hard "origin/${NEXUS_GIT_BRANCH}"
else
if [[ -d "$NEXUS_ROOT" ]] && [[ -n "$(ls -A "$NEXUS_ROOT" 2>/dev/null)" ]]; then
error "目录非空且不是 git 仓库: $NEXUS_ROOT"
exit 1
fi
rm -rf "$NEXUS_ROOT"
info "克隆 → $NEXUS_ROOT"
git clone "$url" "$NEXUS_ROOT"
git -C "$NEXUS_ROOT" checkout "$NEXUS_GIT_BRANCH" 2>/dev/null || true
fi
load_credentials
info "版本: $(git -C "$NEXUS_ROOT" log -1 --oneline)"
chmod +x "${NEXUS_ROOT}/deploy/"*.sh 2>/dev/null || true
}
phase_install_stack() {
step "阶段 5/6 — Docker 构建与启动(全新库,约 10~20 分钟)"
export NEXUS_ROOT NEXUS_DOMAIN NEXUS_PROFILE
bash "${NEXUS_ROOT}/deploy/nexus-1panel.sh" install \
--fresh \
--skip-clone \
--profile "$NEXUS_PROFILE" \
--domain "$NEXUS_DOMAIN"
}
phase_post() {
step "阶段 6/6 — 收尾"
ln -sf "${NEXUS_ROOT}/deploy/nx" /usr/local/bin/nx 2>/dev/null || true
chmod +x "${NEXUS_ROOT}/deploy/nx" 2>/dev/null || true
local port health
port="8600"
health="$(curl -sf "http://127.0.0.1:${port}/health" 2>/dev/null || echo "pending")"
echo ""
echo -e "${GREEN}╔══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}${NC} ${GREEN}Nexus 全新安装完成${NC} ${GREEN}${NC}"
echo -e "${GREEN}╠══════════════════════════════════════════════════════════════╣${NC}"
echo -e "${GREEN}${NC} 本地健康: http://127.0.0.1:${port}/health → ${health} ${GREEN}${NC}"
echo -e "${GREEN}${NC} ${GREEN}${NC}"
echo -e "${GREEN}${NC} ${YELLOW}① 浏览器完成安装向导(必做)${NC} ${GREEN}${NC}"
echo -e "${GREEN}${NC} https://${NEXUS_DOMAIN}/app/install.html ${GREEN}${NC}"
echo -e "${GREEN}${NC} ${GREEN}${NC}"
echo -e "${GREEN}${NC} ${YELLOW}② 1Panel 创建网站并反代${NC} ${GREEN}${NC}"
echo -e "${GREEN}${NC} 目标: http://127.0.0.1:${port} ${GREEN}${NC}"
echo -e "${GREEN}${NC} 示例: ${NEXUS_ROOT}/deploy/1panel/openresty-nexus.conf.example ${GREEN}${NC}"
echo -e "${GREEN}${NC} ${GREEN}${NC}"
echo -e "${GREEN}${NC} ${YELLOW}③ 日常运维(上帝菜单)${NC} ${GREEN}${NC}"
echo -e "${GREEN}${NC} nx god # 重启 Python / 升级 / 日志 / 备份 ${GREEN}${NC}"
echo -e "${GREEN}${NC} nx # 主菜单 ${GREEN}${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════════════════════════╝${NC}"
echo ""
}
main() {
banner
phase_preflight
phase_1panel
phase_packages
phase_clone
phase_install_stack
phase_post
}
main "$@"
+14 -3
View File
@@ -104,7 +104,7 @@ menu_install() {
[3] 安装 — 1核4G1c4g
[4] 自定义规格(输入 CPU 与内存 GB)
[5] 已 clone 到 /opt/nexus,仅 pull + 启动(--skip-clone
[6] 全新安装向导模式/app/install.html
[6] 全新安装(install-nexus-fresh.sh → /app/install.html
[7] 检查端口 / 防火墙(不安装)
[8] 写入 Gitea 令牌(init-token
[9] 返回主菜单
@@ -124,7 +124,13 @@ EOF
run_install 2c8g ""
;;
5) run_install 2c8g skip-clone ;;
6) run_install 2c8g fresh ;;
6)
if [[ -x "${NX_DIR}/install-nexus-fresh.sh" ]]; then
bash "${NX_DIR}/install-nexus-fresh.sh" --profile "${NEXUS_PROFILE:-2c8g}"
else
run_install 2c8g fresh
fi
;;
7)
require_root
load_secrets
@@ -342,6 +348,10 @@ nx_main() {
""|menu) menu_main ;;
install) menu_install ;;
god|ops|admin) menu_god ;;
install-fresh|fresh)
require_root
exec bash "${NX_DIR}/install-nexus-fresh.sh" "$@"
;;
install-auto|auto)
require_root
if is_stack_installed; then
@@ -360,7 +370,8 @@ nx_main() {
(无) 交互主菜单
install 安装向导
install-auto 非交互一键安装(2c8g
install-fresh 全新安装(1Panel 风格,/app/install.html
install-auto 非交互安装已有密钥(2c8g)
god 上帝菜单(重启/升级/日志)
health 健康检查
@@ -0,0 +1,35 @@
# Changelog: 1Panel 风格全新安装脚本
**日期**: 2026-06-04
## 摘要
新增 `deploy/install-nexus-fresh.sh`:参考 1Panel `quick_start.sh` 的分阶段检查与安装完成信息框;空库安装后引导 `/app/install.html` 与 1Panel 反代配置。
## 涉及文件
- `deploy/install-nexus-fresh.sh` — 主脚本
- `deploy/nx` — 菜单项 6 / 子命令 `install-fresh`
- `deploy/README-1panel.md`
## 用法
```bash
curl -sSL "http://66.154.115.8:3000/admin/Nexus/raw/branch/main/deploy/install-nexus-fresh.sh" -o /tmp/install-nexus-fresh.sh
sudo bash /tmp/install-nexus-fresh.sh
sudo bash /tmp/install-nexus-fresh.sh --profile 4c16g
```
或:`bash deploy/nx install-fresh`
## 与迁机区别
| 脚本 | 场景 |
|------|------|
| `install-nexus-fresh.sh` | 新库 + 安装向导 |
| `nexus-1panel.sh install --from-env` | 宝塔迁密钥 |
## 验证
- `bash -n deploy/install-nexus-fresh.sh`
- 1Panel 新机执行后 `/health``/app/install.html` 可访问