WSL2 Ubuntu22.04 部署配置Xinference和所有的坑

Qwen3-32B-Chat 私有部署镜像 | RTX4090D 24G 显存 CUDA12.4 优化版

本镜像基于 RTX 4090D 24GB 显存 + CUDA 12.4 + 驱动 550.90.07 深度优化,内置完整运行环境与 Qwen3-32B 模型依赖,开箱即用。

从零安装 WSL2 Ubuntu22.04 并部署Xinference和所有的坑

2025-1-20
老规矩,感谢参考文章的作者,少走了很多弯路。

参考

【1】 WSL2-Ubuntu20.04配置深度学习环境(CUDA、CUDNN、Pytorch)

【2】windows wsl2(ubuntu)使用xinference快速部署ai模型

【3】Xinference 安装使用(支持CPU、Metal、CUDA推理和分布式部署)

安装 N卡 windows 驱动

  • 注意是 windows 驱动,不是linux驱动

查看当前版本

右键/nvidia 控制面板/系统信息
Nvidia GeForce RTX4070 Super
版本 560.94

NVIDIA Windows Driver x86
https://www.nvidia.com/Download/index.aspx
https://www.nvidia.cn/drivers/lookup/

国内用 cn

NVIDIA Studio 驱动程序
GeForce Game Ready 驱动程序

Q00 选哪个? 我的环境已有驱动,先不升级。

验证下


PS C:\Users\zy-de> nvidia-smi
Mon Jan 20 13:45:26 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 560.94                 Driver Version: 560.94         CUDA Version: 12.6     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                  Driver-Model | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 4070 ...  WDDM  |   00000000:01:00.0  On |                  N/A |
|  0%   43C    P8              3W /  220W |    1610MiB /  12282MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

WSL2 安装

windows11 安装WSL2全流程

1、启用window子系统及虚拟化

2、手动安装
wsl --update
wsl --version

设置默认WSL版本
我们只使用wsl2,power shell 以管理员方式运行 # 将 WSL 默认版本设置为 WSL 2
wsl --set-default-version 2

查看当前已有的镜像
wsl -l -v

更改存储路径

wsl2迁移存储位置快捷方法适用于WSL 2.3.11以上

步骤详细
1.列出可用wsl版本
wsl --list
2.如果在使用关闭wsl
wsl --shoudown
3. 移动指定版本到指定路径
wsl --manage Ubuntu-22.04 --move <path>

安装 Ubuntu 并改存储路径

wsl --list --online
wsl --install -d Ubuntu-22.04

wsl --shutdown
wsl --list --verbose

wsl --manage Ubuntu-22.04 --move d:\WSL_Ubuntu2204

安装 miniconda(关键)

关键步骤,安装了 python 环境,为安装 cuda_toolkit 准备环境。

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

conda --version
conda info -e


conda create -n mypy310 python=3.10

conda activate mypy310
conda deactivate mypy310

安装 cuda toolkit

先切换到 conda mypy310 环境下, 不需要切换到 root 用户

注意选, wsl-Ubuntu!!!

Ubuntu不用换源, 速度挺快的。没有任何错,直接安装ok。

wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.6.3/local_installers/cuda-repo-wsl-ubuntu-12-6-local_12.6.3-1_amd64.deb
> 2G

sudo dpkg -i cuda-repo-wsl-ubuntu-12-6-local_12.6.3-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-12-6-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-6

一次成功

  • 配置环境变量
vim ~/.bashrc
export PATH=/usr/local/cuda-12.6/bin:$PATH
source ~/.bashrc

【1】 还要求配置 LD_LIBRARY_PATH, 暂时没配置
export LD_LIBRARY_PATH=/usr/local/cuda-12.6/lib64:$LD_LIBRARY_PATH

(mypy310) ***:~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Tue_Oct_29_23:50:19_PDT_2024
Cuda compilation tools, release 12.6, V12.6.85
Build cuda_12.6.r12.6/compiler.35059454_0

(base) ***:~$ nvidia-smi
Mon Jan 20 17:21:38 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 560.35.02              Driver Version: 560.94         CUDA Version: 12.6     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|

