手把手教你从0开始在服务器上部署stable diffusion

这篇具有很好参考价值的文章主要介绍了手把手教你从0开始在服务器上部署stable diffusion。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

StableDiffusion 服务器部署

0. 服务器

GPU A5000-24G 数量: 1 显存: 24 GB
CPU AMD EPYC 7551P 核心: 8 核
实例内存: 63G
系统 Ubuntu20.04

验证是否有nvidia驱动

nvidia-smi

如果没有显示出显卡信息(如下)

+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.30.02              Driver Version: 530.30.02    CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| 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 RTX A5000                On | 00000000:06:00.0 Off |                  Off |
| 30%   33C    P8               15W / 230W|      1MiB / 24564MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

则需要参考ubuntu安装nvidia驱动

https://blog.csdn.net/Perfect886/article/details/119109380

1. 使用工具

  • 远程连接服务器工具:VS Code

    https://code.visualstudio.com/Download

    • VS Code 插件:Remote
  • 文件传输工具 FileZilla

    https://www.filezilla.cn/download

2. 装python环境

下载地址:https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

./Miniconda3-latest-Linux-x86_64.sh

# 一路回车+yes

.bashrc中添加以下内容

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/usr/local/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/usr/local/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/usr/local/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/usr/local/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<
# 根据自己的安装路径去修改

3. 设置Conda、PIP国内源

  • codna
touch .condarc # 如果有了就不用了

写入以下内容

channels:
  - defaults
show_channel_urls: true
auto_activate_base: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  • pip
mkdir .pip
cd .pip
touch pip.conf

写入以下内容

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

4. 设置git加速

该方案为使用镜像网站加速git代码的下载

git config --global url."https://hub.njuu.cf/".insteadOf https://github.com
http://lib.zuotiyi.cn/tool/github.html # 从这里可以找其他镜像网站

注意,镜像网站可能存在滞后

5. 拉取代码

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

6. 创建python虚拟环境并下载依赖包

conda create -n sd python=3.11 -y
conda activate sd
# 优先安装torch会避免很多麻烦
pip install torch torchvision torchaudio
pip install -r requirements.txt 
pip install xformers

可能遇到的问题

在执行的时候可能会卡在安装 basicsr 这里,可以尝试进行以下操作

# 1.下载  tb_nightly
https://files.pythonhosted.org/packages/c0/1c/4d95416f1d9c8bab3d2c3271642084a9a93324a85b1b897ef44fb05ab734/tb_nightly-2.15.0a20230816-py3-none-any.whl
# 2. 安装tb_nightly
pip install tb_nightly-2.15.0a20230816-py3-none-any.whl

# 3.拉取basicsr源码
git clone https://github.com/XPixelGroup/BasicSR.git
# 4. 安装basicsr
cd BasicSR
pip install -r requirements.txt 
python setup.py install

单独安装完basicsr后再执行

pip install -r requirements.txt 

出现 ImportError: libGL.so.1: cannot open shared object file: No such file or directory

apt install libgl1-mesa-glx

7. 修改webui.sh

  1. 使用现有conda环境而不是新建一个环境

    在webui.sh中搜索 use_venv
    use_venv=1 (默认) -> use_venv=0
    
  2. 允许root用户运行

    在webui.sh中搜索 can_run_as_root
    can_run_as_root=0 (默认) -> can_run_as_root=1
    

8. 修改 paths_internal.py

# stable-diffusion-webui/modules/paths_internal.py
# 搜索 commandline_args
# 将 
commandline_args = os.environ.get('COMMANDLINE_ARGS', "")
# 改为
commandline_args = os.environ.get('COMMANDLINE_ARGS', "--xformers")

9. 安装TCMalloc

sudo apt-get install google-perftools

10. 下载一个模型到指定路径

https://civitai.com/api/download/models/130312
将下载到的模型放入stable-diffusion-webui/models/Stable-diffusion
# 模型网站
https://civitai.com/
https://huggingface.co/

11. 运行webui.sh

./webui.sh

正常启动后,你就能看到vs code贴心的帮你转发了127.0.0.1:7860,通过vs code点击这个链接,你就能看到SD的页面了

