乐于分享
好东西不私藏

Linux AI 工具实战:在本地搭建你的私人 AI 助手

Linux AI 工具实战:在本地搭建你的私人 AI 助手

Linux AI 工具实战:在本地搭建你的私人 AI 助手

上一篇文章讲了 Linux 办公效率提升,今天我们来聊点更前沿的:如何在 Linux 上搭建自己的 AI 环境

引言:为什么要本地部署 AI?

上个月,ChatGPT 突然无法访问:

我的反应

• "怎么办?我有重要项目在用 AI!"

• "我的代码审查、文档生成都依赖它!"

• "数据都上传到云端,安全吗?"

解决方案

我在 Linux 服务器上搭建了本地 AI 环境,现在:

• ✅ 完全离线:不需要互联网也能用

• ✅ 数据安全:所有数据都在本地

• ✅ 成本为零:一次性投入,永久使用

• ✅ 可定制:可以训练自己的模型

今天这篇文章,就是教你如何在 Linux 上从零搭建 AI 环境,让你拥有一个完全属于自己的私人 AI 助手


一、为什么选择 Linux 做 AI 开发?

1.1 Linux vs Windows:AI 开发对比

| 特性 | Windows | Linux | 优势 |

|------|---------|-------|------|

| GPU 驱动 | 需要手动安装 CUDA | 包管理器一键安装 | Linux 更简单 |

| Docker 支持 | WSL2 不稳定 | 原生支持 | Linux 更稳定 |

| 深度学习框架 | 安装复杂 | pip/apt 一键安装 | Linux 更快 |

| 性能 | 有性能损耗 | 原生性能最佳 | Linux 更高效 |

| 远程训练 | GUI 占资源 | 命令行远程 SSH | Linux 更灵活 |

1.2 Linux AI 开发的优势

开箱即用的工具链

• Python 3.11+:系统自带或一键安装

• CUDA/cuDNN:包管理器直接安装

• Docker/Podman:容器化部署

• Jupyter Lab:交互式开发环境

强大的生态系统

• PyTorch、TensorFlow:官方优先支持 Linux

• Hugging Face:模型库一键下载

• Ollama:本地运行大模型

• Stable Diffusion:AI 绘图

成本优势

• 免费的 Linux 系统

• 开源的 AI 工具

• 复用现有服务器

• 云服务器更便宜


二、环境准备(5 个步骤)

2.1 硬件要求

最低配置(CPU 推理):

• CPU:4 核心以上

• 内存:8GB(推荐 16GB)

• 硬盘:50GB SSD

推荐配置(GPU 加速):

• GPU:NVIDIA RTX 3060 或更高(12GB+ VRAM)

• 内存:32GB

• 硬盘:200GB NVMe SSD

云服务器选择

• 阿里云:GPU 实例(ecs.gn6v-c8g1.2xlarge)

• 腾讯云:GN10Xp 实例

• AWS:p3.2xlarge(V100)

• Google Cloud:n1-standard-4 + T4 GPU

2.2 系统配置

更新系统

# Ubuntu/Debian sudo apt update && sudo apt upgrade -y  # CentOS/RHEL sudo yum update -y  # Arch Linux sudo pacman -Syu

安装基础工具

# 开发工具 sudo apt install build-essential git curl wget vim htop  # Python 环境 sudo apt install python3 python3-pip python3-venv  # CUDA 工具包(如果有 NVIDIA GPU) sudo apt install nvidia-cuda-toolkit nvidia-driver-535  # 验证 GPU nvidia-smi

配置 Python 虚拟环境

# 创建项目目录 mkdir -p ~/ai-projects cd ~/ai-projects  # 创建虚拟环境 python3 -m venv ai-env  # 激活环境 source ai-env/bin/echo "source ~/ai-projects/ai-env/bin/activate" >> ~/.bashrc

2.3 安装 AI 框架

PyTorch(推荐):

# CPU 版本 pip install torch torchvision torchaudio  # GPU 版本(CUDA 11.8) pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118  # 验证安装 python3 << EOF import torch print(f"PyTorch 版本: {torch.__version__}") print(f"CUDA 可用: {torch.cuda.is_available()}") if torch.cuda.is_available():     print(f"GPU 数量: {torch.cuda.device_count()}")     print(f"GPU 名称: {torch.cuda.get_device_name(0)}") EOF

TensorFlow

# CPU 版本 pip install tensorflow-cpu  # GPU 版本 pip install tensorflow[and-cuda]  # 验证安装 python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices())"

2.4 安装 Ollama(本地大模型)

什么是 Ollama

Ollama 是一个工具,让你在本地运行大语言模型(如 Llama 3、Qwen、DeepSeek),无需联网。

安装 Ollama

