当前位置: 首页 > news >正文

Ubuntu20.04系统安装,使用系统盘安装

1、系统安装

Ubuntu20.04系统安装,使用系统盘安装

查看ubuntu系统版本

lsb_release -a:显示发行版名称、版本号及代号

(base) root@ai-System-Product-Name:/media/ai/wh/clash-for-linux-master# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.6 LTS
Release:	20.04
Codename:	focal

查看Ubuntu系统内核版本

uname -r:直接显示内核版本

(base) root@ai-System-Product-Name:/media/ai/wh/clash-for-linux-master# uname -r
5.15.0-139-generic

2、NVIDIA驱动安装

Ubuntu操作系统安装Nvidia GPU驱动-物理机-用户指南-实例-GPU驱动安装说明 - 天翼云

Ubuntu操作系统安装Nvidia GPU驱动

验证驱动是否正常安装

nvidia-smi

安装cuna工具包(一般情况选择带有系统版本的CUDA就能直接安装完)

CUDA Toolkit Archive | NVIDIA Developer

检查 CUDA Toolkit 是否安装成功

nvcc --version

操作系统及软件相关

安装检查命令
系统驱动

uname -r 

C/C++编译运行环境

检查命令  gcc --version 、 g++ --version 、 cmake --version 

 Pytorch

Python -c "import torch" 

Langchain

Python -c "import langchain" 

 Stable - diffusion

通过查看代码仓库有无文件判断

Lora微调框架

通过查看代码仓库有无文件判断

 Dockers容器组件

检查命令  sudo systemctl status docker 、 Docker --version 

Python

python --version 

 2.1 Pytorch安装

PyTorch官网下载链接:Start Locally | PyTorch

离线“:https://download.pytorch.org/whl/torch/

首先更新系统并安装必要的工具和依赖:

sudo apt update && sudo apt upgrade -y
sudo apt install python3-pip python3-dev build-essential libssl-dev libffi-dev -y

确保pip是最新版本:

pip3 install --upgrade pip

直接安装

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124

2.2 安装Miniconda的步骤

Miniconda - Anaconda

下载Miniconda安装脚本

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh

运行安装脚本

bash Miniconda3-latest-Linux-x86_64.sh