完成以上操作就可以给自己用了

好了,可以Ctrl+c关掉程序了

下面的操作是用来给别人用的

12. 修改 webui.py

# webui.py中搜索 api.launch
# 将
    api.launch(
        server_name="0.0.0.0" if cmd_opts.listen else "127.0.0.1",
        port=cmd_opts.port if cmd_opts.port else 7861,
        root_path=f"/{cmd_opts.subpath}" if cmd_opts.subpath else ""
    )
# 修改为
    api.launch(
        server_name="127.0.0.1",
        port=18101, # 自己选一个端口
        root_path="/StableDiffusion/Web"
    )
    
# webui.py中搜索 shared.demo.launch
# 将
        app, local_url, share_url = shared.demo.launch(
            share=cmd_opts.share,
            server_name=server_name,
            server_port=cmd_opts.port,
            ssl_keyfile=cmd_opts.tls_keyfile,
            ssl_certfile=cmd_opts.tls_certfile,
            ssl_verify=cmd_opts.disable_tls_verify,
            debug=cmd_opts.gradio_debug,
            auth=gradio_auth_creds,
            inbrowser=cmd_opts.autolaunch and os.getenv('SD_WEBUI_RESTARTING') != '1',
            prevent_thread_lock=True,
            allowed_paths=cmd_opts.gradio_allowed_path,
            app_kwargs={
                "docs_url": "/docs",
                "redoc_url": "/redoc",
            },
            root_path=f"/{cmd_opts.subpath}" if cmd_opts.subpath else "",
        )
# 修改为
        app, local_url, share_url = shared.demo.launch(
            share=cmd_opts.share,
            server_name="127.0.0.1",
            server_port=18101,
            ssl_keyfile=cmd_opts.tls_keyfile,
            ssl_certfile=cmd_opts.tls_certfile,
            ssl_verify=cmd_opts.disable_tls_verify,
            debug=cmd_opts.gradio_debug,
            auth=gradio_auth_creds,
            inbrowser=cmd_opts.autolaunch and os.getenv('SD_WEBUI_RESTARTING') != '1',
            prevent_thread_lock=True,
            allowed_paths=cmd_opts.gradio_allowed_path,
            app_kwargs={
                "docs_url": "/docs",
                "redoc_url": "/redoc",
            },
            root_path="/StableDiffusion/Web",
        )

13. 安装Nginx

sudo apt install nginx -y
nginx

14. 设置Nginx转发

把配置文件软链到自己目录下好修改文章来源地址https://www.toymoban.com/news/detail-736645.html

