From 809ff9428cc9858726b2ec512202b7aef6a02bf1 Mon Sep 17 00:00:00 2001 From: lgh <625458956@qq.com> Date: Fri, 20 Feb 2026 23:04:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DDocker=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E9=97=AE=E9=A2=98=EF=BC=8C=E6=B7=BB=E5=8A=A0=E9=98=BF?= =?UTF-8?q?=E9=87=8C=E4=BA=91=E9=95=9C=E5=83=8F=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy.sh | 63 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/deploy.sh b/deploy.sh index 0ac985a..3740af1 100644 --- a/deploy.sh +++ b/deploy.sh @@ -27,20 +27,47 @@ fi echo -e "${GREEN}✅ 开始部署...${NC}" # ========== 1. 安装系统依赖 ========== -echo -e "${YELLOW}[1/8] 安装系统依赖...${NC}" +echo -e "${YELLOW}[1/9] 安装系统依赖 (包括 Docker)...${NC}" -# 移除可能导致问题的 Docker 仓库配置 +echo -e "${YELLOW}>>> 清理旧的 Docker 仓库配置...${NC}" rm -f /etc/apt/sources.list.d/docker*.list 2>/dev/null || true +rm -f /etc/apt/keyrings/docker.gpg 2>/dev/null || true -# 更新包列表,允许不安全的仓库 -apt-get update --allow-insecure-repositories || apt-get update +echo -e "${YELLOW}>>> 添加 Docker 国内镜像源...${NC}" +# 添加 Docker 阿里云镜像源 +mkdir -p /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg 2>/dev/null || \ +curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg 2>/dev/null || true -# 升级包,跳过不可用的包 -apt-get upgrade -y --allow-downgrades --remove-essentialallow- --allow-change-held-packages || \ -apt-get upgrade -y --fix-missing || true +echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] http://mirrors.aliyun.com/docker-ce/linux/debian bullseye stable" > /etc/apt/sources.list.d/docker.list -# 安装基础工具 -apt-get install -y --no-install-recommends curl wget git nginx software-properties-common || true +# 更新包列表 +apt-get update || apt-get update --allow-insecure-repositories + +echo -e "${YELLOW}>>> 安装基础工具...${NC}" +apt-get install -y --no-install-recommends ca-certificates curl wget git nginx software-properties-common || true + +echo -e "${YELLOW}>>> 安装 Docker...${NC}" +apt-get install -y --no-install-recommends docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin || true + +# 启动 Docker +systemctl start docker || true +systemctl enable docker || true + +echo -e "${YELLOW}>>> 配置 Docker 镜像加速...${NC}" +mkdir -p /etc/docker +cat > /etc/docker/daemon.json << 'DOCKEREOF' +{ + "registry-mirrors": [ + "https://docker.mirrors.ustc.edu.cn", + "https://hub-mirror.c.163.com", + "https://mirror.baidubce.com" + ] +} +DOCKEREOF + +systemctl daemon-reload +systemctl restart docker || true # 安装 Python apt-get install -y --no-install-recommends python3.9 python3-pip python3-venv python3-dev libpq-dev || true @@ -52,11 +79,12 @@ apt-get install -y --no-install-recommends nodejs || true python3 --version node --version npm --version +docker --version echo -e "${GREEN}✅ 系统依赖安装完成${NC}" # ========== 2. 配置 PostgreSQL ========== -echo -e "${YELLOW}[2/8] 配置 PostgreSQL 数据库...${NC}" +echo -e "${YELLOW}[2/9] 配置 PostgreSQL 数据库...${NC}" apt-get install -y --no-install-recommends postgresql postgresql-contrib || true @@ -71,7 +99,7 @@ su - postgres -c "psql -d neural_sync -c \"CREATE EXTENSION IF NOT EXISTS vector echo -e "${GREEN}✅ PostgreSQL 配置完成${NC}" # ========== 3. 拉取项目代码 ========== -echo -e "${YELLOW}[3/8] 拉取项目代码...${NC}" +echo -e "${YELLOW}[3/9] 拉取项目代码...${NC}" cd /opt @@ -136,7 +164,7 @@ fi echo -e "${GREEN}✅ 项目代码拉取完成${NC}" # ========== 4. 配置后端 ========== -echo -e "${YELLOW}[4/8] 配置后端服务...${NC}" +echo -e "${YELLOW}[4/9] 配置后端服务...${NC}" cd "$PROJECT_DIR/backend" @@ -163,7 +191,7 @@ deactivate echo -e "${GREEN}✅ 后端配置完成${NC}" # ========== 5. 构建前端 ========== -echo -e "${YELLOW}[5/8] 构建前端...${NC}" +echo -e "${YELLOW}[5/9] 构建前端...${NC}" cd "$PROJECT_DIR/frontend" @@ -179,7 +207,7 @@ fi echo -e "${GREEN}✅ 前端构建完成${NC}" # ========== 6. 配置 Nginx ========== -echo -e "${YELLOW}[6/8] 配置 Nginx...${NC}" +echo -e "${YELLOW}[6/9] 配置 Nginx...${NC}" cat > /etc/nginx/sites-available/neural-sync << 'EOF' server { @@ -229,7 +257,7 @@ systemctl reload nginx echo -e "${GREEN}✅ Nginx 配置完成${NC}" # ========== 7. 配置 Systemd 服务 ========== -echo -e "${YELLOW}[7/8] 配置 Systemd 服务...${NC}" +echo -e "${YELLOW}[7/9] 配置 Systemd 服务...${NC}" cat > /etc/systemd/system/neural-sync.service << EOF [Unit] @@ -264,8 +292,8 @@ else journalctl -u neural-sync -n 20 fi -# ========== 8. 开放防火墙端口 ========== -echo -e "${YELLOW}[8/8] 开放防火墙端口...${NC}" +# ========== 9. 开放防火墙端口 ========== +echo -e "${YELLOW}[9/9] 开放防火墙端口...${NC}" # Ubuntu ufw if command -v ufw &> /dev/null; then @@ -293,6 +321,7 @@ echo -e "${YELLOW}常用命令:${NC}" echo " - 查看后端日志: journalctl -u neural-sync -f" echo " - 重启后端: systemctl restart neural-sync" echo " - 重载 Nginx: nginx -s reload" +echo " - Docker: docker ps / docker logs 等" echo "" echo -e "${YELLOW}配置信息:${NC}" echo " - 数据库: neural_sync"