# 安装 curl -fsSL https://ollama.com/install.sh | sh  # 验证安装 ollama --version

下载模型

# Llama 3(8B 参数,需要 16GB 内存) ollama pull llama3  # Qwen 2(7B 参数,中文优化) ollama pull qwen2  # DeepSeek Coder(代码生成) ollama pull deepseek-coder  # 查看已安装的模型 ollama list

运行模型

# 交互式对话 ollama run llama3  # 一次性提问 ollama run llama3 "解释一下什么是机器学习"  # 流式输出 ollama run qwen2 "用中文介绍一下你自己"

2.5 安装 Stable Diffusion(AI 绘图)

什么是 Stable Diffusion

Stable Diffusion 是一个开源的 AI 绘图工具,可以根据文字描述生成高质量图片。

环境准备

# 安装依赖 sudo apt install python3.10-venv git wget  # 克隆 Stable Diffusion WebUI git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git cd stable-diffusion-webui

启动 WebUI

# 创建虚拟环境 python3 -m venv venv source venv/bin/activate  # 安装依赖 pip install -r requirements.txt  # 启动 WebUI(会自动下载模型) ./webui.sh --listen --xformers  # 浏览器访问 # http://localhost:7860

生成图片示例

• 提示词:a beautiful sunset over the ocean, highly detailed, 4k

• 负面提示词:ugly, blurry, low quality

• 步数:30

• CFG Scale:7

高级配置

# 使用特定模型 ./webui.sh --ckpt /path/to/model.safetensors  # 启用 API 模式 ./webui.sh --listen --api  # 限制内存使用(低配置电脑) ./webui.sh --lowvram --listen

API 调用示例

import requests import json  url = "http://localhost:7860/sdapi/v1/txt2img"  payload = {     "prompt": "a futuristic city at night, cyberpunk style, highly detailed",     "negative_prompt": "ugly, blurry, low quality",     "steps": 30,     "cfg_scale": 7,     "width": 512,     "height": 512 }  response = requests.post(url, json=payload) data = response.json()  # 保存图片 import base64 with open("output.png", "wb") as f:     f.write(base64.b64decode(data["images"][0]))  print("✅ 图片已生成")

2.6 安装 Whisper(语音识别)

什么是 Whisper

OpenAI 开发的语音识别工具,支持多语言,准确率极高。

安装

pip install openai-whisper  # 或使用系统包 sudo apt install whisper

使用示例

# 转录音频(中文) whisper meeting.mp3 --model medium --language zh  # 翻译成英文 whisper meeting.mp3 --model medium --task translate  # 输出为 JSON whisper meeting.mp3 --output_format json

Python 调用

import whisper  # 加载模型 model = whisper.load_model("medium")  # 转录音频 result = model.transcribe("meeting.mp3", language="zh")  # 打印结果 print(result["text"])  # 保存为文件 with open("meeting.txt", "w") as f:     f.write(result["text"])  # 获取时间戳 for segment in result["segments"]:     print(f"[{segment['start']:.2f}s -> {segment['end']:.2f}s] {segment['text']}")

批量处理

import whisper import os  model = whisper.load_model("base")  # 批量处理音频文件 audio_dir = "./audio_files" for filename in os.listdir(audio_dir):     if filename.endswith('.mp3'):         filepath = os.path.join(audio_dir, filename)                  # 转录         result = model.transcribe(filepath)                  # 保存文本         output_file = filepath.replace('.mp3', '.txt')         with open(output_file, 'w') as f:             f.write(result["text"])                  print(f"✅ 已处理: {filename}")

三、本地 AI 助手实战(3 个场景)

3.1 场景一:代码助手

需求

自动生成代码、审查代码、解释代码逻辑。

实现方案

# 安装 Continue(VS Code 插件) code --install-source-extension Continue.continue  # 或使用命令行 ollama run deepseek-coder "用 Python 写一个快速排序"

示例对话

$ ollama run deepseek-coder  >>> 写一个 Python 函数计算斐波那契数列  def fibonacci(n):     """计算斐波那契数列的第 n 项"""     if n <= 1:         return n     a, b = 0, 1     for _ in range(2, n + 1):         a, b = b, a + b     return b  # 测试 for i in range(10):     print(f"F({i}) = {fibonacci(i)}")

高级用法

# code_assistant.py import ollama  def code_review(code):     """使用 AI 审查代码"""     prompt = f"请审查以下代码,指出潜在问题和改进建议:\n\n{code}"          response = ollama.generate(model='deepseek-coder', prompt=prompt)     return response['response']  # 使用 code = """ def calculate(a, b):     return a + b """  print(code_review(code))

3.2 场景二:文档生成器

需求

自动生成 API 文档、README、技术文档。

实现方案