cuda toolkit 安装成功

不需要手动安装 pytorch

pytorch

conda install pytorch torchvision torchaudio pytorch-cuda=12.4 -c pytorch -c nvidia

TODO 暂时没装, cuda 是12.6, 这里显示 12.4 有点奇怪。

后续 pip 安装 Xinference 时会自动安装。

不需要手动安装 NCCL, cudaxxx 一堆东东

后续 pip 安装 Xinference 时会自动安装。

pip 部署 Xinference 而不是 docker部署

尝试过用 Docker 部署 Xinference CPU版 和 GPU 版。
Docker 用过 windows的 Docker desktop和 虚拟机的 docker。 都不行。
特别花时间,CPU版 6G, GPU 版 17G。

安装

pip install "xinference[all]"

很慢。换源。

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
pip config set install.trusted-host mirrors.aliyun.com

ok

pip install "xinference[all]"

  • 坑 nvidia-cublas-cu12 time out

再试一次ok

  • 坑 llama-cpp-python

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for llama-cpp-python
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (llama-cpp-python)

不用 xinference[all], 单独安装其它, 暂时不安装 llama-cpp-python

pip install "xinference[transformers]"
pip install "xinference[vllm]"
pip install "xinference[sglang]"

安装成功


CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python

CMake Error at vendor/llama.cpp/CMakeLists.txt:104 (message):
LLAMA_CUBLAS is deprecated and will be removed in the future.

Use GGML_CUDA instead
*** CMake configuration failed
[end of output]


CMAKE_ARGS="-DGGML_CUDA=on" pip install llama-cpp-python


