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

ubuntu 22.04 anaconda comfyui安装

背景:

戴尔R740服务器,安装了proxmox操作系统,配置了显卡直通。创建了一个ubuntu 22.04 VM虚拟机实例,并安装了显卡驱动与cuda等相关配置:

接下来准备搭建一套comfyui的环境,前段时间B站,抖音各种刷到相关视频,自己也想玩一下!

ubuntu 22.04 anaconda comfyui

可以参考官方网站:https://docs.comfy.org/zh-CN/installation/manual_install

对于 ComfyUI 的安装, 主要分为几个步骤

  1. 创建一个虚拟环境(避免污染系统级 Python 环境)
  2. 克隆 ComfyUI 代码仓库
  3. 安装依赖
  4. 启动 ComfyUI

安装anaconda并配置虚拟环境

独立的虚拟环境是必要的,因为 ComfyUI 的依赖可能会与系统上的其他依赖冲突,也可以避免对系统级 Python 环境的污染。这里选择了使用anaconda安装python环境:

下载安装anaconda

通过访问:https://repo.anaconda.com/archive/ 选择对应安装程序:

下载并运行安装脚本:(在ubuntu 22.04 VM虚拟机实例上,这里使用了xshell远程连接)

wget https://repo.anaconda.com/archive/Anaconda3-2024.10-1-Linux-x86_64.sh
bash Anaconda3-2024.10-1-Linux-x86_64.sh

全部默认yes yes 一路回车:

anaconda加入系统环境变量:

其实这里已经加入了 <font style="color:rgb(77, 77, 77);">~/.bashrc</font>文件来激活安装

source ~/.bashrc
conda list

安装后的一些配置:

鉴于源的访问问题,配置源为清华源:

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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/conda config --set show_channel_urls yespip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

创建comfyui的 python虚拟环境:

创建python 3.12的comfyui的运行环境,并进入该运行环境:

conda create -n comfyui python=3.12
conda activate comfyui

验证python的版本:

ubuntu系统的一些其他配置:

使用如下命令查看当前的分区状况:

lsblk

我在创建VM实例的时候明明分配了1.5T这里的根/默认的只有100G,需要处理一下(估计后续1.5T也不够需要扩容磁盘):

查看当前PV配置:

使用**pvdisplay **查看当前PV配置:

pvdisplay

分配剩余空间给根目录:

将卷组ubuntu-vg(VG)中所有剩余空间(+100%FREE)分配给名为ubuntu-lv的逻辑卷(LV),并使用r**esize2fs **命令调整文件系统以匹配新容量:

sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
df -Th /
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

验证扩容:

使用如下命令验证lv扩容成功:

df -h
lsblk

comfyui的安装

参照官方网站:https://docs.comfy.org/zh-CN/installation/manual_install.

克隆仓库:

这里使用git克隆的方式安装(默认git已经安装),个人喜欢目录使用/data安装软件:

mkdir /data
cd /data
git clone https://github.com/comfyanonymous/ComfyUI.git

安装GPU 及 ComfyUI 依赖

可以参照github仓库README.md,安装GPU依赖:

cd /data/ComfyUI
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu128

安装 ComfyUI 依赖:

pip install -r requirements.txt

注意:执行命令的目录,必须是comfyui 的相对路径下,如我的目录绝对路径是/data/ComfyUI!

启动 ComfyUI

进入ComfyUI目录,执行如下启动命令,等待comfyui启动:

cd /data/ComfyUI
python main.py --port 15070 --listen 0.0.0.0

通过浏览器访问安装comfyui应用的VM实例主机的15070端口,可以看到如下页面:

运行默认的工作流,会报如下错误:

模型缺失,需要下载该模型到 models目录下,我这里直接使用了魔搭社区

通过该社区这里下载了模型:https://www.modelscope.cn/models/stabilityai/stable-diffusion-2-inpainting/files(否则就要通过科学上网,这里就偷懒了)

右击模型文件右侧下载,复制连接。获得下载地址,下载模型到Comfyui模型目录下:

cd /data/ComfyUI/models/checkpoints/
wget  https://www.modelscope.cn/models/stabilityai/stable-diffusion-2-inpainting/resolve/master/512-inpainting-ema.ckpt

kill掉comfyui进程 ,重启comfyui程序:

一般的方式是ps -aux获取进程号,然后kill -9杀掉进程

也可以通过下面的方式杀死进程:

kill -9 $(ps aux | grep 'python main.py --port 15070 --listen 0.0.0.0' | grep -v grep | awk '{print $2}')

然后重新启动comfyui:

python main.py --port 15070 --listen 0.0.0.0

刷新浏览器重新运行工作量可以正常运行:

其他的一些配置

将comfyui注册为系统服务

每次使用命令启动comfyui的方式很不方便对服务的管理与维护,现在我们将comfyui注册为系统服务,通过systemctl管理comfyui:

vi /etc/systemd/system/comfyui.service

[Unit]
Description=ComfyUI Stable Diffusion Service
After=network.target
StartLimitIntervalSec=60[Service]
Type=simple
User=root
WorkingDirectory=/data/ComfyUI
Environment="PATH=/root/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
ExecStart=/bin/bash -c 'source /root/anaconda3/etc/profile.d/conda.sh && conda activate comfyui && exec python main.py --port 15070 --listen 0.0.0.0'
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
SyslogIdentifier=comfyui
ProtectSystem=full
PrivateTmp=true
NoNewPrivileges=true
LimitNOFILE=65536[Install]
WantedBy=multi-user.target