# doc_generator.py import ollama import os  def generate_readme(project_path):     """自动生成 README.md"""          # 读取代码文件     code_files = []     for root, dirs, files in os.walk(project_path):         for file in files:             if file.endswith('.py'):                 with open(os.path.join(root, file), 'r') as f:                     code_files.append(f.read())          # 生成提示词     prompt = f"""     基于以下代码,生成一个专业的 README.md 文档:          {chr(10).join(code_files[:3])}  # 只用前 3 个文件          包含以下部分:     1. 项目简介     2. 安装步骤     3. 使用方法     4. API 文档     5. 贡献指南     """          # 调用 AI     response = ollama.generate(model='llama3', prompt=prompt)          # 保存     with os.path.join(project_path, 'README.md'), 'w') as f:         f.write(response['response'])          print("✅ README.md 已生成")  # 使用 generate_readme('/path/to/project')

3.3 场景三:智能客服

需求

基于公司文档构建问答系统。

实现方案

# 安装 RAG(检索增强生成)工具 pip install chromadb sentence-transformers  # 创建知识库 python3 << 'EOF' import chromadb from sentence_transformers import SentenceTransformer  # 创建向量数据库 client = chromadb.Client() collection = client.create_collection("company_docs")  # 加载模型 model = SentenceTransformer('all-MiniLM-L6-v2')  # 添加文档 documents = [     "公司成立于 2020 年,专注于 AI 解决方案",     "产品价格:基础版 $99/月,专业版 $299/月",     "技术支持邮箱:support@example.com" ]  # 生成嵌入向量并存储 for i, doc in enumerate(documents):     embedding = model.encode(doc).tolist()     collection.add(         documents=[doc],         embeddings=[embedding],         ids=[f"doc_{i}"]     )  print("✅ 知识库已创建") EOF

问答系统

# qa_system.py import ollama import chromadb from sentence_transformers import SentenceTransformer  class QASystem:     def __init__(self):         self.client = chromadb.Client()         self.collection = self.client.get_collection("company_docs")         self.model = SentenceTransformer('all-MiniLM-L6-v2')          def ask(self, question):         """回答问题"""                  # 生成问题向量         query_embedding = self.model.encode(question).tolist()                  # 检索相关文档         results = self.collection.query(             query_embeddings=[query_embedding],             n_results=2         )                  # 构建提示词         context = "\n".join(results['documents'][0])         prompt = f"""         基于以下信息回答问题:                  {context}                  问题:{question}         """                  # 调用 LLM         response = ollama.generate(model='llama3', prompt=prompt)         return response['response']  # 使用 qa = QASystem() print(qa.ask("公司什么时候成立的?")) print(qa.ask("产品价格是多少?"))

四、AI 工具推荐(5 个神器)

4.1 Ollama:本地大模型

特点

• 支持多种模型(Llama、Qwen、Mistral)

• 命令行简单易用

• 支持 API 调用

安装和使用

# 安装 curl -fsSL https://ollama.com/install.sh | sh  # 运行 ollama run llama3  # API 调用 curl http://localhost:11434/api/generate -d '{   "model": "llama3",   "prompt": "为什么 Linux 是开发的首选?" }'

4.2 LangChain:AI 应用框架

特点

• 快速构建 AI 应用

• 支持链式调用

• 丰富的工具集成

安装

pip install langchain langchain-community

示例

from langchain.llms import Ollama from langchain.prompts import PromptTemplate  # 初始化模型 llm = Ollama(model="llama3")  # 创建提示词模板 template = PromptTemplate(     input_variables=["question"],     template="用中文回答:{question}" )  # 生成回答 result = llm.invoke(template.format(question="什么是 AI?")) print(result)

4.3 Stable Diffusion:AI 绘图

特点

• 文生图、图生图

• 开源免费

• 模型丰富

安装

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git cd stable-diffusion-webui ./webui.sh

4.4 Whisper:语音识别

特点

• OpenAI 开发

• 支持多语言

• 高准确率

安装

pip install openai-whisper  # 使用 whisper audio.mp3 --model medium --language zh

实战案例

import whisper  # 加载模型 model = whisper.load_model("medium")  # 转录音频 result = model.transcribe("meeting.mp3", language="zh")  # 保存文本 with open("meeting.txt", "w") as f:     f.write(result["text"])  print("✅ 转录完成")

4.5 Vector Database:向量数据库

ChromaDB(推荐):

pip install chromadb

Qdrant(高性能):

# Docker 部署 docker run -p 6333:6333 qdrant/qdrant

五、实战案例:从零构建 AI 应用

5.1 项目:智能代码审查工具

需求

自动审查 Python 代码,提出改进建议。

实现步骤

步骤 1:安装依赖

pip install ollama ast

步骤 2:代码分析

