Stable diffusion概念

stable-diffusion-webui

stable-diffusion-webui

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
stable-diffusion-webui ❯ ./webui.sh
################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Running on cs user
################################################################

################################################################
Clone stable-diffusion-webui
################################################################
正克隆到 'stable-diffusion-webui'...
remote: Enumerating objects: 25633, done.
remote: Counting objects: 100% (20/20), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 25633 (delta 7), reused 18 (delta 7), pack-reused 25613
接收对象中: 100% (25633/25633), 31.61 MiB | 54.00 KiB/s, 完成.
处理 delta 中: 100% (17963/17963), 完成.

################################################################
Create and activate python venv

只记录关键步骤

跳过下载检查

v1.0

~/stable-diffusion-webui/launch.py

1
skip_install = True

v1.2

~/stable-diffusion-webui/webui.sh

1
/sbin/ldconfig
1
2
git fetch --all //只是下载代码到本地,不进行合并操作
git reset --hard v1.2.1 //把HEAD指向最新下载的版本

使用代理下载7个github的库https://ghproxy.com/

https://github.com/Stability-AI/stablediffusion/archive/refs/heads/main.zip

1
2
3
4
5
6
7
8
9
10
11

https://github.com/salesforce/BLIP
https://github.com/sczhou/CodeFormer
https://github.com/crowsonkb/k-diffusion
https://github.com/Stability-AI/stablediffusion
https://github.com/CompVis/taming-transformers

#/stable-diffusion-webui/venv/lib/python3.9/site-packages/
https://github.com/TencentARC/GFPGAN
https://github.com/openai/CLIP
https://github.com/mlfoundations/open_clip

GPU CUDA安装

GPU

https://developer.nvidia.com/cuda-gpus

版本

下载 https://www.nvidia.cn/geforce/drivers/

1
2
3
4
$  uname -srm
Linux 5.10.0-21-amd64 x86_64

# dpkg-query -s linux-headers-$(uname -r)

Driver Version 要是 51x

1
2
$ lspci | grep -i vga
01:00.0 VGA compatible controller: NVIDIA Corporation GP106M [GeForce GTX 1060 Mobile] (rev a1)

Nvidia 卡信息的末尾是 rev a1,表示已经开启。

末尾是 rev ff,表示独显已经关闭

支持列表 https://developer.nvidia.com/cuda-gpus

X server

1
2
3
4
5
#切换到文本界面
/sbin/init 3

#切换到图形界面
/sbin/init 5

Using: nvidia-installer ncurses v6 user interface
-> Detected 8 CPUs online; setting concurrency level to 8.
-> The file ‘/tmp/.X0-lock’ exists and appears to contain the process ID ‘773’ of a running X server.
ERROR: You appear to be running an X server; please exit X before installing. For further details, please see the section INSTALLING THE NVIDIA DRIVER in the README available on the Linux driver download page at www.nvidia.com.
ERROR: Installation has failed. Please see the file ‘/var/log/nvidia-installer.log’ for details. You may find suggestions on fixing installation problems in the README available on the Linux driver download page at www.nvidia.com.

driver

1
2
3
4
5
6
7
8
9
10
cat <<EOF | sudo tee /usr/lib/modprobe.d/dist-blacklist.conf
blacklist nouveau
options nouveau modeset=0
EOF


sudo update-initramfs -u

#reboot
lsmod | grep nouveau

ERROR: The Nouveau kernel driver is currently in use by your system. This driver is incompatible with the NVIDIA driver, and must be disabled before proceeding. Please consult the NVIDIA driver README and your Linux distribution’s documentation for details on how to correctly disable the Nouveau kernel driver.

kernel-source

会提示安装

1
2
#根据/var/log/nvidia-installer.log 报错情况安装缺失包
sudo apt install dkms

–kernel-source-path 问题 安装linux-headers

1
2
3
#关闭X server 图形界面后执行
sh NVIDIA-Linux-x86_64-*.run

驱动版本

1
cat /proc/driver/nvidia/version

显卡编号

1
ls -l /dev/nvidia*