cd ~
ln -s /etc/nginx/ Nginx
# 打开Nginx下的nginx.conf
# 搜索 include /etc/nginx/sites-enabled/*;
# 在这行下添加
include /etc/nginx/myHost/*.conf;
mkdir myHost
cd myHost
touch StableDiffusion.conf
# 在StableDiffusion.conf中写入如下内容
server {
    listen 8080;
    server_name example.com www.example.com;  # Change this to your domain name

    location /StableDiffusion/Web/ {  # Change this if you'd like to server your Gradio app on a different path
        proxy_pass http://127.0.0.1:18101/; # Change this if your Gradio app will be running on a different port
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
    }
}
# 验证配置是否正确
nginx -t
# 重启nginx
nginx -s reload

15. 后台启动webui

nohup webui.sh &

到了这里,关于手把手教你从0开始在服务器上部署stable diffusion的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 手把手教你从入门到精通C# Modbus通信

    在工业通信领域,Modbus通信是一种使用非常广泛的通信协议,Modbus一般有三种,分别为ModbusRTU、ModbusASCII、ModbusTCP,其中ModbusRTU、ModbusASCII是应用于串行链路上的协议,通俗一点就是说它是走串口的,ModbusTCP通俗点说就是它是走网口的,作者在自动化领域耕耘多年,做过的Mo

    2024年02月14日
    浏览(32)
  • 从零开始,手把手教你实现基于 Websocket 的微服务

    Websocket 协议是为了解决 HTTP 协议缺陷而产生的一种通信协议,它能够在客户端和服务器之间建立持久性的连接,并且允许双向通信。 HTTP 协议的请求与响应模式,其实并不适合实时通信的场景。比如聊天室、在线游戏等应用,都需要实时地推送消息到客户端,而 HTTP 协议则需

    2024年02月11日
    浏览(33)
  • 【【手把手教你从SD卡驱动VDMA显示图片实验】】

    典型的BMP图像文件是由四部分组成的 包括了BMP的文件头,BMP信息头,调色板,位图数据 因为传递的是RGB图像 RGB不太需要调色板了 从信息头直接到位图数据 文件头占据了14个字节 分别是 查看这个16进制格式 BMP的文件格式 总是低字节的放在低地址位,高字节放在高地址位。

    2024年01月21日
    浏览(37)
  • 手把手教你从微软官网上下载系统镜像【保持最新版】

    🔥推荐阅读:http://t.csdn.cn/nQfIY🔥 🥇个人主页:@MIKE笔记 🥈专栏:爱倒腾 如何从微软官网下载到全系列的系统镜像: 有人可能会说,都有镜像下载工具了,还有了解如何从微软官网直接下载镜像的必要吗? MIKE笔记认为,不仅要知其然,还要知其所以然,掌握这些电脑技巧

    2024年02月04日
    浏览(46)
  • 手把手教你搭建一个Minecraft 服务器

    这次,我们教大家如何搭建一个我的世界服务器 首先,我们来到这个网站 MCVersions.net - Minecraft Versions Download List MCVersions.net offers an archive of Minecraft Client and Server jars to download, for both current and old releases! https://mcversions.net/   在这里,我们点击对应的版本,从左到右依次是稳定版

    2024年02月09日
    浏览(34)
  • 手把手教你将项目部署到服务器!

    一、导入centos7虚拟机: 打开VMWare,点击“打开虚拟机”,选择centos7.ova之后,选择存储路径: 点击导入: 选择“不再显示此消息”,点击“重试”按钮: 点击“编辑虚拟机设置”,修改处理器、内存、硬盘等信息后,启动 按Ctrl+Alt键可以切换到windows下。 启动成功后,输入

    2023年04月20日
    浏览(38)
  • 手把手教你搭建内网穿透服务器

    有时候我们需要把外网可以访问自己的内网,比如在微信公众号开发调用接口时为了方便调试就需要配置回调地址或者是想把自己的nas可以在不在家就能访问,这时候就需要内网穿透。使用内网穿透主要有几种方式,1.使用内网穿透服务商提供的服务,但是这种需要付费,免

    2024年04月23日
    浏览(32)
  • 【Linux】手把手教你实现udp服务器

    网络套接字~ 文章目录 前言 一、udp服务器的实现 总结 上一篇文章中我们讲到了很多的网络名词以及相关知识,下面我们就直接进入udp服务器的实现。 一、udp服务器的实现 首先我们需要创建五个文件(文件名可以自己命名也可以和我一样),分别是makefile,udpclient.cc,udpclient.hpp

    2024年02月13日
    浏览(29)
  • 手把手教你如何使用Unity搭建简易图片服务器

    目录 引言 服务器 WAMP简介 WAMP的配置与使用 主要的WAMP集成环境有: 正文 1、外部工具素材准备 首先下载并安装 WAMP  图片路径设置 2、创建 Unity 工程 将图片加载到 Unity 项目中: 代码块 运行效果如下: 网络游戏中,服务器的搭建尤为重要,无论是授权服务器,还是非授权服务

    2024年02月02日
    浏览(37)
  • 手把手教你在 Windows 环境中搭建 MQTT 服务器

    前些天要对接一家硬件商的设备数据,对方使用的 MQTT 协议点对点透传,所以又赶紧搭建 MQTT 服务器,写 .NET 程序接收数据等等,今天分享一下如何搭建 MQTT 服务器。 MQTT(Message Queuing Telemetry Transport)是一种轻量级的、基于发布/订阅模式的通信协议,专门设计用于在低带宽

    2024年02月03日
    浏览(45)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包