# code_reviewer.py import ast import ollama  class CodeReviewer:     def __init__(self):         self.model = "deepseek-coder"          def analyze_code(self, code):         """分析代码结构"""         try:             tree = ast.parse(code)                          # 统计信息             info = {                 "lines": len(code.split('\n')),                 "functions": len([node for node in ast.walk(tree) if isinstance(node, ast.FunctionDef)]),                 "classes": len([node for node in ast.walk(tree) if isinstance(node, ast.ClassDef)]),             }                          return info         except:             return None          def review_with_ai(self, code):         """使用 AI 审查代码"""                  prompt = f"""         请审查以下 Python 代码,从以下几个方面进行分析:         1. 代码质量         2. 性能问题         3. 安全隐患         4. 改进建议                  代码:         {code}                  请用中文回答。         """                  response = ollama.generate(model=self.model, prompt=prompt)         return response['response']          def generate_report(self, code):         """生成审查报告"""                  # 分析代码         info = self.analyze_code(code)                  # AI 审查         ai_review = self.review_with_ai(code)                  # 生成报告         report = f""" # 代码审查报告  ## 基础信息 - 行数:{info['lines']} - 函数数:{info['functions']} - 类数:{info['classes']}  ## AI 审查意见 {ai_review}         """                  return report  # 使用 reviewer = CodeReviewer()  code = """ def calculate_sum(numbers):     result = 0     for num in numbers:         result += num     return result """  print(reviewer.generate_report(code))

步骤 3:运行

python3 code_reviewer.py

5.2 项目:文档问答系统

需求

基于公司文档构建智能问答系统。

完整实现

# doc_qa.py import ollama import chromadb from sentence_transformers import SentenceTransformer import os  class DocQA:     def __init__(self):         self.client = chromadb.Client()         self.model = SentenceTransformer('all-MiniLM-L6-v2')         self.llm = "llama3"          def add_document(self, text, doc_id):         """添加文档到知识库"""                  # 生成嵌入向量         embedding = self.model.encode(text).tolist()                  # 存储到向量数据库         collection = self.client.get_or_create_collection("docs")         collection.add(             documents=[text],             embeddings=[embedding],             ids=[doc_id]         )                  print(f"✅ 文档 {doc_id} 已添加")          def load_directory(self, directory):         """加载目录中的所有文档"""                  collection = self.client.get_or_create_collection("docs")                  for filename in os.listdir(directory):             if filename.endswith('.txt'):                 filepath = os.path.join(directory, filename)                                  with open(filepath, 'r') as f:                     text = f.read()                                  # 生成嵌入向量                 embedding = self.model.encode(text).tolist()                                  # 存储                 collection.add(                     documents=[text],                     embeddings=[embedding],                     ids=[filename]                 )                                  print(f"✅ 已加载: {filename}")          def ask(self, question):         """回答问题"""                  # 生成问题向量         query_embedding = self.model.encode(question).tolist()                  # 检索相关文档         collection = self.client.get_collection("docs")         results = collection.query(             query_embeddings=[query_embedding],             n_results=3         )                  # 构建提示词         context = "\n\n".join(results['documents'][0])         prompt = f"""         基于以下文档内容回答问题。如果文档中没有相关信息,请明确说明。                  文档内容:         {context}                  问题:{question}                  回答:         """                  # 调用 LLM         response = ollama.generate(model=self.llm, prompt=prompt)         return response['response']  # 使用 qa = DocQA()  # 加载文档 qa.load_directory('./docs')  # 问答 while True:     question = input("\n问题(输入 'quit' 退出):")     if question.lower() == 'quit':         break          answer = qa.ask(question)     print(f"\n回答:{answer}")

5.3 项目:AI 内容生成器

需求

批量生成博客文章、社交媒体内容。

实现