多块

2

1
sudo nvidia-smi

温度

1
sudo nvidia-smi -q -d TEMPERATURE

10s 一次

1
watch -n 10 nvidia-smi

卸载

1
sh  NVIDIA*.run  --uninstall  

高版本可以卸载低版本的 525卸载515

venv虚拟环境

venv

https://docs.python.org/zh-cn/3/library/venv.html

创建

1
2
3
4
5
python -m venv -h

python -m venv /path/to/new/virtual/environment

source <venv>/bin/activate

激活

1
2
3
4
python3 -m venv /opt/stable-diffusion/sd-venv

#激活虚拟环境
source /opt/stable-diffusion/sd-venv/bin/activate

(sd-venv) cs@debian:/opt/stable-diffusion/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#查看当前pip源
pip config list
#pip config set global.index-url 源网址

pip install -r requirements.txt

#已经安装的包以requirements的格式
pip freeze



pip wheel -w ./tmp_dir -r requirements.txt
pip download -d ./tmp_dir -r requirements.txt
pip install -no-index --find-links=./tmp_dir -r requirements.txt

停止

1
2
#停止使用虚拟环境
source /opt/stable-diffusion/sd-venv/bin/deactivate

nfs介绍

NFS

https://nfs.sourceforge.net/

1
2
3
4
5
#debian
sudo apt-get install nfs-common nfs-kernel-server -y

#centos
sudo yum install nfs-utils rpcbind -y

#下载安装包

sudo apt-get install nfs-common nfs-kernel-server -y –download-only

sudo yum install nfs-utils rpcbind -y –downloadonly –downloaddir /opt/nfs

nfs

  1. 首先服务器端启动RPC服务,并开启111端口;启动NFS服务,并向RPC注册端口信息
  2. 客户端启动RPC(portmap服务),向服务端的RPC(portmap)服务请求服务端的NFS端口(由程序在NFS客户端发起存取文件的请求,客户端本地的RPC(rpcbind)服务会通过网络向NFS服务端的RPC的111端口发出文件存取功能的请求。)
  3. 服务端的RPC(portmap)服务反馈NFS端口信息给客户端。
  4. 客户端通过获取的NFS端口来建立和服务端的NFS连接并进行数据的传输。(客户端获取正确的端口,并与NFS daemon联机存取数据。)
  5. 存取数据成功后,返回前端访问程序,完成一次存取操作。

regular expression

基本规则

字符 描述
| 当有多个选项的使用,选项之间用”|“进行隔离。例如:匹配abc和DEF中的任意一项:abc|DEF。
() 匹配括号内容的内容。例如:(abc|DEF)可以匹配abc或者DEF。
[] 匹配括号中的任一字符,例如[abc],可以匹配字符”a”,或者匹配字符”b”,或者匹配字符”c”。
* 匹配前面的子表达式零次或多次。例如,”ab*”能匹配 “a” 以及 “abb”。* 等价于{0,}。
+ 匹配前面的子表达式一次或多次。例如,”ab+”能匹配 “ab” 以及 “abb”,但不能匹配 “a”。+ 等价于 {1,}。
? 匹配前面的子表达式零次或一次。例如,”a(b)?”能匹配 “a”以及”ab”。? 等价于 {0,1}。
{n} 是一个非负整数。匹配确定的 n 次。例如,’a{2}’ 能匹配 “baac” 中的两个 a, 但是不能匹配bac中的一个a。
{n,} 是一个非负整数。至少匹配n 次。例如,’a{2,}’ 不能匹配 “bac” 中的一个a,但能匹配 “baaaac” 中的全部a。
{n,m} 和 n 均为非负整数,其中n <= m。最少匹配 n 次且最多匹配 m 次。例如,”a{1,3}” 将匹配 “baaaaaac”中的前三个a。注意:在逗号和两个数之间不能有空格。

