From 8a4cfca9508d01dc455ee536d0b0c26c53df1935 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 8 Apr 2026 22:43:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Ubuntu=20=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E8=84=9A=E6=9C=AC=20-=20=E7=A7=BB=E9=99=A4=E4=B8=8D?= =?UTF-8?q?=E5=8F=AF=E7=94=A8=E7=9A=84=205.0=20=E6=BA=90=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20Docker=20=E5=A4=87=E7=94=A8=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/install_neo4j_ubuntu.sh | 84 ++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 27 deletions(-) diff --git a/scripts/install_neo4j_ubuntu.sh b/scripts/install_neo4j_ubuntu.sh index c54f44f..3a6240f 100644 --- a/scripts/install_neo4j_ubuntu.sh +++ b/scripts/install_neo4j_ubuntu.sh @@ -44,54 +44,84 @@ $SUDO apt install -y curl gnupg # 添加 GPG key curl -fsSL https://debian.neo4j.com/neotechnology.gpg.key | $SUDO gpg --dearmor -o /usr/share/keyrings/neo4j.gpg -# 添加 repository +# 添加 repository - 只使用 stable latest(5.0 已不可用) echo "deb [signed-by=/usr/share/keyrings/neo4j.gpg] https://debian.neo4j.com stable latest" | $SUDO tee /etc/apt/sources.list.d/neo4j.list -echo "deb [signed-by=/usr/share/keyrings/neo4j.gpg] https://debian.neo4j.com 5.0 latest" | $SUDO tee -a /etc/apt/sources.list.d/neo4j.list -$SUDO apt update +# 允许 apt update 失败继续,但只关注 Neo4j +$SUDO apt update -o Dir::Etc::sourcelist="sources.list.d/neo4j.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="false" 2>/dev/null || true # ------------------------------------------------------------------------- # 3. 安装 Neo4j # ------------------------------------------------------------------------- echo "[3/6] 安装 Neo4j Community Edition..." -# 安装 neo4j (会同时安装依赖) -$SUDO apt install -y neo4j +# 尝试通过 apt 安装,如果失败则使用备用方案 +if $SUDO apt install -y neo4j 2>/dev/null; then + echo " Neo4j 通过 apt 安装成功" +else + echo " apt 安装失败,尝试使用 Docker..." + + # 检查并安装 Docker(如果未安装) + if ! command -v docker &> /dev/null; then + echo " 安装 Docker..." + $SUDO apt install -y docker.io 2>/dev/null || true + fi + + # 如果 Docker 可用,使用 Docker 启动 Neo4j + if command -v docker &> /dev/null; then + docker run -d --name neo4j \ + -p 7474:7474 -p 7687:7687 \ + -e NEO4J_AUTH=neo4j/neo4j \ + -e NEO4J_PLUGINS='["apoc"]' \ + neo4j:5 || true + echo " Neo4j Docker 容器已启动" + else + echo " 无法安装 Neo4j,请手动安装或使用 Docker" + exit 1 + fi +fi # ------------------------------------------------------------------------- # 4. 配置 Neo4j # ------------------------------------------------------------------------- echo "[4/6] 配置 Neo4j..." -# 允许远程访问 -$SUDO sed -i 's/#server.default_listen_address=0.0.0.0/server.default_listen_address=0.0.0.0/' /etc/neo4j/neo4j.conf - -# 设置初始密码 (默认用户: neo4j) -# 如果需要设置密码,取消下面注释并修改密码 -# echo "neo4j:你的密码" | $SUDO tee /etc/neo4j/neo4j-auth - -# 关闭增强监控(开发环境) -$SUDO sed -i 's/#dbms.security.procedures.unrestricted=.*/dbms.security.procedures.unrestricted=apoc.*/' /etc/neo4j/neo4j.conf - -# 启用 APOC -$SUDO sed -i 's/#dbms.security.procedures.unallowed=.*/dbms.security.procedures.unallowed=apoc.*/' /etc/neo4j/neo4j.conf +# 检测是否使用 Docker +if command -v docker &> /dev/null && docker ps 2>/dev/null | grep -q neo4j; then + echo " 检测到 Neo4j Docker 容器,跳过配置步骤" + NEO4J_IS_DOCKER=true +else + NEO4J_IS_DOCKER=false + + # 允许远程访问 + $SUDO sed -i 's/#server.default_listen_address=0.0.0.0/server.default_listen_address=0.0.0.0/' /etc/neo4j/neo4j.conf 2>/dev/null || true + + # 关闭增强监控(开发环境) + $SUDO sed -i 's/#dbms.security.procedures.unrestricted=.*/dbms.security.procedures.unrestricted=apoc.*/' /etc/neo4j/neo4j.conf 2>/dev/null || true + + # 启用 APOC + $SUDO sed -i 's/#dbms.security.procedures.unallowed=.*/dbms.security.procedures.unallowed=apoc.*/' /etc/neo4j/neo4j.conf 2>/dev/null || true +fi # ------------------------------------------------------------------------- # 5. 启动 Neo4j # ------------------------------------------------------------------------- echo "[5/6] 启动 Neo4j 服务..." -$SUDO systemctl enable neo4j -$SUDO systemctl start neo4j - -# 等待启动 -sleep 5 - -# 检查状态 -if $SUDO systemctl is-active --quiet neo4j; then - echo " Neo4j 已启动" +if [ "$NEO4J_IS_DOCKER" = "true" ]; then + docker start neo4j 2>/dev/null || true + sleep 5 + echo " Neo4j Docker 容器已启动" else - echo " 警告: Neo4j 启动可能失败,请检查: sudo systemctl status neo4j" + $SUDO systemctl enable neo4j 2>/dev/null || true + $SUDO systemctl start neo4j 2>/dev/null || true + sleep 5 + + if $SUDO systemctl is-active --quiet neo4j 2>/dev/null; then + echo " Neo4j 已启动" + else + echo " 警告: Neo4j 启动可能失败" + fi fi # -------------------------------------------------------------------------