从零搭建私有 AI 搜索:Perplexica + SearXNG 部署实战与命令整理
AI搜索 部署完整教程|附完整命令
随着大模型应用的普及,越来越多团队开始关注“AI搜索”能力。传统搜索引擎只能返回网页链接,而 AI 搜索可以结合搜索结果、网页内容抓取、向量检索和大语言模型,对问题进行总结、归纳,并给出更接近答案的结果。
如果你希望搭建一个类似 Perplexity、秘塔 AI 搜索、Kimi 搜索问答的私有化 AI 搜索系统,可以使用开源方案完成部署。本文将以 Perplexica + SearXNG + Docker Compose 为例,手把手讲解如何在服务器上部署一个可用的 AI 搜索服务,并附上完整命令。
一、方案说明
本文采用的方案如下:
| 组件 | 作用 |
|---|---|
| Perplexica | 开源 AI 搜索前端与后端服务,负责对话、搜索增强和结果整理 |
| SearXNG | 元搜索引擎,用于聚合 Google、Bing、DuckDuckGo 等搜索结果 |
| Docker | 容器化运行环境 |
| Docker Compose | 统一编排多个服务 |
| OpenAI / DeepSeek / 通义千问 / Ollama | 大语言模型,可选择云端 API 或本地模型 |
Perplexica 是一个开源的 AI 搜索项目,可以将搜索引擎结果与大语言模型结合起来,生成带引用来源的搜索答案。它非常适合个人知识检索、企业内部搜索入口、技术文档问答、行业信息聚合等场景。
二、服务器准备
本文以 Ubuntu 22.04 LTS 为例,推荐配置如下:
| 项目 | 推荐配置 |
|---|---|
| CPU | 2 核及以上 |
| 内存 | 4GB 及以上 |
| 磁盘 | 20GB 及以上 |
| 系统 | Ubuntu 20.04 / 22.04 / 24.04 |
| 网络 | 可访问 GitHub、Docker Hub |
如果你只是调用云端大模型 API,例如 OpenAI、DeepSeek、通义千问等,服务器配置不需要太高。
如果你希望本地运行 Ollama 模型,建议至少:
- 8GB 内存运行 7B 量级模型;
- 16GB 内存体验更好;
- 如果有 NVIDIA GPU,效果更佳。
三、更新系统环境
首先连接服务器:
ssh root@你的服务器IP
更新系统软件包:
apt update && apt upgrade -y
安装常用工具:
apt install -y curl wget git vim unzip ca-certificates gnupg lsb-release
设置时区为上海:
timedatectl set-timezone Asia/Shanghai
查看时间:
date
四、安装 Docker
如果你的服务器还没有安装 Docker,可以使用官方安装脚本:
curl -fsSL https://get.docker.com | bash
启动 Docker:
systemctl enable docker
systemctl start docker
查看 Docker 版本:
docker version
如果能够正常显示客户端和服务端版本,说明 Docker 安装成功。
五、安装 Docker Compose
新版 Docker 一般已经内置了 Compose 插件,可以直接执行:
docker compose version
如果提示没有该命令,可以手动安装:
apt install -y docker-compose-plugin
再次确认:
docker compose version
六、创建部署目录
建议将 AI 搜索服务统一放在 /opt/ai-search 目录下:
mkdir -p /opt/ai-search
cd /opt/ai-search
七、克隆 Perplexica 项目
执行以下命令:
git clone https://github.com/ItzCrazyKns/Perplexica.git
进入项目目录:
cd Perplexica
查看项目文件:
ls -la
一般可以看到 docker-compose.yaml、sample.config.toml 等文件。
八、配置 Perplexica
复制示例配置文件:
cp sample.config.toml config.toml
编辑配置文件:
vim config.toml
你需要重点关注以下配置项。
九、配置搜索引擎 SearXNG
Perplexica 通常通过 SearXNG 获取搜索结果。使用 Docker Compose 部署时,可以让 Perplexica 访问同一个 Compose 网络中的 SearXNG 服务。
如果配置文件里有类似内容:
[SEARCH]
SEARXNG_API_URL = "http://searxng:8080"
可以保持为:
[SEARCH]
SEARXNG_API_URL = "http://searxng:8080"
这里的 searxng 是 Docker Compose 中的服务名称,不需要改成服务器 IP。
如果你使用外部 SearXNG 服务,则可以改为:
[SEARCH]
SEARXNG_API_URL = "https://你的searxng域名"
不过更推荐本地一起部署,稳定性更好。
十、配置大模型 API
AI 搜索必须接入大语言模型。你可以选择以下方式之一。
方式一:使用 OpenAI API
如果你使用 OpenAI,可以在 config.toml 中配置 OpenAI Key。
示例:
[OPENAI]
API_KEY = "sk-xxxxxxxxxxxxxxxxxxxxxxxx"
如果你的项目配置中支持 API 地址,也可以配置:
[OPENAI]
API_KEY = "sk-xxxxxxxxxxxxxxxxxxxxxxxx"
API_URL = "https://api.openai.com/v1"
方式二:使用 DeepSeek API
DeepSeek API 兼容 OpenAI 格式,因此很多项目可以通过 OpenAI-compatible 方式接入。
配置示例:
[OPENAI]
API_KEY = "sk-你的DeepSeek API Key"
API_URL = "https://api.deepseek.com/v1"
模型可以选择:
MODEL = "deepseek-chat"
如果配置文件中有模型列表,请将模型名称改为:
deepseek-chat
方式三:使用通义千问 API
阿里云通义千问也支持 OpenAI 兼容接口。
配置示例:
[OPENAI]
API_KEY = "sk-你的DashScope API Key"
API_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1"
模型示例:
MODEL = "qwen-plus"
也可以使用:
MODEL = "qwen-turbo"
方式四:使用本地 Ollama
如果你希望完全本地化部署,可以使用 Ollama 运行模型。
先安装 Ollama:
curl -fsSL https://ollama.com/install.sh | sh
启动 Ollama:
systemctl enable ollama
systemctl start ollama
拉取模型,例如 Qwen2.5 7B:
ollama pull qwen2.5:7b
测试模型:
ollama run qwen2.5:7b
如果希望 Perplexica 容器访问宿主机 Ollama,可以使用:
http://host.docker.internal:11434
但在 Linux 下,有时需要在 Docker Compose 中额外添加:
extra_hosts:
- "host.docker.internal:host-gateway"
如果 Perplexica 支持 Ollama 配置,可以设置:
[OLLAMA]
API_URL = "http://host.docker.internal:11434"
MODEL = "qwen2.5:7b"
十一、检查 Docker Compose 配置
查看 Compose 文件:
cat docker-compose.yaml
如果项目默认提供了 docker-compose.yaml,一般可以直接使用。
如果你想自定义端口,可以编辑:
vim docker-compose.yaml
常见端口说明:
| 服务 | 默认端口 | 说明 |
|---|---|---|
| Perplexica Web | 3000 | AI搜索页面 |
| Perplexica Backend | 3001 | 后端 API |
| SearXNG | 8080 | 搜索引擎服务 |
如果你的服务器 3000 端口被占用,可以改成:
ports:
- "3080:3000"
这样访问地址就变成:
http://服务器IP:3080
十二、启动 AI 搜索服务
在 Perplexica 项目目录下执行:
docker compose up -d
查看容器状态:
docker compose ps
查看日志:
docker compose logs -f
如果只想查看某个服务日志,例如 Perplexica:
docker compose logs -f perplexica
如果服务名称不同,可以先查看:
docker compose ps
十三、访问 AI 搜索页面
启动成功后,在浏览器访问:
http://你的服务器IP:3000
如果你修改过端口,例如映射为 3080,则访问:
http://你的服务器IP:3080
进入页面后,可以输入问题测试,例如:
2025年AI搜索的发展趋势是什么?
或者:
帮我搜索并总结 Docker Compose 部署 SearXNG 的方法,给出关键步骤。
如果配置正常,系统会先调用 SearXNG 获取搜索结果,再调用大模型进行总结,最后返回带有引用来源的回答。
十四、开放服务器端口
如果无法访问页面,可能是云服务器安全组或防火墙未开放端口。
Ubuntu UFW 防火墙
查看状态:
ufw status
开放 3000 端口:
ufw allow 3000/tcp
如果你使用 3080:
ufw allow 3080/tcp
重新加载:
ufw reload
云服务器安全组
如果你使用阿里云、腾讯云、华为云、AWS、Azure 等,还需要在控制台开放对应端口。
例如开放:
TCP 3000
TCP 3080
TCP 80
TCP 443
十五、配置域名访问
直接使用 IP + 端口虽然方便,但正式使用建议绑定域名,例如:
search.example.com
先添加 DNS 解析:
| 类型 | 主机记录 | 记录值 |
|---|---|---|
| A | search | 服务器 IP |
等待解析生效后,安装 Nginx:
apt install -y nginx
创建站点配置:
vim /etc/nginx/sites-available/ai-search.conf
写入以下内容:
server {
listen 80;
server_name search.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
启用配置:
ln -s /etc/nginx/sites-available/ai-search.conf /etc/nginx/sites-enabled/
检查 Nginx 配置:
nginx -t
重启 Nginx:
systemctl restart nginx
此时访问:
http://search.example.com
十六、配置 HTTPS 证书
推荐使用 Certbot 免费申请 Let’s Encrypt 证书。
安装 Certbot:
apt install -y certbot python3-certbot-nginx
申请证书:
certbot --nginx -d search.example.com
根据提示输入邮箱并确认即可。
查看证书自动续期:
systemctl status certbot.timer
测试自动续期:
certbot renew --dry-run
配置成功后访问:
https://search.example.com
十七、常用运维命令
查看服务状态
cd /opt/ai-search/Perplexica
docker compose ps
查看实时日志
docker compose logs -f
停止服务
docker compose down
启动服务
docker compose up -d
重启服务
docker compose restart
更新代码
cd /opt/ai-search/Perplexica
git pull
docker compose down
docker compose up -d --build
清理无用镜像
docker system prune -f
查看端口占用
ss -tunlp
如果发现 3000 端口被占用,可以查看具体进程:
lsof -i:3000
如果没有安装 lsof:
apt install -y lsof
十八、SearXNG 单独测试
如果 AI 搜索结果为空,建议先测试 SearXNG 是否正常。
查看 SearXNG 容器:
docker compose ps
进入容器网络测试:
docker compose logs -f searxng
如果 SearXNG 映射了宿主机端口,可以浏览器访问:
http://服务器IP:8080
也可以用 curl 测试:
curl "http://127.0.0.1:8080/search?q=docker&format=json"
如果返回 JSON 搜索结果,说明 SearXNG 正常。
如果返回 403、429 或没有结果,可能是搜索源限制、网络问题或 SearXNG 配置问题。
十九、常见问题排查
1. 页面打不开
先检查容器:
docker compose ps
再检查端口:
ss -tunlp | grep 3000
查看日志:
docker compose logs -f
还要确认云服务器安全组是否开放 3000 端口。
2. 页面能打开,但搜索没有结果
重点检查 SearXNG:
docker compose logs -f searxng
测试搜索接口:
curl "http://127.0.0.1:8080/search?q=AI&format=json"
如果 SearXNG 不通,Perplexica 就无法获取搜索结果。
3. 大模型调用失败
检查 API Key 是否正确,确认模型名称是否可用。
例如 DeepSeek 可以测试:
curl https://api.deepseek.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer 你的API_KEY" \
-d '{
"model": "deepseek-chat",
"messages": [
{
"role": "user",
"content": "你好"
}
]
}'
如果返回正常 JSON,说明 API 可用。
4. Docker 拉取镜像很慢
可以配置 Docker 镜像加速器。创建配置文件:
mkdir -p /etc/docker
vim /etc/docker/daemon.json
写入示例:
{
"registry-mirrors": [
"https://docker.1ms.run",
"https://docker.m.daocloud.io"
]
}
重启 Docker:
systemctl daemon-reload
systemctl restart docker
再次启动:
cd /opt/ai-search/Perplexica
docker compose up -d
二十、安全建议
AI 搜索服务如果直接暴露在公网,建议做好安全配置。
1. 使用 HTTPS
不要长期使用 HTTP 明文访问,建议通过 Nginx + Certbot 配置 HTTPS。
2. 限制后台接口访问
如果项目有管理后台或 API 接口,建议增加访问控制。
3. 不要泄露 API Key
配置文件中的 API Key 不要提交到 GitHub,也不要截图公开。
可以设置文件权限:
chmod 600 config.toml
4. 配置反向代理访问限制
如果只是个人使用,可以在 Nginx 中限制 IP:
allow 你的公网IP;
deny all;
示例:
location / {
allow 1.2.3.4;
deny all;
proxy_pass http://127.0.0.1:3000;
}
5. 定期更新
建议定期更新系统、Docker 镜像和 Perplexica 项目:
apt update && apt upgrade -y
cd /opt/ai-search/Perplexica
git pull
docker compose down
docker compose up -d --build
二十一、完整一键部署命令参考
如果你已经准备好服务器,并希望快速部署,可以参考以下命令。
注意:以下命令适合 Ubuntu 系统,API Key 和域名需要你自行替换。
apt update && apt upgrade -y
apt install -y curl wget git vim unzip ca-certificates gnupg lsb-release lsof
timedatectl set-timezone Asia/Shanghai
curl -fsSL https://get.docker.com | bash
systemctl enable docker
systemctl start docker
docker compose version || apt install -y docker-compose-plugin
mkdir -p /opt/ai-search
cd /opt/ai-search
git clone https://github.com/ItzCrazyKns/Perplexica.git
cd Perplexica
cp sample.config.toml config.toml
vim config.toml
docker compose up -d
docker compose ps
docker compose logs -f
如果要配置 Nginx 和 HTTPS:
apt install -y nginx certbot python3-certbot-nginx
cat > /etc/nginx/sites-available/ai-search.conf <<'EOF'
server {
listen 80;
server_name search.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
EOF
ln -s /etc/nginx/sites-available/ai-search.conf /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
certbot --nginx -d search.example.com
二十二、体验优化建议
部署完成只是第一步,如果希望 AI 搜索体验更好,还可以继续优化。
1. 选择更强的模型
如果使用云端 API,推荐选择推理能力较强的模型,例如:
- GPT-4o;
- Claude 3.5 Sonnet;
- DeepSeek Chat;
- Qwen Plus;
- Qwen Max。
如果使用本地 Ollama,可以尝试:
ollama pull qwen2.5:7b
ollama pull qwen2.5:14b
ollama pull llama3.1:8b
2. 优化搜索源
SearXNG 可以配置不同搜索引擎来源。你可以根据网络环境启用或禁用某些搜索源,提高稳定性。
配置文件通常在 SearXNG 容器或挂载目录中,例如:
settings.yml
常见优化方向:
- 禁用不可用搜索源;
- 优先启用 Bing、DuckDuckGo、Wikipedia;
- 设置搜索语言;
- 调整返回结果数量。
3. 增加缓存
如果多人使用,可以考虑增加缓存层,减少重复搜索和重复模型调用成本。
4. 接入企业知识库
AI 搜索除了联网搜索,还可以接入企业内部文档,例如:
- PDF 文档;
- Markdown 文档;
- Notion;
- Confluence;
- 飞书文档;
- 企业网站;
- 数据库内容。
这类功能通常需要结合向量数据库,例如:
- Milvus;
- Qdrant;
- Weaviate;
- Elasticsearch;
- PostgreSQL + pgvector。
二十三、总结
通过本文的步骤,我们完成了一个私有化 AI 搜索系统的部署,核心流程包括:
- 准备 Ubuntu 服务器;
- 安装 Docker 和 Docker Compose;
- 克隆 Perplexica 项目;
- 配置 SearXNG 搜索引擎;
- 配置 OpenAI、DeepSeek、通义千问或 Ollama 模型;
- 使用 Docker Compose 启动服务;
- 配置 Nginx 域名访问;
- 使用 Certbot 开启 HTTPS;
- 掌握常见运维和排错命令。
这套方案的优势是部署简单、可控性强、成本灵活。个人用户可以用它替代传统搜索入口,技术团队可以用它搭建内部资料检索平台,企业也可以在此基础上扩展知识库问答、行业情报分析和自动化信息整理能力。
如果你只是快速体验,使用云端模型 API 最简单;如果你更重视数据隐私,可以进一步接入 Ollama,实现更高程度的本地化 AI 搜索。