# content_generator.py import ollama import json import random  class ContentGenerator:     def __init__(self):         self.model = "llama3"          def generate_blog_post(self, topic, tone="professional"):         """生成博客文章"""                  prompt = f"""         写一篇关于"{topic}"的博客文章,要求:         1. 语调:{tone}         2. 长度:800-1000 字         3. 结构:引言、正文(3-5 个小节)、结论         4. 风格:通俗易懂,避免过于技术化                  请用 Markdown 格式输出。         """                  response = ollama.generate(model=self.model, prompt=prompt)         return response['response']          def generate_social_media(self, topic, platform="twitter"):         """生成社交媒体内容"""                  if platform == "twitter":             max_length = 280             style = "简洁有力,使用表情符号"         elif platform == "linkedin":             max_length = 3000             style = "专业,有深度"         else:             max_length = 2200             style = "友好,互动性强"                  prompt = f"""         为{platform}写一篇关于"{topic}"的帖子,要求:         1. 长度:不超过{max_length}字符         2. 风格:{style}         3. 包含相关标签         """                  response = ollama.generate(model=self.model, prompt=prompt)         return response['response']          def generate_product_description(self, product_name, features):         """生成产品描述"""                  features_text = "\n".join([f"- {f}" for f in features])                  prompt = f"""         为以下产品写一个吸引人的描述:                  产品名称:{product_name}         主要功能:         {features_text}                  要求:         1. 突出卖点         2. 语言生动         3. 长度:200-300 字         """                  response = ollama.generate(model=self.model, prompt=prompt)         return response['response']  # 使用示例 generator = ContentGenerator()  # 生成博客文章 blog_post = generator.generate_blog_post("人工智能在医疗领域的应用") with open("blog_post.md", "w") as f:     f.write(blog_post)  # 生成社交媒体内容 twitter_post = generator.generate_social_media("AI 辅助编程", "twitter") print("Twitter 内容:") print(twitter_post)  # 生成产品描述 product_desc = generator.generate_product_description(     "智能代码审查工具",     ["自动检测代码漏洞", "提供优化建议", "支持多种编程语言"] ) print("\n产品描述:") print(product_desc)

5.4 项目:智能会议助手

需求

自动记录会议内容、生成会议纪要、提取行动项。

完整实现

# meeting_assistant.py import whisper import ollama import json from datetime import datetime  class MeetingAssistant:     def __init__(self):         self.whisper_model = whisper.load_model("medium")         self.llm = "llama3"          def transcribe_audio(self, audio_file):         """转录音频"""                  print("🎙️ 正在转录音频...")         result = self.whisper_model.transcribe(audio_file, language="zh")                  transcript = {             "text": result["text"],             "segments": result["segments"],             "duration": result["segments"][-1]["end"] if result["segments"] else 0         }                  print(f"✅ 转录完成,时长:{transcript['duration']/60:.1f} 分钟")         return transcript          def generate_summary(self, transcript):         """生成会议纪要"""                  prompt = f"""         请根据以下会议转录内容,生成一份结构化的会议纪要。                  会议内容:         {transcript['text']}                  请包含以下部分:         1. 会议主题         2. 主要讨论点(3-5 个)         3. 达成的共识         4. 行动项(Action Items)及负责人         5. 下次会议时间(如有)                  请用 Markdown 格式输出。         """                  print("📝 正在生成会议纪要...")         response = ollama.generate(model=self.llm, prompt=prompt)                  return response['response']          def extract_action_items(self, transcript):         """提取行动项"""                  prompt = f"""         从以下会议内容中提取所有行动项(Action Items)。                  会议内容:         {transcript['text']}                  请按以下格式输出 JSON:         {{             "action_items": [                 {{                     "task": "任务描述",                     "assignee": "负责人",                     "deadline": "截止日期",                     "priority": "优先级(高/中/低)"                 }}             ]         }}                  只输出 JSON,不要有其他内容。         """                  print("✅ 正在提取行动项...")         response = ollama.generate(model=self.llm, prompt=prompt)                  try:             action_items = json.loads(response['response'])             return action_items         except:             # 如果 AI 返回的不是有效 JSON,手动解析             return {"action_items": []}          def process_meeting(self, audio_file, output_dir="./meetings"):         """完整处理会议"""                  # 创建输出目录         os.makedirs(output_dir, exist_ok=True)                  # 生成时间戳         timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")                  # 1. 转录音频         transcript = self.transcribe_audio(audio_file)                  # 保存转录文本         transcript_file = os.path.join(output_dir, f"{timestamp}_transcript.txt")         with open(transcript_file, 'w') as f:             f.write(transcript['text'])                  # 2. 生成会议纪要         summary = self.generate_summary(transcript)                  # 保存会议纪要         summary_file = os.path.join(output_dir, f"{timestamp}_summary.md")         with open(summary_file, 'w') as f:             f.write(summary)                  # 3. 提取行动项         action_items = self.extract_action_items(transcript)                  # 保存行动项         action_file = os.path.join(output_dir, f"{timestamp}_actions.json")         with open(action_file, 'w') as f:             json.dump(action_items, f, ensure_ascii=False, indent=2)                  print(f"\n✅ 会议处理完成!")         print(f"📄 转录文本:{transcript_file}")         print(f"📋 会议纪要:{summary_file}")         print(f"✅ 行动项:{action_file}")                  return {             "transcript": transcript_file,             "summary": summary_file,             "action_items": action_file         }  # 使用示例 assistant = MeetingAssistant()  # 处理会议录音 result = assistant.process_meeting("team_meeting.mp3")  # 查看会议纪要 with open(result['summary'], 'r') as f:     print(f.read())

使用场景