按照提示进行操作:

  • 按Enter查看许可协议

  • 输入yes接受许可条款

  • 选择安装位置(默认在~/miniconda3

  • 是否初始化Miniconda(建议选择yes

激活conda

source ~/.bashrc

验证安装

conda –version

配置环境(可选)

conda config --set auto_activate_base false

添加清华镜像源(国内推荐)

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

创建和管理环境

conda create -n xx_conda python=3.9conda activate xx_conda
conda activate xx_conda

卸载 Miniconda(如需)

rm -rf ~/miniconda3

清理 ~/.bashrc 中的 Conda 初始化代码(删除相关行)

模型下载

pip install modelscope

modelscope download --model Valdemardi/DeepSeek-R1-Distill-Qwen-32B-AWQ

3、编译开发组件安装

apt update 安装基本开发组件

组件名称安装命令检查命令

GUN调试工具(gdb)

 sudo apt install gdb 

gdb --version 

内存调试分析工具(valgrind)

sudo apt install valgrind 

valgrind --version         

格式化C/C++代码的工具(clang - format)

 sudo apt install clang - format 

 clang - format --version

 C/C++代码格式化和美化工具(astyle)

sudo apt install astyle 

astyle --version 

版本控制工具组件(git)

 sudo apt install git 

git --version 

ssh设备访问工具

 sudo apt install openssh - client (客户端 ),

sudo apt install openssh - server (服务端 )

ssh -V 

网络工具组件(scp是ssh附带工具 )

 scp -V 

下载网络内容的非交互工具(wget)

 sudo apt install wget 

wget --version 

容器镜像仓库工具组件(docker)

sudo apt-get update && sudo apt-get install docker - ce docker - ce - cli containerd.io 

docker --version 

系统分析与监控工具组件(性能分析 = perf)

sudo apt install linux - tools - common linux - tools - generic 

perf --version 

系统性能分析(sysstat)

sudo apt install sysstat 

sar -V 

增强的交互式系统监控工具(htop)

sudo apt install htop 

 htop --version 

网络带宽工具组件(nload)

sudo apt install nload 

nload --version 

文本编辑工具(vim)

sudo apt install vim 

 vim --version 

命令文本编辑器工具(nano)

 sudo apt install nano 

nano --version 

开发库和依赖工具组件(build - essential/tree )

sudo apt install build - essential tree 

 tree --version 

树状图列出目录内容工具(tree)

 tree --version 

基本的网络诊断工具(ping)

一般系统自带,若缺失sudo apt install iputils - ping 

ping -V 

 ifconfig

一般系统自带,若缺失sudo apt install net - tools 

ifconfig

4、AI生态框架安装

框架名称

PyTorch

LangChainIntroduction | 🦜️🔗 LangChain
Stable DiffusionStable Diffusion API Docs | Stable Diffusion API Documentation
SAM

https://github.com/facebookresearch/segment-anything

GitCode - 全球开发者的开源社区,开源代码托管平台

Lora微调组件

4.1 LangChain-ChatChat 本地部署文档

一、系统要求

  • 操作系统:Ubuntu 20.04+

  • Python:推荐 3.9 或 3.10

  • 内存:建议 ≥ 8GB

  • GPU(可选):用于部署大语言模型(如 Qwen、ChatGLM)

  • Conda(推荐)或 venv 用于隔离环境

二、环境准备

1. 安装基础依赖

sudo apt update
sudo apt install -y git wget curl build-essential

2. 安装 Anaconda 或 Miniconda(推荐)

从官网下载安装:https://docs.conda.io/en/latest/miniconda.html

3. 创建并激活环境

conda create -n chatchat python=3.10 -y conda activate chatchat

三、克隆项目

git clone https://github.com/chatchat-space/langchain-chatchat.git
cd langchain-chatchat
 

四、安装依赖

pip install -r requirements.txt

安装较慢时可使用国内镜像:

pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

五、下载语言模型

这里为了方便调用选择小模型

手动下载

Hugging Face 或模型官方仓库下载模型文件

六、配置启动参数

编辑 .env 文件(或创建)设置默认参数:

LLM_MODEL=Qwen3-0.6B-Base
VECTOR_STORE_TYPE=faiss
EMBEDDING_MODEL=text2vec-base-chinese

七、运行服务

项目使用 FastAPI + Web UI + 后端服务,推荐使用一键脚本:

# 启动服务(Web UI + FastAPI 后台)
bash start.sh

等待约 30~60 秒后,打开浏览器访问:

http://localhost:7860

八、测试功能

  • 上传 PDF 文档、TXT、DOCX

  • 输入自然语言提问

  • 支持多模型切换

  • 支持上下文记忆、插件功能、对话历史

4.2 SAM 部署流程文档

一、系统要求

  • 操作系统:Ubuntu 20.04

  • Python:推荐使用 Python 3.9+

  • 显卡驱动:NVIDIA GPU + CUDA 11.7 或以上

  • 内存:≥8GB

  • 显卡显存:≥6GB(建议使用 12GB 以上显存)

二、环境准备

1. 安装系统依赖

sudo apt update
sudo apt install -y git wget unzip build-essential libgl1-mesa-glx

2. 创建 Python 虚拟环境

# 安装 Python 虚拟环境工具(可选)
sudo apt install python3.9-venv

# 创建并激活虚拟环境
python3.9 -m venv sam_env
source sam_env/bin/activate

三、安装 PyTorch

请根据你的 CUDA 版本从 PyTorch 获取对应安装指令。以下为示例:

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

四、克隆 SAM 仓库

git clone https://github.com/facebookresearch/segment-anything.git
cd segment-anything
pip install -e .

五、下载 SAM 模型权重

可以从 Meta 官方提供的地址下载权重模型(需要梯子):

# 创建模型目录
mkdir -p ~/models/sam

# 示例下载 ViT-H SAM 模型
wget https://dl.fbaipublicfiles.com/s        egment_anything/sam_vit_h_4b8939.pth -P ~/models/sam

测试部署(命令行接口)

创建一个测试脚本 run_sam.py

import torch
from segment_anything import sam_model_registry, SamPredictor
import cv2# 加载模型
sam = sam_model_registry["vit_h"](checkpoint="/home/yourname/models/sam/sam_vit_h_4b8939.pth")
sam.to("cuda")predictor = SamPredictor(sam)# 加载图像
image = cv2.imread("test.jpg")
predictor.set_image(image)# 示例点
input_point = [[500, 375]]
input_label = [1]masks, scores, logits = predictor.predict(point_coords=input_point,point_labels=input_label,multimask_output=True,
)# 保存掩码图
import matplotlib.pyplot as plt
import numpy as npfor i, mask in enumerate(masks):plt.imsave(f"mask_{i}.png", mask, cmap="gray")

运行:

python run_sam.py

七、(可选)部署为 Web 服务

你可以使用 gradio 快速部署一个 Web UI:

pip install gradio opencv-python

# 创建 web_app.py

import gradio as gr
import cv2
from segment_anything import sam_model_registry, SamPredictorsam = sam_model_registry["vit_h"](checkpoint="/home/yourname/models/sam/sam_vit_h_4b8939.pth")
sam.to("cuda")
predictor = SamPredictor(sam)def segment(image, x, y):predictor.set_image(image)masks, _, _ = predictor.predict(point_coords=[[x, y]], point_labels=[1], multimask_output=False)return masks[0]gr.Interface(fn=segment,inputs=["image", gr.Number(label="X"), gr.Number(label="Y")],outputs="image").launch()

运行:

python web_app.py

八、常见问题

问题解决方法
RuntimeError: CUDA out of memory使用较小的模型(如 ViT-B)、减小图像尺寸
cv2.error: OpenCV确保图像路径正确,格式为 RGB
下载权重失败使用代理或科学上网工具

九、总结

部署 SAM 的关键在于:

  1. 安装兼容的 CUDA + PyTorch 环境;

  2. 下载官方模型权重;

  3. 使用 segment_anything 提供的 API 接口进行加载与预测;

  4. 可选:集成 Web 服务或 API 接口用于后续调用。

4.3 Stable Diffusion 部署文档

使用 CompVis 官方仓库(或 Stability AI 的扩展版):

git clone https://github.com/CompVis/stable-diffusion.git
cd stable-diffusion

五、安装依赖

pip install -r requirements.txt

如果你看到 transformersdiffusers 缺失,可以补装:

pip install diffusers transformers accelerate

六、下载模型权重

下载文件

https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt

七、运行图像生成(命令行)

python scripts/txt2img.py \
    --prompt "a fantasy castle in the sky" \
    --plms \
    --ckpt models/ldm/stable-diffusion-v1/model.ckpt \
    --config configs/stable-diffusion/v1-inference.yaml \
    --outdir outputs/ \
    --n_samples 1 \
    --n_iter 1 \
    --H 512 --W 512 \
    --ddim_steps 50
 

八、输出结果查看

图片会保存在 outputs/ 文件夹中。

九、测试示例

python scripts/txt2img.py \
  --prompt "a cyberpunk cityscape at night, neon lights, rain" \
  --ckpt models/ldm/stable-diffusion-v1/model.ckpt \
  --config configs/stable-diffusion/v1-inference.yaml \
  --outdir outputs/
 

十、常见问题解决

问题解决方案
CUDA out of memory尝试减小图像尺寸(如 384x384)、使用 --n_samples 1
No module named xformers可选模块,pip install xformers(需编译)
权重文件太大下载失败可手动从浏览器下载 .ckpt 文件,放入指定目录

十一、可选扩展

  • 使用 diffusers + transformers 替代原生结构,部署更轻量

  • 部署 Gradio Web UI 示例(需要我可补充)

  • Docker 化部署

  • 使用自动 Web UI(如 A1111 或 ComfyUI)

总结

Stable Diffusion 原生部署流程为:

  1. 安装环境(Python + PyTorch)

  2. 克隆项目并安装依赖

  3. 下载模型权重

  4. 使用 txt2img.py 脚本生成图像

4.4 Lora微调框架安装

5、AI加速框架安装

加速组件
vLLMvLLM - vLLM

 vllm安装

6、KVM虚拟化和Docker容器安装

容器化组件
Dockerhttps://docs.docker.com/

docker-compose

Harbor镜像仓库

Harbor docs | Harbor 2.4 Documentation

6.1 Dockers容器组件安装

6.2 KVM虚拟化

http://www.xdnf.cn/news/668575.html

相关文章:

  • 在thinkphp5.0中。单表使用 model clone 时就会有问题。 需要使用 alias(), 否则会报错。
  • 防腐防爆配电箱:采用 304 不锈钢材质,抗腐蚀、抗冲击,适应恶劣工况
  • 第三届黄河流域网安技能挑战赛复现
  • 2025吉林CCPC 题解(前六题)
  • [图文]图6.3会计事项-Fowler分析模式的剖析和实现
  • docker 搭建php 开发环境 添加扩展redis、swoole、xdebug(1)
  • Qt不同布局添加不同控件
  • 模型评价指标介绍
  • Spark、Hadoop对比
  • Excel 操作 转图片,转pdf等
  • Go语言中的浮点数类型详解
  • Kotlin 中 Lambda 表达式的语法结构及简化推导
  • 学习黑客 Metasploit 主要组件之Encoder
  • MS1826+MS2131 1080P@60Hz 4路输入输出USB3.0采集
  • 通过ansible playbook创建azure 资源
  • 解决ubuntu服务器未使用空间的分配
  • c++复习_第一天(引用+小众考点)
  • c#,vb.net使用OleDb写入Excel异常:字段太小而不能接受所要添加的数据的数量
  • etcd:高可用,分布式的key-value存储系统
  • 鸿蒙OSUniApp 实现登录状态管理与持久化#三方框架 #Uniapp
  • 如何通过ES实现SQL风格的查询?
  • linux快速入门-VMware安装linux,配置静态ip,使用服务器连接工具连接,快照和克隆以及修改相关配置信息
  • 【机器学习基础】机器学习入门核心算法:逻辑回归(Decision Tree)
  • 第一章 LVS 负载均衡群集核心概念与体系架构
  • 计算机网络实验课(三)——直接使用数据构造以太网帧,打包并发送|使用SharpPcap库函数构造以太网帧,并发送出去
  • 哈希算法:原理、应用、安全演进与推荐
  • 学习路之PHP--easyswoole入门及文件热加载
  • 织梦dedecms arclist最新发布日期显示红色
  • Android 15 控制亮屏灭屏接口实现
  • WPF【11_2】WPF实战-重构与美化(Entity Framework)-示例