| 当有多个选项的使用,选项之间用”|“进行隔离。例如:匹配abc和DEF中的任意一项:abc|DEF。
() 匹配括号内容的内容。例如:(abc|DEF)可以匹配abc或者DEF。
[] 匹配括号中的任一字符,例如[abc],可以匹配字符”a”,或者匹配字符”b”,或者匹配字符”c”。
* 匹配前面的子表达式零次或多次。例如,”ab*”能匹配 “a” 以及 “abb”。* 等价于{0,}。
+ 匹配前面的子表达式一次或多次。例如,”ab+”能匹配 “ab” 以及 “abb”,但不能匹配 “a”。+ 等价于 {1,}。
? 匹配前面的子表达式零次或一次。例如,”a(b)?”能匹配 “a”以及”ab”。? 等价于 {0,1}。
{n} n 是一个非负整数。匹配确定的 n 次。例如,’a{2}’ 能匹配 “baac” 中的两个 a, 但是不能匹配bac中的一个a。
{n,} n 是一个非负整数。至少匹配n 次。例如,’a{2,}’ 不能匹配 “bac” 中的一个a,但能匹配 “baaaac” 中的全部a。
{n,m} m 和 n 均为非负整数,其中n <= m。最少匹配 n 次且最多匹配 m 次。例如,”a{1,3}” 将匹配 “baaaaaac”中的前三个a。注意:在逗号和两个数之间不能有空格。

ansible playbook

Roles

Roles 就是通过分别将变量、文件、任务、模块及处理器放置于单独的目录中,并可以便捷地 include 它们

http://www.ansible.com.cn/docs/playbooks_roles.html#roles

1
2
3
4
5
6
7
8
9
10
11
└── roles
└── k8s
├── files 用来存放由 copy 模块或 script 模块调用的文件
├── library
├── tasks 包含一个 main.yml 文件,用于定义此角色的任务列表,此文件可以使用 include 包含其它的位于此目录的 task 文件
└── vars 包含一个 main.yml 文件,用于定义此角色用到的变量
└──templates 用来存放正则模板,template 模块会自动在此目录中寻找正则模板文件
└──handlers 此目录应当包含一个 main.yml 文件,用于定义此角色中触发条件时执行的动作
└──defaults 此目录应当包含一个 main.yml 文件,用于为当前角色设定默认变量
└──meta 此目录应当包含一个 main.yml 文件,用于定义此角色的特殊设定及其依赖关系
.......

根据情况删减目录

目录

cni /opt/cni/bin

cni config /etc/cni/net.d

containerd /etc/containerd/config.toml

crictl /etc/crictl.yaml

ansible安装使用入门

安装

准备

下载地址

https://github.com/ansible/ansible/releases

设置源

cs@debian:~$ cat ~/.pip/pip.conf
[global]
trusted-host=mirrors.aliyun.com
index-url=http://mirrors.aliyun.com/pypi/simple/

get-pip.py

This is a Python script that uses some bootstrapping logic to install pip.

  • Download the script, from https://bootstrap.pypa.io/get-pip.py.

  • Open a terminal/command prompt, cd to the folder containing the get-pip.py file and run:

    Linux

    1
    $ python get-pip.py

No module named ‘distutils.cmd’ #依赖 python3.x-distutils

export PATH=”$HOME/.local/bin:$PATH”

开始

cd ansible-xxx

安装依赖

pip install –user -r ./requirements.txt

正式安装

python setup.py install

ansible –version

pkg_resources.DistributionNotFound: The ‘jinja2’

pip list 查看,执行用户没有安装该模板

自定义cmd命令

typora没有details快捷的插入标签功能,对xml这种折叠不行,其他文本还可以

脚本

/home/cs/.local/custom/details.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
xdetails_helpdoc(){
cat <<EOF
Description:
处理文档,方便粘贴到typora,实现折叠效果
Usage:
xdetails file
eg:
xdetails /home/cs/data/kvm/default.xml
--------------------------------------------------
<details>
<summary>折叠代码块</summary>
<pre><a>xxxx</a><xmp>
<network>
<input type='tablet' bus='usb'>
<address type='usb' bus='0' port='1'/>
</input>
</network>
</xmp></pre>
</details>
------------------------------------------------------
EOF
}