# 录制会议 # 使用 Audacity 或系统录音工具保存为 meeting.mp3  # 处理会议 python3 meeting_assistant.py  # 输出: # 🎙️ 正在转录音频... # ✅ 转录完成,时长:45.3 分钟 # 📝 正在生成会议纪要... # ✅ 正在提取行动项... #  # ✅ 会议处理完成! # 📄 转录文本:./meetings/20260401_143022_transcript.txt # 📋 会议纪要:./meetings/20260401_143022_summary.md # ✅ 行动项:./meetings/20260401_143022_actions.json

六、性能优化(3 个技巧)

6.1 GPU 内存优化

问题

模型太大,GPU 内存不够用。

解决方案

import torch  # 启用梯度检查点(节省 50% 内存) from torch.utils.checkpoint import checkpoint  # 使用混合精度训练(节省 40% 内存) from torch.cuda.amp import autocast, GradScaler  scaler = GradScaler()  with autocast():     output = model(input)  # 量化模型(节省 75% 内存) quantized_model = torch.quantization.quantize_dynamic(     model, {torch.nn.Linear}, dtype=torch.qint8 )

6.2 批处理优化

# 批量推理 def batch_inference(model, data, batch_size=32):     results = []          for i in range(0, len(data), batch_size):         batch = data[i:i+batch_size]                  with torch.no_grad():             output = model(batch)                  results.extend(output.cpu().numpy())          return results

6.3 模型缓存

from functools import lru_cache  @lru_cache(maxsize=128) def get_embedding(text):     """缓存文本嵌入向量"""     return model.encode(text)

七、常见问题

7.1 GPU 内存不足

解决

# 清空 GPU 缓存 pip install gpustat gpustat -cpu  # 或使用 PyTorch python3 << EOF import torch torch.cuda.empty_cache() print("GPU 缓存已清空") EOF

7.2 模型下载慢

解决

# 使用镜像站 export HF_ENDPOINT=https://hf-mirror.com  # 或手动下载后放到缓存目录 mkdir -p ~/.cache/huggingface/hub cp model/* ~/.cache/huggingface/hub/

7.3 依赖冲突

解决

# 使用虚拟环境 python3 -m venv ai-env source ai-env/bin/activate  # 或使用 Conda conda create -n ai python=3.11 conda activate ai

7.4 模型推理速度慢

问题

CPU 推理太慢,GPU 利用率低。

解决方案

# 方案 1:使用量化模型 pip install bitsandbytes  # 方案 2:启用 GPU 加速 export CUDA_VISIBLE_DEVICES=0  # 方案 3:使用更快的后端 pip install vllm  # 比原生 PyTorch 快 10x  # 使用 vLLM python3 -m vllm.entrypoints.openai.api_server --model llama3

7.5 Ollama 模型无法启动

问题

ollama run 命令报错。

解决

# 检查 Ollama 服务状态 systemctl status ollama  # 重启服务 sudo systemctl restart ollama  # 查看日志 journalctl -u ollama -n 50  # 重新安装 Ollama curl -fsSL https://ollama.com/install.sh | sh

7.6 Stable Diffusion 生成失败

问题

生成图片时报错或生成结果不佳。

解决

# 检查依赖 pip install --upgrade torch torchvision torchaudio  # 降低分辨率 ./webui.sh --listen --resolution 512x512  # 使用不同的采样器 # WebUI 界面中选择:DPM++ 2M Karras  # 清空缓存 rm -rf ~/.cache/huggingface/

7.7 网络问题:无法下载模型

问题

Hugging Face 模型下载失败。

解决

# 方案 1:使用镜像站 export HF_ENDPOINT=https://hf-mirror.com  # 方案 2:手动下载 wget https://huggingface.co/TheBloke/llama3-8B-GGUF/resolve/main/llama3-8b.Q4_K_M.gguf  # 方案 3:使用代理 export http_proxy=http://127.0.0.1:7890 export https_proxy=http://127.0.0.1:7890

八、实战案例对比:云端 vs 本地

8.1 成本对比(一年)

方案 A:使用 ChatGPT API

# 假设每天处理 1000 次 API 调用 # GPT-4 Turbo:$0.01/1K tokens # 平均每次 1000 tokens  cost_per_day = 1000 * 0.01  # $10/天 cost_per_year = cost_per_day * 365  # $3,650/年  print(f"年成本:${cost_per_year:,.2f}")

方案 B:本地部署

# 硬件成本(一次性) GPU(RTX 4060 Ti 16GB):$400 CPU(Ryzen 5 5600):$200 内存(32GB):$100 硬盘(1TB NVMe):$80 --- 总计:$780  # 电费成本 功耗:300W 每日运行:24 小时 电费:$0.12/kWh yearly_power = 0.3 * 24 * 365 * 0.12  # ~$315/年  # 总成本(第一年) total_first_year = 780 + 315  # $1,095  # 第二年起 yearly_cost = 315  # 仅电费  print(f"第一年成本:${total_first_year}") print(f"第二年起:${yearly_cost}/年")

