fix: 修复Docker仓库问题,添加阿里云镜像源

This commit is contained in:
Sens 2026-02-20 23:04:07 +08:00
parent 5194bf8c99
commit 809ff9428c
1 changed files with 46 additions and 17 deletions

View File

@ -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"