ComfyUI 服务器部署

ComfyUI 服务器部署笔记(Ubuntu 20.04 + NVIDIA,Windows 浏览器访问)

目标

  • 只在服务器部署 ComfyUI(Linux + GPU 推理)
  • Windows 不装环境,直接用浏览器访问
  • SSH 隧道访问(默认不对公网开放 8188 端口,更安全)

服务器前置检查

1) 确认显卡驱动正常

1
nvidia-smi

能看到 GPU 型号、Driver Version、CUDA Version 即可。

说明:nvidia-smi 里显示的 “CUDA Version: 12.x” 是驱动支持的最高 CUDA 版本,不代表你必须装对应版本的 CUDA Toolkit。

2) 系统版本/conda 版本(可选)

1
2
lsb_release -a
conda --version

推荐安装方案(最终成功方案)

关键点:不要用 conda 安装 torch,改用 pip 官方 PyTorch wheel(cu121),避免 iJIT_NotifyEvent 等二进制符号问题。

Step 0:准备目录

假设 ComfyUI 路径是:

  • ~/comfyui/ComfyUI

没有的话:

1
2
3
mkdir -p ~/comfyui
cd ~/comfyui
git clone https://github.com/comfyanonymous/ComfyUI.git

Step 1:创建 conda 环境(Python 3.11)

1
2
3
conda create -n comfyui python=3.11 -y
conda activate comfyui
python -m pip install -U pip

不建议 Python 3.12(生态兼容性更容易踩坑)。


Step 2:用 uv 加速 pip 安装 PyTorch(GPU 版)

2.1 安装 uv

1
pip install -U uv

2.2 安装 PyTorch cu121(服务器驱动 12.x 也能用)

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

2.3 验证 torch & CUDA

1
python -c "import torch; print('torch', torch.__version__, 'cuda', torch.version.cuda, 'avail', torch.cuda.is_available())"

期望输出类似:

  • torch 2.5.1+cu121 cuda 12.1 avail True

Step 3:安装 ComfyUI 依赖

1
2
cd ~/comfyui/ComfyUI
pip install -r requirements.txt

Step 4:启动 ComfyUI(推荐只监听本机)

1
2
3
cd ~/comfyui/ComfyUI
export CUDA_VISIBLE_DEVICES=0 # 可选:指定用哪张卡(0/1)
python main.py --listen 127.0.0.1 --port 8188
  • --listen 127.0.0.1:只允许本机访问(安全)
  • --port 8188:默认端口

启动后看到类似 “Running on http://127.0.0.1:8188” 即成功。


Windows 访问方式(推荐:SSH 隧道)

方式 A:不开放端口(最安全)

在 Windows PowerShell 执行:

如果 SSH 端口是 22(默认)

1
ssh -L 8188:127.0.0.1:8188 <用户名>@<ip>

如果 SSH 不是 22(例如 2222)

1
ssh -p 2222 -L 8188:127.0.0.1:8188 <用户名>@<ip>

然后 Windows 浏览器打开:

1
http://127.0.0.1:8188

注意:SSH 窗口不能关,关了隧道就断。


一键复现(最简版命令串)

1
2
3
4
5
6
7
8
9
10
conda create -n comfyui python=3.11 -y
conda activate comfyui
pip install -U pip uv
uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

cd ~/comfyui/ComfyUI
pip install -r requirements.txt

export CUDA_VISIBLE_DEVICES=0
python main.py --listen 127.0.0.1 --port 8188

Windows:

1
ssh -L 8188:127.0.0.1:8188 <用户名>@<ip>

浏览器:
http://127.0.0.1:8188