对比结果

• ChatGPT API:每年 $3,650

• 本地部署(第一年):$1,095(节省 70%)

• 本地部署(第二年起):$315/年(节省 91%)

8.2 性能对比

| 指标 | ChatGPT API | 本地 Ollama | 本地 Llama 3 |

|------|-------------|-------------|--------------|

| 响应时间 | 2-5 秒 | 1-3 秒 | 0.5-2 秒 |

| 并发能力 | 无限 | 受限于 GPU | 受限于 GPU |

| 数据安全 | 上传云端 | 完全本地 | 完全本地 |

| 可定制性 | 低 | 中 | 高 |

| 离线使用 | ❌ | ✅ | ✅ |

8.3 适用场景

选择云端 API

• 需要最强大的模型(GPT-4)

• 不考虑数据安全

• 使用频率低

• 没有硬件预算

选择本地部署

• 数据敏感(医疗、金融)

• 长期使用(> 6 个月)

• 需要离线使用

• 需要定制模型

• 有 GPU 硬件


九、完整的生产环境配置

9.1 Docker 部署 Ollama

创建 Dockerfile

FROM ollama/ollama:latest  # 复制预下载的模型 COPY llama3.gguf /models/  # 暴露端口 EXPOSE 11434  # 启动 Ollama CMD ["ollama", "serve"]

docker-compose.yml

version: '3.8'  services:   ollama:     build: .     ports:       - "11434:11434"     volumes:       - ./models:/models     environment:       - OLLAMA_NUM_GPU=1     deploy:       resources:         reservations:           devices:             - driver: nvidia               count: 1               capabilities: [gpu]

启动

docker-compose up -d

9.2 Nginx 反向代理

配置文件

# /etc/nginx/sites-available/ai-server  server {     listen 80;     server_name ai.example.com;      location /ollama/ {         proxy_pass http://localhost:11434;         proxy_set_header Host $host;         proxy_set_header X-Real-IP $remote_addr;     }      location /stablediffusion/ {         proxy_pass http://localhost:7860;         proxy_set_header Host $host;         proxy_set_header X-Real-IP $remote_addr;                  # 增加超时时间(SD 生成慢)         proxy_read_timeout 300;     }      location /whisper/ {         proxy_pass http://localhost:5000;         proxy_set_header Host $host;         proxy_set_header X-Real-IP $remote_addr;                  # 允许上传大文件         client_max_body_size 100M;     } }

启用配置

sudo ln -s /etc/nginx/sites-available/ai-server /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx

9.3 监控和日志

安装监控工具

# GPU 监控 pip install gpustat gpustat -i 1 > /var/log/gpustat.log &  # 系统监控 sudo apt install htop iotop

日志管理

# 创建日志目录 mkdir -p /var/log/ai-services  # Ollama 日志 journalctl -u ollama -f > /var/log/ai-services/ollama.log &  # Stable Diffusion 日志 ./webui.sh --listen > /var/log/ai-services/sd.log 2>&1 &

9.4 自动化部署脚本

deploy.sh

#!/bin/bash  set -e  echo "🚀 开始部署 AI 服务..."  # 更新系统 sudo apt update && sudo apt upgrade -y  # 安装 Docker if ! command -v docker &> /dev/null; then     echo "📦 安装 Docker..."     curl -fsSL https://get.docker.com -o get-docker.sh     sudo sh get-docker.sh     sudo usermod -aG docker $USER fi  # 安装 Nginx if ! command -v nginx &> /dev/null; then     echo "📦 安装 Nginx..."     sudo apt install nginx -y fi  # 启动 Docker Compose echo "🐳 启动服务..." docker-compose up -d  # 配置 Nginx echo "🌐 配置 Nginx..." sudo cp nginx.conf /etc/nginx/sites-available/ai-server sudo ln -s /etc/nginx/sites-available/ai-server /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx  # 配置防火墙 echo "🔒 配置防火墙..." sudo ufw allow 80/tcp sudo ufw allow 443/tcp  echo "✅ 部署完成!" echo "🌐 访问 http://ai.example.com"

八、总结:开始你的 AI 之旅

8.1 学习路径

初学者(1-2 周):

1. 安装 Ollama,运行本地大模型

2. 尝试 Stable Diffusion 生成图片

3. 使用 LangChain 构建简单应用

进阶(1-2 月):

1. 学习 PyTorch/TensorFlow

2. 微调预训练模型

3. 构建生产级 AI 应用

高级(3-6 月):

1. 深入研究模型架构

2. 自定义模型训练

3. 优化推理性能

