Second-Me 本地化部署


前言

本文主要针对本地/国内服务器部署的时候,可能会出现的一些网络问题,相对应的做了一些配置修改


一、Second-Me 介绍

不多介绍,感兴趣的可以去看一下官网,Second-Me

二、本地化部署

1. 服务器准备

我使用的是Ubuntu Server 20.04.6,服务器初始化和docker,docker-compose的安装过程就省略了,网上教程很多

root@ubuntu:~# cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

2. 下载源码

git clone https://github.com/mindverse/Second-Me.git

3. 修改配置(重点)

3.1 前端镜像

修改任何文件之前,养成备份的好习惯

root@ubuntu:~# cd Second-Me-master/
root@ubuntu:~/Second-Me-master# cp Dockerfile.frontend Dockerfile.frontend.bak
root@ubuntu:~/Second-Me-master# vim Dockerfile.frontend
# BaseImage修改
FROM registry.cn-hangzhou.aliyuncs.com/tmp2025/node:23
  
# Set working directory
WORKDIR /app

# Copy frontend package files
COPY lpm_frontend/package.json lpm_frontend/package-lock.json* /app/

# Install dependencies(增加了npm安装源地址修改)
RUN npm config set registry https://registry.npmmirror.com && npm install

# Copy frontend code
COPY lpm_frontend/ /app/

# Set environment variable for backend URL (can be overridden in docker-compose)
ENV DOCKER_API_BASE_URL=http://backend:8002

# Create logs directory
RUN mkdir -p /app/logs

# Expose frontend port
EXPOSE 3000

# Start frontend service
CMD ["npm", "run", "dev"]

3.2 后端镜像

root@ubuntu:~/Second-Me-master# cp Dockerfile.backend Dockerfile.backend.bak
root@ubuntu:~/Second-Me-master# vim Dockerfile.backend
# BaseImage修改
FROM registry.cn-hangzhou.aliyuncs.com/tmp2025/python:3.12

# Set working directory
WORKDIR /app

# Install system dependencies, Poetry and configure it
RUN sed -i 's@deb.debian.org@mirrors.ustc.edu.cn@g' /etc/apt/sources.list.d/debian.sources \
    && apt-get update && apt-get install -y \
    build-essential cmake git curl wget lsof vim unzip sqlite3 \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    && pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple --upgrade pip \
    && pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple \
    && pip install poetry \
    && poetry config virtualenvs.create false

# Create directories
RUN mkdir -p /app/dependencies /app/data/sqlite /app/data/chroma_db /app/logs /app/run /app/resources

# Copy dependency files - Files that rarely change
COPY dependencies/graphrag-1.2.1.dev27.tar.gz /app/dependencies/
COPY dependencies/llama.cpp.zip /app/dependencies/

# Build llama.cpp
RUN LLAMA_LOCAL_ZIP="dependencies/llama.cpp.zip" \
    && echo "Using local llama.cpp archive..." \
    && unzip -q "$LLAMA_LOCAL_ZIP" \
    && cd llama.cpp \
    && mkdir -p build && cd build \
    && cmake .. \
    && cmake --build . --config Release \
    && if [ ! -f "bin/llama-server" ]; then \
         echo "Build failed: llama-server executable not found" && exit 1; \
       else \
         echo "Successfully built llama-server"; \
       fi

# 
# Copy project configuration - Files that occasionally change
COPY pyproject.toml README.md /app/

RUN poetry source add --priority=primary mirrors https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/
RUN poetry install --no-interaction --no-root
RUN pip install --force-reinstall dependencies/graphrag-1.2.1.dev27.tar.gz

# Copy source code - Files that frequently change
COPY docker/ /app/docker/
COPY lpm_kernel/ /app/lpm_kernel/

# Check module import
RUN python -c "import lpm_kernel; print('Module import check passed')"

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONPATH=/app \
    BASE_DIR=/app/data \
    LOCAL_LOG_DIR=/app/logs \
    RUN_DIR=/app/run \
    RESOURCES_DIR=/app/resources \
    APP_ROOT=/app \
    FLASK_APP=lpm_kernel.app

# Expose ports
EXPOSE 8002 8080

# Set the startup command
CMD ["bash", "-c", "echo \"Checking SQLite database...\" && if [ ! -s /app/data/sqlite/lpm.db ]; then echo \"SQLite database not found or empty, initializing...\" && mkdir -p /app/data/sqlite && sqlite3 /app/data/sqlite/lpm.db \".read /app/docker/sqlite/init.sql\" && echo \"SQLite database initialized successfully\" && echo \"Tables created:\" && sqlite3 /app/data/sqlite/lpm.db \".tables\"; else echo \"SQLite database already exists, skipping initialization\"; fi && echo \"Checking ChromaDB...\" && if [ ! -d /app/data/chroma_db/documents ] || [ ! -d /app/data/chroma_db/document_chunks ]; then echo \"ChromaDB collections not found, initializing...\" && python /app/docker/app/init_chroma.py && echo \"ChromaDB initialized successfully\"; else echo \"ChromaDB already exists, skipping initialization\"; fi && echo \"Starting application at $(date)\" >> /app/logs/backend.log && cd /app && python -m flask run --host=0.0.0.0 --port=${LOCAL_APP_PORT:-8002} >> /app/logs/backend.log 2>&1"]

主要修改点

  1. Dockerfile.backend 的第三步替换apt和pip的源地址
RUN sed -i 's@deb.debian.org@mirrors.ustc.edu.cn@g' /etc/apt/sources.list.d/debian.sources \
    && apt-get update && apt-get install -y \
    build-essential cmake git curl wget lsof vim unzip sqlite3 \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    && pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple --upgrade pip \
    && pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple \
    && pip install poetry \
    && poetry config virtualenvs.create false
  1. 第九步,增加poetry下载源
RUN poetry source add --priority=primary mirrors https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/

3.3 修改dependencies包中的依赖

Dockerfile.backend 的第十步,是强制重新安装依赖,这个步骤中需要到github以及poetry官网去下载相关的依赖,编译失败的基本就卡在这一步

RUN pip install --force-reinstall dependencies/graphrag-1.2.1.dev27.tar.gz
3.3.1 解压依赖文件,修改配置:

解压后,pyproject.toml的配置文件中, [tool.poetry.dependencies]、[tool.poetry.urls]

  • ec-core-web-md的依赖包地址
[tool.poetry.dependencies]
python = ">=3.10,<3.13"
environs = "^11.0.0"
en-core-web-md = { url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_md-3.8.0/en_core_web_md-3.8.0.tar.gz" }

修改为
en-core-web-md = { file = "./en_core_web_md-3.8.0.tar.gz" }

需要手动下载该文件,并存放于当前文件夹下,下载链接:“https://download.csdn.net/download/qq_28212937/90628118”

  • poetry的下载源
[tool.poetry.urls]
"Source" = "https://github.com/microsoft/graphrag"

地址替换为
Source" = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/

3.3.2 重新压缩当前的压缩包
  • 备份旧文件
    mv graphrag-1.2.1.dev27.tar.gz graphrag-1.2.1.dev27.tar.gz.bak
  • 压缩新的包
    tar zcvf graphrag-1.2.1.dev27.tar.gz graphrag

或者直接用已经压缩好的包,下载地址:https://download.csdn.net/download/qq_28212937/90628122

4 编译运行

进入项目目录,直接docker-compose up -d

root@ubuntu:~# cd Second-Me-master/
root@ubuntu:~/Second-Me-master# docker-compose up -d

编译的过程有点长,耐心等待即可。


总结

这一篇主要讲一下部署相关的内容,下一篇会分享Second-Me的使用教程。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值