最近 AI 画图很火,最常用的工具就是 Stable Diffusion 了,这里记录一下部署过程。
代理设置
安装过程中如果是国内服务器,下载模块会很慢,所以需要设置代理。这里使用 ssr + privoxy 的方式。
下载 ssr client
1
2
3
4
5
6
7
8
9
10
11
12
  | sudo apt update  
sudo apt upgrade
sudo apt install wget zip unzip python3-m2crypto libsodium23
wget https://s3.tok.ap.cloud-object-storage.appdomain.cloud/xzdl/manyuser.zip
sha256sum manyuser.zip
unzip manyuser.zip
mv shadowsocksr-manyuser shadowsocksr
  | 
客户端配置
1
  | sudo vi /etc/shadowsocks.json
  | 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  | {
  "server": "server_ip",
  "server_ipv6": "",
  "server_port": 1443,
  "local_address": "127.0.0.1",
  "local_port": 1080,
  "password": "password",
  "timeout": 300,
  "udp_timeout": 60,
  "method": "none",
  "protocol": "auth_chain_a",
  "protocol_param": "",
  "obfs": "tls1.2_ticket_auth_compatible",
  "obfs_param": "",
  "fast_open": false,
  "workers": 1
}
 | 
启动客户端
1
2
3
4
5
6
7
8
  | cd shadowsocksr/shadowsocks
sudo python local.py -c /etc/shadowsocks.json -d start
sudo tail -f /var/log/shadowsocksr.log
# 测试
curl --socks5-hostname 127.0.0.1:1080 ip.gs
  | 
安装 privoxy
1
  | sudo apt-get install privoxy
  | 
更改privoxy配置
1
2
3
4
5
6
  | sudo vi /etc/privoxy/config
# 在里面添加:
forward-socks5 /  127.0.0.1:1080 .
listen-address localhost:8118
  | 
重启 privoxy
1
2
3
4
  | service privoxy restart
# 测试
http_proxy=http://localhost:8118 curl ip.gs
  | 
设置命令行代理
1
2
3
4
5
6
7
  | alias goproxy='export http_proxy=http://127.0.0.1:8118 https_proxy=http://127.0.0.1:8118'
alias disproxy='unset http_proxy https_proxy'
# 测试
goproxy
curl ip.gs
  | 
创建账号
因为 stable diffusion 不能使用 root 用户,所以需要创建一个新用户。
1
2
3
4
5
6
7
8
9
  | useradd -d /home/sd -m sd -s /bin/bash
passwd sd
# 删除用户
userdel sd
# 切换成 sd 用户
su sd
cd /home/sd
  | 
安装 Stable Diffusion WebUI
1
2
3
4
  | sudo apt install wget git python3 python3-venv
# 执行SD安装脚本
bash <(wget -qO- https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh)
  | 
修改参数
1
2
3
4
5
6
7
8
9
  | # webui-user.sh
# 设置成远程可访问 可以安装下载扩展
export COMMANDLINE_ARGS="--listen --enable-insecure-extension-access"
# 设置不需要代理的地址
export no_proxy="localhost, 127.0.0.1"
# 装一下 xformers 模块
COMMANDLINE_ARGS="--reinstall-xformers --xformers"
  | 
下载模型
1
2
3
4
5
  | apt intall git-lfs
git lfs clone https://huggingface.co/Kanbara/doll-likeness-series
wget https://huggingface.co/naonovn/chilloutmix_NiPrunedFp32Fix/resolve/main/chilloutmix_NiPrunedFp32Fix.safetensors
  | 
参考链接
- 比较火的Lora模型
 - ubutun 安装 ssr
 - 远程服务器安装 SD
 - 服务器中SD无法安装扩展问题
 - SD WebUI启动问题
 - xformers 模块
 
模型列表
https://huggingface.co/jomcs/NeverEnding_Dream-Feb19-2023/ https://huggingface.co/naonovn/chilloutmix_NiPrunedFp32Fix/