8.2 推荐资源

在线课程

• fast.ai:深度学习实战

• 吴恩达《Machine Learning》:经典入门

• Hugging Face 课程:NLP 实战

书籍

• 《动手学深度学习》(李沐)

• 《Python 深度学习》

• 《Transformer 自然语言处理》

开源项目

• Ollama:本地大模型

• LangChain:AI 应用框架

• Stable Diffusion:AI 绘图


如果觉得这篇文章有帮助,记得点赞、收藏、转发~

【互动话题】

你在 Linux 上用过哪些 AI 工具?在评论区分享你的经验,我会逐一回复~


标签:#Linux #AI #人工智能 #本地部署

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-05-12 08:06:45 HTTP/1.1 GET : https://www.yeyulingfeng.com/a/609613.html
  2. 运行时间 : 0.158554s [ 吞吐率:6.31req/s ] 内存消耗:4,753.30kb 文件加载:145
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=55c9cf8ec1b31e98206b9c73da2dab17
  1. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/autoload_static.php ( 6.05 KB )
  7. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/ralouphie/getallheaders/src/getallheaders.php ( 1.60 KB )
  10. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  11. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  12. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  13. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  14. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  15. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  16. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  17. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  18. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  19. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/guzzlehttp/guzzle/src/functions_include.php ( 0.16 KB )
  21. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/guzzlehttp/guzzle/src/functions.php ( 5.54 KB )
  22. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  23. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  24. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  25. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/provider.php ( 0.19 KB )
  26. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  27. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  28. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  29. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/common.php ( 0.03 KB )
  30. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  32. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/alipay.php ( 3.59 KB )
  33. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  34. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/app.php ( 0.95 KB )
  35. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/cache.php ( 0.78 KB )
  36. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/console.php ( 0.23 KB )
  37. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/cookie.php ( 0.56 KB )
  38. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/database.php ( 2.48 KB )
  39. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/filesystem.php ( 0.61 KB )
  40. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/lang.php ( 0.91 KB )
  41. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/log.php ( 1.35 KB )
  42. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/middleware.php ( 0.19 KB )
  43. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/route.php ( 1.89 KB )
  44. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/session.php ( 0.57 KB )
  45. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/trace.php ( 0.34 KB )
  46. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/view.php ( 0.82 KB )
  47. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/event.php ( 0.25 KB )
  48. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  49. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/service.php ( 0.13 KB )
  50. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/AppService.php ( 0.26 KB )
  51. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  52. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  53. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  54. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  55. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  56. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/services.php ( 0.14 KB )
  57. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  58. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  59. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  60. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  61. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  62. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  63. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  64. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  65. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  66. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  67. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  68. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  69. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  70. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  71. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  72. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  73. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  74. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  75. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  76. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  77. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  78. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  79. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  80. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  81. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  82. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  83. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  84. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  85. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  86. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  87. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/Request.php ( 0.09 KB )
  88. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  89. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/middleware.php ( 0.25 KB )
  90. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  91. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  92. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  93. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  94. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  95. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  96. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  97. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  98. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  99. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  100. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  101. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  102. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  103. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/route/app.php ( 3.94 KB )
  104. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  105. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  106. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/controller/Index.php ( 9.87 KB )
  108. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/BaseController.php ( 2.05 KB )
  109. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  110. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  111. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  112. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  113. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  114. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  115. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  116. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  117. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  118. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  119. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  120. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  121. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  122. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  123. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  124. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  125. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  126. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  127. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  128. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  129. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  130. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  131. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  132. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  133. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  134. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  135. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/controller/Es.php ( 3.30 KB )
  136. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  137. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  138. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  139. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  140. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  141. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  142. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  143. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  144. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/runtime/temp/c935550e3e8a3a4c27dd94e439343fdf.php ( 31.50 KB )
  145. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000491s ] mysql:host=127.0.0.1;port=3306;dbname=wenku;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000908s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000334s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000341s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000633s ]
  6. SELECT * FROM `set` [ RunTime:0.009481s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000996s ]
  8. SELECT * FROM `article` WHERE `id` = 609613 LIMIT 1 [ RunTime:0.013056s ]
  9. UPDATE `article` SET `lasttime` = 1778544405 WHERE `id` = 609613 [ RunTime:0.032464s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 64 LIMIT 1 [ RunTime:0.000770s ]
  11. SELECT * FROM `article` WHERE `id` < 609613 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000549s ]
  12. SELECT * FROM `article` WHERE `id` > 609613 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000455s ]
  13. SELECT * FROM `article` WHERE `id` < 609613 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.000681s ]
  14. SELECT * FROM `article` WHERE `id` < 609613 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.000890s ]
  15. SELECT * FROM `article` WHERE `id` < 609613 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.018614s ]
0.160555s