xdetails_space(){
cat >$2<<EOF
<details>
<summary>折叠代码块</summary>
<pre><a>xxxx</a><code>
EOF

sed "s/^$/<\/br>/" $1 >>$2

cat >>$2<<EOF
</code></pre>
</details>
EOF

echo "对${1##*.}文本使用</br>替换标签。。。"

}



xdetails_xml(){

cat >$2<<EOF
<details>
<summary>折叠代码块</summary>
<pre><a>xxxx</a><xmp>
EOF

sed "/^$/d" $1 >>$2

cat >>$2<<EOF
</xmp></pre>
</details>
EOF

echo "对xml文本使用xmp标签处理。。。"

}


details(){
target="/tmp/${1##*/}.new"
if [ -f "$1" ]
then
[ "xml" = "${1##*.}" ] || { echo "开始对:${1##*/} 处理。。。" && xdetails_space $1 $target ;}
[ "xml" != "${1##*.}" ] || { echo "开始对:${1##*/} 处理。。。" && xdetails_xml $1 $target;}
cat $target | xsel -i -b && echo "已复制到剪贴板中"
echo "新文件路径:$target"
else
xdetails_helpdoc
fi
}

把定义脚本统一放到custom目录

截取分割

#$%

格式 说明
${string: start :length} 从 string 字符串的左边第 start 个字符开始,向右截取 length 个字符。
${string: start} 从 string 字符串的左边第 start 个字符开始截取,直到最后。
${string: 0-start :length} 从 string 字符串的右边第 start 个字符开始,向右截取 length 个字符。
${string: 0-start} 从 string 字符串的右边第 start 个字符开始截取,直到最后。
${string#*chars} 从 string 字符串第一次出现 *chars 的位置开始,截取 *chars 右边的所有字符。
${string##*chars} 从 string 字符串最后一次出现 *chars 的位置开始,截取 *chars 右边的所有字符。
${string%*chars} 从 string 字符串第一次出现 *chars 的位置开始,截取 *chars 左边的所有字符。
${string%%*chars} 从 string 字符串最后一次出现 *chars 的位置开始,截取 *chars 左边的所有字符。
1
var=https://github.com/csyuancode/csyuancode.github.io/tree/master/js

#

从左边开始截取删除保留匹配剩下字符

1
2
3
4
5
6
7
8
9
10
cs@debian:~/oss/hexo$ var=https://github.com/csyuancode/csyuancode.github.io/tree/master/js

#一次匹配
cs@debian:~/oss/hexo$ echo ${var#*cs}
yuancode/csyuancode.github.io/tree/master/js

##最后一次匹配
cs@debian:~/oss/hexo$ echo ${var##*cs}
yuancode.github.io/tree/master/js

%

从末尾开始往前删除保留匹配剩下字符

1
2
3
4
5
6
7
8
9
cs@debian:~/oss/hexo$ var=https://github.com/csyuancode/csyuancode.github.io/tree/master/js

#截取从后面开始第一次cs前字符
cs@debian:~/oss/hexo$ echo ${var%cs*}
https://github.com/csyuancode/

#截取从后面开始最一次cs前字符
cs@debian:~/oss/hexo$ echo ${var%%cs*}
https://github.com/

containerd安装

Installing containerd

https://github.com/containerd/containerd/releases

1
2
$ tar -zxvf  ../containerd-1.6.19-linux-amd64.tar.gz
scp ./bin/* root@k8s01:/usr/local/bin

Warning: Permanently added ‘k8s01,192.168.122.11’ (ECDSA) to the list of known hosts.
containerd 100% 50MB 172.4MB/s 00:00
containerd-shim 100% 7180KB 167.3MB/s 00:00
containerd-shim-runc-v1 100% 9248KB 161.9MB/s 00:00
containerd-shim-runc-v2 100% 9264KB 169.7MB/s 00:00
containerd-stress 100% 22MB 146.9MB/s 00:00
ctr 100% 26MB 193.4MB/s 00:00

载入天数...载入时分秒... ,