重新加载 systemd 管理的服务单元文件,并尝试启动comfyui:

systemctl daemon-reload
systemctl start comfyui.service

通过如下命令确认服务正常启动:

ps -aux|grep python
systemctl status comfyui.service 

并进一步使用浏览器可以正常访问服务:

注意:这里的15070端口可以通过个人喜好修改service文件中中启动命令的端口!

comfyui安装常用插件:

为了方便使用comfyui,需要安装一些常用的插件,如:comfyui-manager ComfyUI-Custom-Scripts等插件,请注意:插件的安装目录是ComfyUI 目录下的custom_nodes目录,ComfyUI-Manager 下载到本地目录名需要替换成小写,具体可以参照github文档!

cd /data/ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Manager comfyui-manager
git clone https://github.com/pythongosssss/ComfyUI-Custom-Scripts.git

重启comfyui服务,等待服务重启:

systemctl restart comfyui.service
systemctl status comfyui.service
journalctl -u comfyui -f

通过浏览器访问comfyui,主要看ComfyUI-Manager这个插件,后续的插件模型可以通过这里去下载:

点击Costom Nodes manager 可以搜索下载插件,其他英文名词可以自行翻译:

代理相关

由于comfyui下载插件很多插件要放我github,模型的下载也需要访问HuggingFace。我局域网有一台cvm安装了科学上网工具,就在安装comfyui的设备上面需要加入变量的方式科学上网:

  export http_proxy=http://192.168.0.31:20171export http_proxys=http://192.168.0.31:20171

不使用了 还要unset 。直接将其封装了一个service:

cat /etc/systemd/system/proxy.service

[Unit]
Description=Proxy Environment Variables Service
Documentation=https://example.com
After=network.target[Service]
Type=oneshot
RemainAfterExit=yes
Environment="PROXY_URL=http://192.168.0.31:20171"ExecStart=/bin/sh -c "\systemctl set-environment http_proxy=${PROXY_URL} && \systemctl set-environment https_proxy=${PROXY_URL} && \systemctl set-environment HTTP_PROXY=${PROXY_URL} && \systemctl set-environment HTTPS_PROXY=${PROXY_URL} && \echo 'Proxy enabled: ${PROXY_URL}'"ExecStop=/bin/sh -c "\systemctl unset-environment http_proxy && \systemctl unset-environment https_proxy && \systemctl unset-environment HTTP_PROXY && \systemctl unset-environment HTTPS_PROXY && \echo 'Proxy disabled'"ExecReload=/bin/sh -c "\systemctl set-environment http_proxy=${PROXY_URL} && \systemctl set-environment https_proxy=${PROXY_URL} && \systemctl set-environment HTTP_PROXY=${PROXY_URL} && \systemctl set-environment HTTPS_PROXY=${PROXY_URL} && \echo 'Proxy reloaded: ${PROXY_URL}'"# 解决status卡住问题的配置
StandardOutput=journal
TimeoutStopSec=5[Install]
WantedBy=multi-user.target

重新加载 systemd 管理的服务单元文件,并尝试启动proxy:

systemctl daemon-reload
systemctl start proxy.service

通过如下命令确认服务正常启动:

systemctl status proxy.service

关闭代理服务则输入stop 关闭proxy服务:

systemctl stop proxy.service
systemctl status proxy.service

当然关于模型的下载也可以使用ModelScope魔搭社区等实现。

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

相关文章:

  • libimagequant windows 编译
  • 云手机常见问题解析:解决延迟、掉线等困扰
  • 机器学习中的朴素贝叶斯(Naive Bayes)模型
  • 新型eSIM攻击技术可克隆用户资料并劫持手机身份
  • Android 16系统源码_窗口动画(一)窗口过渡动画层级图分析
  • 在 Azure Linux 上安装 RustFS
  • 如何保护文件传输安全?文件传输加密
  • 实战:如何创建 AWS RDS 数据库
  • 从“有”到“优”:iPaaS 赋能企业 API 服务治理建设
  • Foundry 私钥管理指南:方法与安全最佳实践
  • 上下文管理器 和 contextlib 模块
  • 深入浅出Kafka Producer源码解析:架构设计与编码艺术
  • VMware 虚拟机装 Linux Centos 7.9 保姆级教程(附资源包)
  • mybatis-plus-jpa-support
  • 常用的OTP语音芯片有哪些?
  • Spring Boot启动原理:从main方法到内嵌Tomcat的全过程
  • Linux 系统下的 Sangfor VDI 客户端安装与登录完全攻略 (CentOS、Ubuntu、麒麟全线通用)
  • Git LFS 操作处理Github上传大文件操作记录
  • 第一章编辑器开发基础第一节绘制编辑器元素_4输入字段(4/7)
  • Redis集群方案——Redis分片集群
  • 《星盘接口4:银河守护者》
  • 小波变换 | Haar 小波变换
  • 浏览器自动化领域的MCP
  • 实战--Tlias教学管理系统(部门管理)
  • 纯CSS轮播
  • SAP ERP与微软ERP dynamics对比,两款云ERP产品有什么区别?
  • 【第零章编辑器开发与拓展】
  • 不用下载软件也能录屏?Windows 10 自带录屏功能详解
  • Postman、Apifox、Apipost用哪个? 每个的优缺点和综合比较(个人观点)
  • qt多线程的实战使用