- 登錄服務(wù)器,了解機(jī)器整體配置,安裝Python3.12 和git
#登錄
ssh -i C:\Users\xxx\.ssh\ssh-key-2025-05-12.key opc@xxx.xxx.xx.xxx
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Mon May 12 12:57:35 2025 from 98.96.223.133
#查看操作系統(tǒng)信息
[opc@instance-20250512-xxx ~]$ uname -a
Linux instance-20250512-xxx5.15.0-306.177.4.el8uek.x86_64 #2 SMP Wed Feb 19 10:29:16 PST 2025 x86_64 x86_64 x86_64 GNU/Linux
Linux @facemosaic 5.15.0-1063-aws #69~20.04.1-Ubuntu SMP Fri May 10 19:20:12 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
#為Oracle的機(jī)器,查看Oracle Linux的版本號
cat /etc/oracle-release # 輸出為Oracle Linux Server release 8.10 #此版本支持的最高python版本為n 3.12
#Ubuntu上看操作系統(tǒng)版本
ubuntu@facemosaic:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
#查看時間
date
Fri May 16 07:38:24 GMT 2025 #此云服務(wù)器上的時間為零時區(qū)的時間,比東八區(qū)早8小時,AWS上機(jī)器則為中國時區(qū)
#查看英偉達(dá)顯卡型號
[opc@instance-20250512-xxx ~]$ lspci | grep -i nvidia
00:04.0 3D controller: NVIDIA Corporation GA102GL [A10] (rev a1)
00:1e.0 3D controller: NVIDIA Corporation Device 2237 (rev a1)
#查看GPU詳情
nvidia-smi
Tue Jun 3 15:42:55 2025
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.183.01 Driver Version: 535.183.01 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| 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 A10G On | 00000000:00:1E.0 Off | 0 |
| 0% 27C P0 58W / 300W | 5726MiB / 23028MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 50436 C /usr/bin/python 5716MiB |
+---------------------------------------------------------------------------------------+
#查看CPU核數(shù)
cat /proc/cpuinfo| grep "cpu cores"| uniq
# 查看RAM 單位G
free -g
# 查看硬盤空間
df -h
#查看python版本號
python3 --version
# python版本為3.6. 需要安裝更新的版本。 參考文檔:https://docs.oracle.com/cd/F22978_01/python/OL8-PYTHONG.pdf
sudo dnf install python3.12
python3.12 --version #輸出為Python 3.12.8
# 將python3 的別名指向3.12(3.6的版本仍然保留,誤刪)
sudo alternatives --set python3 /usr/bin/python3.12 # 在Ubuntu服務(wù)器上可以不設(shè)置,只要創(chuàng)建python虛擬環(huán)境的是python3.12就行
#安裝pip 可以按照python3版本的pip sudo dnf install python3-pip python3-setuptools python3-wheel
# 也可以指定小版本,安裝適配python3.12版本的pip
sudo dnf install python3.12-pip python3.12-setuptools python3.12-wheel
# 啟用pip的別名,這樣以后就可以用pip命令來調(diào)用pip3.12了
sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3.12 1
# 如果是Ubuntu系統(tǒng)則通過以下命令安裝pip
curl -O https://bootstrap.pypa.io/get-pip.py
python3.12 get-pip.py
python3.12 -m pip
# 安裝git 卸載時同樣需要sudo的前綴:sudo dnf remove git
sudo dnf install git -y
# 創(chuàng)建 ComfyUI的項(xiàng)目文件的目錄并進(jìn)入此目錄
mkdir ~/local/comfy
cd ~/local/comfy
# 下載ComfyUI框架代碼
git clone https://github.com/comfyanonymous/ComfyUI.git
# ComfyUI 下載好后,在ComfyUI/custom_nodes目錄下運(yùn)行g(shù)it clone https://github.com/Comfy-Org/ComfyUI-Manager.git
# 來下載節(jié)點(diǎn)管理器
- 配置Python虛擬環(huán)境
# 查看登錄后當(dāng)前目錄下文件,發(fā)現(xiàn)無文件或者文件夾
ls
# 創(chuàng)建文件夾,如無中間目錄則自動創(chuàng)建
mkdir -p ~/local/python/env # -p表示中間目錄不存在則自動創(chuàng)建
# 進(jìn)入虛擬環(huán)境的專用目錄
cd ~/local/python/env
# 在此目錄下創(chuàng)建名字叫comfy_try_on的虛擬環(huán)境,由于上面的配置,這里的python3已經(jīng)自動重定向到python 3.12
python3 -m venv comfy_try_on
# 啟用該虛擬環(huán)境,退出該虛擬環(huán)境的命令: 直接輸deactivate; 刪除該虛擬環(huán)境,則直接刪除目錄即可rm -r comfy_try_on
source comfy_try_on/bin/activate
# 為了能夠在任何目錄都能夠方便的啟用Python虛擬環(huán)境,我們加入以下步驟
# 創(chuàng)建并進(jìn)入bin目錄
mkdir ~/bin
cd ~/bin
# 創(chuàng)建名字叫activate的腳本文件
sudo touch activate
# 給文件增加執(zhí)行權(quán)限
sudo chmod ug+x activate
# 在文件里寫入快速啟動python虛擬環(huán)境的腳本代碼,注意文本里有變量占位符$1,所以第一行的EOF帶引號
sudo tee ~/bin/activate <<'EOF'
> #!/bin/bash
> source ~/local/python/env/$1/bin/activate
> EOF
#清空此文件的命令是執(zhí)行sudo tee ~/bin/activate > /dev/null后按 Ctrl + D 結(jié)束輸入
#將bin文件加入系統(tǒng)目錄
export PATH="~/bin:$PATH"
# 此時在任意位置都可以用此命令啟動某個Python虛擬環(huán)境了
啟動服務(wù)
# 進(jìn)入ComfyUI目錄,在此目錄下啟用python虛擬環(huán)境
cd ~/local/comfy/ComfyUI
source activate comfy_try_on
# 在python虛擬環(huán)境里安裝pytorch, 于系統(tǒng)pytorch解耦
pip install torch torchvision torchaudio
# 如果要指定安裝某個torch版本:
pip install torch==2.6.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
pip install torch==2.5.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
#安裝節(jié)點(diǎn),這里第一次安裝,安裝的是ComfyUI框架默認(rèn)的常用節(jié)點(diǎn)
pip install -r requirements.txt
#在服務(wù)器防火墻里啟用端口,關(guān)閉多個端口的命令是sudo firewall-cmd --zone=public --remove-port=7860/tcp --remove-port=7861/tcp --permanent
sudo firewall-cmd --permanent --add-port=8188/tcp
# 重啟機(jī)器防火墻以生效
sudo firewall-cmd --reload
#查看端口是否已經(jīng)打開
sudo firewall-cmd --zone=public --list-ports
# 端口可用的3個條件:
#1. 服務(wù)器已經(jīng)在本地防火墻里打開端口 2. 云服務(wù)器的控制臺頁面里的安全策略里已經(jīng)打開此端口 3. 機(jī)器上啟動了Http服務(wù)來監(jiān)聽此端口
#啟動ComfyUI管理器,后面是本地訪問的地址和端口,不設(shè)置則默認(rèn)為http://127.0.0.1:8188
#python3 main.py --listen=192.168.98.xx --port=98xx
#這里需要同時能本地訪問以及遠(yuǎn)程互聯(lián)網(wǎng)訪問,則是下面的命令。參考:[Why does my python TCP server need to bind to 0.0.0.0 and not localhost or it's IP address](https://stackoverflow.com/questions/38256851/why-does-my-python-tcp-server-need-to-bind-to-0-0-0-0-and-not-localhost-or-its)
python main.py --listen 0.0.0.0
# 命令行顯示啟動成功后,即顯示
Starting server
To see the GUI go to: http://0.0.0.0:8188
則可以在互聯(lián)網(wǎng)上可以通過IP:8188訪問此頁面了,如不能訪問,則通過這個網(wǎng)站再確認(rèn)一下端口是否以及打開: https://tool.chinaz.com/port
# 關(guān)閉服務(wù)的方法:用頁面上的ComfyUI Manager,或者ctrl+c。如果是在本地機(jī)器的cmd命令行上跑,則直接關(guān)掉cmd也可以
- 給ComfyUI進(jìn)程添加守護(hù)進(jìn)程
#新建守護(hù)進(jìn)程的啟動腳本
nano run_comfyui.sh
#腳本里是如下代碼
#!/bin/bash
while true
do
echo "Starting ComfyUI..."
python main.py --listen 0.0.0.0
echo "ComfyUI crashed or exited. Restarting in 3 seconds..."
sleep 3
done
# 給腳本添加執(zhí)行權(quán)限
chmod +x run_comfyui.sh
# 以后臺進(jìn)程下形式運(yùn)行
nohup ./run_comfyui.sh > comfyui.log 2>&1 &
#命令解釋
nohup
作用:讓后面啟動的進(jìn)程忽略掛起信號(SIGHUP),即使你關(guān)閉終端,進(jìn)程也不會被終止。
常用場景:在遠(yuǎn)程服務(wù)器上運(yùn)行長時間任務(wù),防止 SSH 斷開后進(jìn)程被殺死。
./run_comfyui.sh
作用:執(zhí)行當(dāng)前目錄下的 run_comfyui.sh 腳本。
注意:腳本需要有可執(zhí)行權(quán)限(chmod +x run_comfyui.sh)。
> comfyui.log
作用:將標(biāo)準(zhǔn)輸出(stdout)重定向到 comfyui.log 文件。
效果:腳本運(yùn)行時的正常輸出(如 echo、print)都會寫入 comfyui.log,不會顯示在終端。
2>&1
作用:將標(biāo)準(zhǔn)錯誤輸出(stderr)重定向到標(biāo)準(zhǔn)輸出(stdout)的位置。
效果:所有錯誤信息也會寫入 comfyui.log,不會顯示在終端。
解釋:
2 代表標(biāo)準(zhǔn)錯誤(stderr)。
1 代表標(biāo)準(zhǔn)輸出(stdout)。
2>&1 表示“把標(biāo)準(zhǔn)錯誤輸出重定向到標(biāo)準(zhǔn)輸出的位置”。
&
作用:讓整個命令在后臺運(yùn)行(即不占用當(dāng)前終端,可以繼續(xù)輸入其他命令)。
效果:你可以關(guān)閉終端或繼續(xù)在當(dāng)前終端執(zhí)行其他操作,腳本會在后臺繼續(xù)運(yùn)行
#gradio的應(yīng)用也可以設(shè)置成把日志輸出到文件,這樣萬一ssh端口連接,日志還是可以看得到的
python gradio_tryon.py > gradio.log 2>&1
- 配置按日的日志文件
cd /etc/logrotate.d/
sudo nano comfyui
# 輸入以下文本,注釋不能寫入
/home/opc/local/comfy/ComfyUI/comfyui.log {
daily # 每天輪轉(zhuǎn)一次
rotate 7 # 最多保留7個歷史日志
compress # 輪轉(zhuǎn)后的日志自動gzip壓縮
missingok # 日志不存在時不報錯
notifempty # 日志為空時不輪轉(zhuǎn)
copytruncate # 復(fù)制后清空原日志(適合nohup等后臺寫入的日志)
dateext # 輪轉(zhuǎn)文件名加日期后綴
su opc opc # 表示用 opc 用戶和組來執(zhí)行日志輪轉(zhuǎn),這樣 logrotate 就不會因?yàn)闄?quán)限問題而拒絕操作。
}
#執(zhí)行日志輪轉(zhuǎn)
sudo logrotate -f /etc/logrotate.d/comfyui
# 此時在/home/opc/local/comfy/ComfyUI/目錄下會有一個類似comfyui.log-20250530.gz的文件,可用zcat查看內(nèi)容
- 導(dǎo)入和安裝節(jié)點(diǎn)/模型
-
在web頁面導(dǎo)入工作流后,點(diǎn)擊頁面上的Manager按鈕,然后點(diǎn)擊Custom Node Mager,在此頁面一鍵安裝缺失的節(jié)點(diǎn)
image.png - 在導(dǎo)入工作流時,會主動彈窗提示要不要安裝缺失的節(jié)點(diǎn)。此時不要點(diǎn)擊,直接叉掉,因?yàn)檫@里的manager試了幾次,經(jīng)常安裝過程中會導(dǎo)致ComfyUI的進(jìn)程退出。叉掉后,點(diǎn)擊頂部的Manager按鈕,從這個如果下載缺失的節(jié)點(diǎn),中斷進(jìn)程的bug的發(fā)生率會小一些
- 導(dǎo)入工作流,安裝缺失節(jié)點(diǎn)后,點(diǎn)擊運(yùn)行,還是可能有很多報錯,比如模型依賴缺失,庫版本沖突。只要最終能運(yùn)行成功,cmd上的報錯可以不用管。如果無法運(yùn)行,則結(jié)合web彈窗提示和cmd上的log,解決相應(yīng)的錯誤。
如果是Node或者M(jìn)odel缺失,可以在Manager里一鍵下載;如果是Node報錯,也可以試試Manager里的Node Fix功能; 但實(shí)際使用發(fā)現(xiàn)Model 下載器里,顯示的"工作流中的模型"列表,有些是工作流里不需要的,所有不要一鍵下載,而是選擇需要的下載.
本次好幾個model都需要手動安裝,部分模型的下載來自這些地址
fluxgym安裝教程:只需幾步即可開始訓(xùn)練模型!以及這里https://huggingface.co/comfyanonymous
https://huggingface.co/hfmaster/models/tree/main/flux
也可以本地下載后上傳到云服務(wù)器。即先在一個終端登錄ssh,然后在另一個終端執(zhí)行這個命令
scp -v -i path/to/your/private_key path/to/your/local/file username@remoteIP:path/to/your/target/file
# 對應(yīng)下載文件的命令
# scp -v -i path/to/your/private_key username@remoteIP:path/to/your/remote/file path/to/your/local/target/file
如果是系統(tǒng)庫缺失,比如cv2, 則需要在python虛擬環(huán)境里安裝,而不是在服務(wù)器系統(tǒng)的python環(huán)境里安裝。因?yàn)椴煌墓ぷ髁?,可能依賴的是不同的庫版本,需要?dú)立維護(hù)各個工作流的庫版本號
一個特殊的case是需要2.34版本的glibc,因?yàn)檫@個庫是Linux系統(tǒng)核心庫,直接升級會導(dǎo)致系統(tǒng)不穩(wěn)定,所以參考這篇文章,用本地編譯2.34的glibc版本并通過patchelf使用的方法解決
在同一臺Linux機(jī)器上安裝多個版本GLIBC
最后執(zhí)行的命令是:
cd /home/opc/local/python/env/comfy_try_on/lib/python3.12/site-packages/bitsandbytes
patchelf --add-rpath /opt/glibc234/lib libbitsandbytes_cuda126.so
但這個只是讓so鏈接上2.34版本的glibc,python 運(yùn)行時仍然會先加載2.28的glibc。所以通過
sudo /home/opc/local/python/env/comfy_try_on/bin/patchelf --set-interpreter /opt/glibc234/lib/ld-linux-x86-64.so.2 /home/opc/local/python/env/comfy_try_on/bin/python3
LD_LIBRARY_PATH=/opt/glibc234/lib:$LD_LIBRARY_PATH /home/opc/local/python/env/comfy_try_on/bin/python3 -m bitsandbytes
讓python也使用2.34的glibc庫
但又報gcc的錯,因?yàn)镚LIBC是系統(tǒng)核心庫,用了glibc2.34的庫,在調(diào)用gcc時,又與glibc2.34版本不兼容
至此放棄了2.34的版本。改為使用bitsandbytes老版本0.42.0
直接install安裝的話,運(yùn)行python -m bitsandbytes時報錯,提示請源碼編譯。按提示的步驟源碼編譯
git clone https://github.com/TimDettmers/bitsandbytes.git
cd bitsandbytes
CUDA_VERSION=126
python setup.py install
但因?yàn)槭莄heckout 0.42.0的版本
git checkout 4870580f17767a4165ec05d954dff2b5c25b694d
會報錯so庫不存在libbitsandbytes_cuda126.so
所以需要cd bitsandbytes后先執(zhí)行make CUDA_VERSION=126把so庫編譯出來
最后剩下的錯誤是
ModuleNotFoundError: No module named 'triton.ops'
但其實(shí)triton庫已經(jīng)安裝,找到原因是老版本的bitsandbytes需要老版本的triton庫,所以triton也降級到2.3.1版本
這時候就只有warning了:
torch 2.7.0 requires triton==3.3.0; ... but you have triton 2.3.1 which is incompatible.
torchscale 0.3.0 requires timm==0.6.13, but you have timm 1.0.15 which is incompatible.
即PyTorch 2.7.0 官方要求 triton==3.3.0,現(xiàn)在降級成了 2.3.1,部分 PyTorch 的功能(如 torch.compile、torch.inductor)可能無法用 triton 加速,但大部分基礎(chǔ)功能不受影響。
看某個庫被其他庫依賴的情況
pipdeptree --reverse --packages protobuf
然后運(yùn)行工作流時又報錯
ValueError: Calling `to()` is not supported for `4-bit` quantized models with the installed version of bitsandbytes. The current device is `cuda:0`. If you intended to move the model, please install bitsandbytes >= 0.43.2.
報錯的代碼行是
python3.12/site-packages/accelerate/big_modeling.py
elif version.parse(importlib.metadata.version("bitsandbytes")) < version.parse("0.43.2"):
raise ValueError(
"Calling `to()` is not supported for `4-bit` quantized models with the installed version of bitsandbytes. "
f"The current device is `{self.device}`. If you intended to move the model, please install bitsandbytes >= 0.43.2."
)
本來想解決方案是不是把JoyCaption2或者bitsandbytes換成其他工作類似的節(jié)點(diǎn)試試,但在看JoyCaption2的模型列表時,發(fā)現(xiàn)同時包含這兩個節(jié)點(diǎn)