cuda.so: undefined reference to `cudaGetLastError@libcudart.so.12'
collect2: error: ld returned 1 exit status

*** CMake build failed
[end of output]

llama-cpp-python 还是出错。先不用这种模型。

查看 ip

ifconfig
172.29.225.230

TODO 扩展,WSL怎样配置能固定这个ip

启动

XINFERENCE_HOME=/***/xinference XINFERENCE_MODEL_SRC=modelscope xinference-local --host 0.0.0.0 --port 9997

访问

Windows 下浏览器 172.29.225.230:9997 直接访问 ok。
不需要在 wsl Ubuntu里启动浏览器。

在这里插入图片描述

Q00 虚拟机能访问吗?
可以访问!

在这里插入图片描述

查看显卡使用


(base) ***:~$ nvidia-smi
Mon Jan 20 17:33:08 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 560.35.02              Driver Version: 560.94         CUDA Version: 12.6     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 4070 ...    On  |   00000000:01:00.0  On |                  N/A |
|  0%   41C    P8              2W /  220W |    3617MiB /  12282MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A      7792      C   /python3.10                                 N/A      |
+-----------------------------------------------------------------------------------------+

哇咔咔,终于搞定!
2025-1-20

您可能感兴趣的与本文相关的镜像

Qwen3-32B-Chat 私有部署镜像 | RTX4090D 24G 显存 CUDA12.4 优化版

Qwen3-32B-Chat 私有部署镜像 | RTX4090D 24G 显存 CUDA12.4 优化版

Qwen
文本生成
Qwen3

本镜像基于 RTX 4090D 24GB 显存 + CUDA 12.4 + 驱动 550.90.07 深度优化,内置完整运行环境与 Qwen3-32B 模型依赖,开箱即用。

根据您提供的参考资料,在 Windows 11 上部署 WSL2 Ubuntu 可以分为三个核心步骤:**启用必要功能**、**安装 WSL2Ubuntu**、**基础配置与优化**。下面将结合具体操作代码示例,为您详细拆解每个步骤 [ref_1][ref_4]。 ### **第一步:启用 Windows 功能** 此步骤在 Windows 环境下完成,目的是为 WSL2 提供运行所需的底层支持。 1. **以管理员身份打开 PowerShell**:右键点击开始菜单,选择“Windows PowerShell (管理员)”或“终端 (管理员)”。 2. **执行启用命令**:在 PowerShell 中,输入以下命令并回车。此命令会启用“适用于 Linux 的 Windows 子系统”“虚拟机平台”两个功能 [ref_4]。 ```powershell dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart ``` 3. **重启计算机**:执行完上述命令后,**必须重启电脑**以使更改生效 [ref_4]。 ### **第二步:安装 WSL2 内核与 Ubuntu 发行版** 重启后,继续在管理员 PowerShell 中操作。 1. **设置 WSL2 为默认版本**:WSL2 相比 WSL1 在性能兼容性上大幅提升,是推荐的版本 [ref_3]。 ```powershell wsl --set-default-version 2 ``` 2. **安装 Ubuntu**:使用以下命令安装 Ubuntu 22.04 LTS(长期支持版),这是目前兼容性较好的一个版本 [ref_1][ref_3]。 ```powershell wsl --install -d Ubuntu-22.04 ``` 命令执行后,系统会自动下载并安装安装完成后,会提示您为 Ubuntu 系统创建一个新的用户名密码。请注意,**此处设置的密码在输入时不会显示字符,这是正常的** [ref_1]。 ### **第三步:基础配置、验证与系统优化** 安装完成后,您可以通过在开始菜单搜索 “Ubuntu” 来启动它,并进入 Linux 终端环境。 1. **验证安装**: * 在 PowerShell 中,运行 `wsl -l -v` 可以查看已安装WSL 发行版及其状态,确认 Ubuntu 正在以 WSL2 版本运行 [ref_1]。 * 在 Ubuntu 终端中,运行 `lsb_release -a` 可以查看 Ubuntu 的具体版本信息 [ref_1]。 2. **系统更新与升级**:首次进入 Ubuntu 后,建议立即更新软件包列表并升级现有软件,以确保系统安全获取最新组件 [ref_1]。 ```bash sudo apt update && sudo apt upgrade -y ``` 3. **启用 Systemd(可选但推荐)**:许多现代 Linux 服务工具(如 Docker)依赖于 Systemd 初始化系统。WSL2 默认未启用它,可按以下步骤开启 [ref_1][ref_5]: * 在 Ubuntu 终端中创建配置文件: ```bash sudo tee /etc/wsl.conf >/dev/null <<'EOF' [boot] systemd=true EOF ``` * 关闭 WSL,然后在 Windows PowerShell 中执行: ```powershell wsl --shutdown ``` * 重新打开 Ubuntu 终端,运行 `systemctl --version`,如果显示版本号(如 systemd 249),则说明启用成功 [ref_1]。 4. **性能与存储优化(进阶)**: * **更改安装位置**:默认 WSL 镜像存储在 C 盘。如需迁移至其他盘符(如 D 盘),可在 PowerShell 中导出再导入 [ref_4]。 ```powershell # 导出发行版到指定文件 wsl --export Ubuntu-22.04 D:\wsl-ubuntu.tar # 注销原有发行版 wsl --unregister Ubuntu-22.04 # 从指定文件导入,并设置新存储路径 wsl --import Ubuntu-22.04 D:\WSL D:\wsl-ubuntu.tar --version 2 ``` * **内存与 CPU 限制**:可以在用户目录(如 `C:\Users\<你的用户名>\`)下创建 `.wslconfig` 文件,配置 WSL2 的资源使用上限,防止其占用过多主机资源 [ref_3]。 ```ini [wsl2] memory=4GB # 限制最大内存为 4GB processors=2 # 限制使用 2 个 CPU 核心 localhostForwarding=true ``` 通过以上三个步骤,您就完成了一个基础且功能完整的 WSL2 + Ubuntu 开发环境部署。这个环境可以用于运行 Linux 原生应用、进行 Python/Node.js 开发、部署 Docker 容器 [ref_5] 或运行特定的 AI 工具链(如 Xinference [ref_2]、Ollama [ref_6] 等)。后续如需安装特定开发工具(如 Node.js、Docker),可以在 Ubuntu 终端中利用 `apt` 或 `curl` 等命令继续配置
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值