# ubuntu24.04 部署 ragflow + 阿里百炼大模型 + docker ，系统使用阿里源，采用纯cpu 无gpu方案 详细的部署方法1

下面给你一套**在 Ubuntu 24.04（阿里云源）+ Docker + CPU-only（无GPU）环境**部署：

> **RAGFlow + 阿里云百炼（DashScope）大模型接入 + Ollama/可选嵌入模型 + Docker Compose**

这是目前生产里比较稳的一种“CPU RAG方案”。

---

# 一、整体架构（你最终会跑的东西）

你这套系统本质是：

- RAGFlow（RAG框架）
- Elasticsearch（向量/检索）
- Ollama（可选，本地embedding/小模型）
- 阿里百炼 DashScope（LLM 主模型）
- Docker Compose 一键编排

---

# 二、Ubuntu 24.04 基础环境（阿里源优化）

## 1. 替换阿里APT源（建议）

```bash
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i 's|http://.*ubuntu.com|https://mirrors.aliyun.com|g' /etc/apt/sources.list
sudo apt update && sudo apt upgrade -y

```

---

## 2. 安装基础依赖

```bash
sudo apt install -y \
  git curl wget vim \
  ca-certificates gnupg lsb-release \
  htop net-tools

```

---

## 3. Docker + Compose（必须24+）

### 安装 Docker（官方方式）

```bash
curl -fsSL https://get.docker.com | bash
sudo usermod -aG docker $USER
newgrp docker

```

### 验证

```bash
docker -v
docker compose version

```

---

## 4. 内核参数（RAGFlow必须）

```bash
sudo sysctl -w vm.max_map_count=262144
echo "vm.max_map_count=262144" | sudo tee -a /etc/sysctl.conf

```

---

# 三、部署 RAGFlow（CPU版本）

## 1. 克隆项目

```bash
git clone https://github.com/infiniflow/ragflow.git
cd ragflow

```

---

## 2. 使用 CPU docker-compose

进入 docker 目录：

```bash
cd docker

```

查看 compose：

```bash
ls

```

你会看到类似：

- docker-compose.yml
- .env
- service\_conf.yaml.template

---

## 3. 修改 .env（关键）

打开：

```bash
vim .env

```

重点改这些（CPU模式）：

```env
# CPU模式
RAGFLOW_MODE=cpu

# 端口
RAGFLOW_PORT=80

# 禁用GPU
USE_GPU=false

```

---

## 4. 启动 RAGFlow

```bash
docker compose up -d

```

第一次会拉取：

- Elasticsearch
- RAGFlow backend
- worker
- frontend

---

## 5. 检查状态

```bash
docker ps

```

访问：

```
http://你的服务器IP

```

---

# 四、接入阿里云百炼（DashScope LLM）

这是你最关键的一步。

---

## 1. 获取 API Key

进入阿里云百炼：

- [https://bailian.aliyun.com/](https://bailian.aliyun.com/)

创建：

- API Key（DashScope）

---

## 2. 在 RAGFlow 中配置 LLM

进入 RAGFlow Web UI：

```
Settings → Model Provider → Add Model

```

选择：

> DashScope / Alibaba Cloud

填写：

```text
API Key: sk-xxxx
Base URL: https://dashscope.aliyuncs.com/compatible-mode/v1
Model: qwen-plus 或 qwen-max

```

---

## 3. 推荐模型（CPU RAG稳定）

- qwen-turbo（最快，推荐默认）
- qwen-plus（平衡）
- qwen-max（效果最好，贵）

---

# 五、嵌入模型（CPU方案推荐）

你有两种方式：

---

## 方案A（推荐）：阿里Embedding（省事）

在百炼里选：

```
text-embedding-v3

```

配置：

```
Provider: DashScope
Model: text-embedding-v3

```

---

## 方案B：本地 Ollama（CPU）

安装 Ollama：

```bash
curl -fsSL https://ollama.com/install.sh | sh

```

启动：

```bash
ollama serve

```

拉 embedding：

```bash
ollama pull bge-m3

```

---

### RAGFlow连接 Ollama：

```text
http://host.docker.internal:11434

```

⚠️ CPU机器也能跑，但比阿里 embedding 慢

---

# 六、Docker CPU优化（重要）

编辑：

```bash
docker-compose.yml

```

加：

```yaml
deploy:
  resources:
    limits:
      cpus: "4"
      memory: 8G

```

---

# 七、常见坑（非常重要）

## 1. Elasticsearch 起不来

```bash
vm.max_map_count < 262144

```

解决：

```bash
sudo sysctl -w vm.max_map_count=262144

```

---

## 2. CPU太慢

建议：

- 用 qwen-turbo
- embedding 用 text-embedding-v3
- 不要本地大模型

---

## 3. Docker 内存爆

至少：

- 16GB RAM（最低）
- 推荐 32GB

---

# 八、完整启动流程（总结版）

```bash
# 1. 安装docker
curl -fsSL https://get.docker.com | bash

# 2. clone
git clone https://github.com/infiniflow/ragflow.git
cd ragflow/docker

# 3. 系统参数
sudo sysctl -w vm.max_map_count=262144

# 4. 启动
docker compose up -d

```

---

# 九、推荐生产级组合（CPU最优）

<table id="bkmrk-%E6%A8%A1%E5%9D%97-%E6%96%B9%E6%A1%88-rag%E6%A1%86%E6%9E%B6-ragflow-"><thead><tr><th>模块</th><th>方案</th></tr></thead><tbody><tr><td>RAG框架</td><td>RAGFlow</td></tr><tr><td>LLM</td><td>阿里百炼 qwen-turbo</td></tr><tr><td>Embedding</td><td>text-embedding-v3</td></tr><tr><td>向量</td><td>Elasticsearch</td></tr><tr><td>部署</td><td>Docker Compose</td></tr><tr><td>OS</td><td>Ubuntu 24.04（阿里源）</td></tr></tbody></table>

---

# 如果你要进阶（我可以继续帮你）

我可以再帮你细化这三块：

### 🚀 1. 生产级 docker-compose（含Nginx + HTTPS）

### 🚀 2. RAGFlow + 百炼 prompt 最佳实践（中文知识库优化）

### 🚀 3. Elasticsearch 调优（CPU 低配提速 3-5倍）

只要你说你机器配置（CPU/内存/磁盘），我可以给你一套“可直接上线版本”。