猜測默認(rèn)的第一個模型,應(yīng)該是8bit轉(zhuǎn)4bit的量化加速模型,所以選擇第二個僅8bit的版本試試,結(jié)果工作流成功跑完,但估計速度比4bit會慢兩三秒.
目前的工作流:
- 已經(jīng)引入bitsandbytes老版本0.42.0和HyperL-FLUX-Accelerator兩個加速器,換裝耗時在80秒左右,和競品Creati的30秒還有差距,會再看看有沒有其他加速的途徑
-
效果上還不對,估計是參數(shù)配置的問題,要調(diào)試一下
image.png - 第二次運(yùn)行就OOM了,點(diǎn)擊釋放GPU的按鈕也沒用,還需要調(diào)試一下OOM的原因
- 數(shù)據(jù)備份
通過rclone可以從Linux服務(wù)器備份文件到Google Drive,也可以下載;
也可以通過gdown下載(wget只能下載小文件)
rclone的配置步驟參考
rclone config
# n) New remote
# name> gdrive
# Storage> drive
# client_id> (可留空)
# client_secret> (可留空)
# scope> 1 (full access)
# root_folder_id> (可留空)
# service_account_file> (可留空)
# Edit advanced config? n
# Use auto config? n
# 復(fù)制提示的網(wǎng)址到本地電腦瀏覽器,登錄并授權(quán)
# 把獲得的 code 粘貼回服務(wù)器終端
# 配置完成
#這里的client ID 和 Secret 最好可以不為空,也就是執(zhí)行以下步驟
Here are the steps:
Log in to the Google Cloud Console.
Create a new project (or select an existing project).
Enable the Google Drive API:
In the left menu, go to “APIs & Services” → “Library”.
Search for “Google Drive API”, click on it, and enable it.
Create OAuth 2.0 credentials:
Go to “APIs & Services” → “Credentials”.
Click “Create Credentials” → “OAuth client ID”.
For application type, select “Desktop app”.
Enter a name and click “Create”.
Obtain the client_id and client_secret:
After creation, the client_id and client_secret will be displayed. Copy them.
Enter them during rclone config:
When configuring the Google Drive remote in rclone, paste the client_id and client_secret you just obtained.
#如果提示要先建Content Screen, 則執(zhí)行以下步驟
This message means that before you can create OAuth client credentials in Google Cloud Console, you need to set up the OAuth consent screen for your project.
Here’s what you should do:
Go to the Google Cloud Console:
https://console.cloud.google.com/
In the left menu, select “APIs & Services” → “OAuth consent screen”.
Configure the consent screen:
Choose “External” (recommended for most use cases) or “Internal” (if only for users in your organization).
Fill in the required fields (App name, User support email, Developer contact information, etc.).
You do not need to add any scopes or test users for basic rclone use (unless you want to restrict access).
Save and continue through the steps.
After the consent screen is configured, return to “Credentials” and create your OAuth client ID as described before.
然后通過此命令下載Google Drive文件夾到服務(wù)器里
rclone copy /home/ubuntu/local/ComfyUI/models/ hjm:'server-local/comfy/ComfyUI/models/' -P --ignore-existing
# 如果發(fā)現(xiàn)有部分文件未傳上去,則再傳一遍:
以存在的文件忽略
(comfy_try_on) [opc@instance-20250512-junmin ComfyUI]$ rclone listremotes
hjm:
(comfy_try_on) [opc@instance-20250512-junmin ComfyUI]$ rclone copy /home/opc/local/comfy/ComfyUI/models/diffusion_models hjm:'server-local/comfy/ComfyUI/models/diffusion_models' -P --ignore-existing
或者只更新新的文件
rclone copy /home/opc/local/comfy/ComfyUI/models/diffusion_models hjm:'server-local/comfy/ComfyUI/models/diffusion_models' -P --update
或者強(qiáng)制覆蓋舊文件
rclone copy /home/opc/local/comfy/ComfyUI/models/diffusion_models hjm:'server-local/comfy/ComfyUI/models/diffusion_models' -P --ignore-times
- 疑難解決
如果啟動main.py時報錯
OSError: [Errno 98] error while attempting to bind on address ('127.0.0.1', 8188): [errno 98] address already in use
則先通過netstat -tuplen看是哪個服務(wù)在使用這個端口,如果是上次的ComfyUI服務(wù)沒有退出的話,則直接先kill此服務(wù):kill -9 PID重啟ComfyUI服務(wù)并加載工作流時,即使是很簡單的工作流,也可能會報OOM, 是因?yàn)樯洗喂ぷ髁鬟\(yùn)行時加載的模型和使用的VRAM, 還沒有釋放。所以關(guān)閉ComfyUI服務(wù),或者啟動ComfyUI服務(wù)加載工作流之前,都需要先調(diào)用一下清空VRAM的接口
下了新節(jié)點(diǎn)后,有可能引起各種沖突,所以需要在下節(jié)點(diǎn)前先運(yùn)行
pipdeptree | grep mediapipe保存當(dāng)前所有的python 庫的版本
然后安裝節(jié)點(diǎn)的時候看log分別安裝了哪些庫并記錄
這樣后面如果有沖突,可以分析原因

