如何提速CentOS部署Stable Diffusion

AI技术
小华
2026-09-20

CentOS 上部署 Stable Diffusion 时,提速通常体现在 系统环境、依赖安装、模型加载、推理性能 四个方面。下面给你一套可落地的提速方案(CentOS 7/8 通用)。

一、系统层面提速(基础)

1. 使用国内镜像源

CentOS 默认源很慢,先换源:

# CentOS 7
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache

或使用清华源(推荐服务器):

https://mirrors.tuna.tsinghua.edu.cn/help/centos/

2. 更新内核 & 系统

yum update -y

3. 关闭 SELinux(避免权限问题)

setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

二、Python 环境提速(非常关键)

✅ 不要用系统 Python

CentOS 自带 Python 很旧(2.7 / 3.6),会巨慢。

使用 Miniconda(强烈推荐)

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

创建专用环境:

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

三、依赖安装提速(pip 加速)

使用国内 pip 镜像

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

或临时:

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

四、GPU 加速(核心提速点)

1. 安装 NVIDIA 驱动

nvidia-smi

若无输出,安装驱动(CentOS):

yum install -y gcc kernel-devel
sh NVIDIA-Linux-x86_64-*.run

2. 安装 CUDA + cuDNN(推荐版本)

Stable Diffusion 常用:

  • CUDA 11.8
  • PyTorch 2.x
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

验证:

python -c "import torch; print(torch.cuda.is_available())"

✅ 返回 True 才算成功

五、Stable Diffusion 部署提速(WebUI)

推荐:Automatic1111

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

使用国内加速

export COMMANDLINE_ARGS="--xformers --no-half-vae"

启动:

./webui.sh

⚡ 关键加速参数

--xformers        # 显存 & 速度提升(必须)
--medvram         # 显存 < 8G
--lowvram         # 显存 < 4G
--opt-sdp-attention

六、模型加载提速

1. 模型放 SSD / NVMe

mv models /data/ssd/models
ln -s /data/ssd/models ~/stable-diffusion-webui/models

2. 使用 safetensors(比 ckpt 快)

  • 优先下载 .safetensors
  • 启动更快、更安全

七、网络 & 下载提速

HuggingFace 加速

export HF_ENDPOINT=https://hf-mirror.com

Git 加速

git config --global url."https://ghproxy.com/https://github.com/".insteadOf "https://github.com/"

八、常见 CentOS 坑(避免卡死)

问题解决
glibc 太低用 conda 环境
缺少 libGLyum install mesa-libGL
端口不通防火墙放行
中文乱码安装中文字体

九、整体提速总结(重点)

必做项

  • Miniconda + Python 3.10
  • CUDA + xformers
  • 国内 pip / git 镜像
  • SSD 存模型

提速效果

  • 安装时间 ↓ 50%
  • 推理速度 ↑ 30%~80%
  • 显存占用 ↓ 20%

如果你愿意,我可以:

  • ✅ 给你 一键安装脚本(CentOS)
  • ✅ 按 显存大小 定制参数
  • ✅ 教你 无 GUI 服务器部署

你现在的 CentOS 版本 + 显卡型号 是多少?

亿速云提供售前/售后服务

售前业务咨询

售后技术保障

400-100-2938

7*24小时售后电话

官方微信小程序