auto setup stable diffusion environment under aliyun virtual gpu instance



# system
apt-get update -q && apt-get -y upgrade -q

# install packages
apt-get -y install -q curl git jq python3 python3-pip python3-venv python3-dev tmux unzip wget zip p7zip-full nfs-client

# aliyun setup nvidia driver
acs-plugin-manager --exec --plugin grid_driver_install

# nfs mount(fast prepare data and models)
mkdir /mnt/shared
mount -t nfs -o vers=3,nolock,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport location.cn-guangzhou.nas.aliyuncs.com:/ /mnt/shared

# download and extract stable diffusion
mkdir /data && cd /data 
7z x /mnt/shared/scys/sd.7z
cd sd
cp /mnt/shared/scys/sd_models/* models/Stable-diffusion
7z x /mnt/shared/scys/sd_venv.7z 

# prepare python env(first time)
# pip config set global.index-url https://mirrors.bfsu.edu.cn/pypi/web/simple
# pip install -q torch==2.0.1+cu118 torchvision==0.15.2+cu118 torchaudio==2.0.2+cu118 torchtext==0.15.2 torchdata==0.6.1 --extra-index-url https://mirror.sjtu.edu.cn/pytorch-wheels
# pip install -q xformers==0.0.20 triton==2.0.0 gradio_client==0.2.7
# pip install -q -i https://mirrors.aliyun.com/pypi/simple/ tb-nightly cython

wget -q https://iscys.com/github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x cloudflared-linux-amd64
nohup ./cloudflared-linux-amd64 tunnel --url 2>&1 > /tmp/cloudflared.log &
sleep 3s && grep -o 'https://.*\.trycloudflare.com' /tmp/cloudflared.log | head -n 1 | xargs -I {} echo "Your tunnel url {}"

# install zerotier
# curl -s https://install.zerotier.com | bash 
# zerotier-cli join [ZONE_ID]

# install docker
#curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh --mirror aliyun
#docker up -d ollama:ollama 

# optional: install ollama
# export HTTPS_PROXY=http://proxy_host:port
# curl -fsSL https://ollama.com/install.sh | sh

# remove aliyun aegis
wget http://update.aegis.aliyun.com/download/uninstall.sh && chmod +x uninstall.sh &&./uninstall.sh
wget http://update.aegis.aliyun.com/download/quartz_uninstall.sh && chmod +x quartz_uninstall.sh && ./quartz_uninstall.sh
sudo rm -r /usr/local/aegis
sudo systemctl disable aliyun.service
sudo rm /usr/sbin/aliyun-service
sudo rm /usr/sbin/aliyun-service.backup
sudo rm /usr/sbin/aliyun_installer
sudo rm /etc/systemd/system/aliyun.service
sudo rm /lib/systemd/system/aliyun.service
rm uninstall.sh quartz_uninstall.sh


  • add docker support
  • add zerotier support
  • send shared url to email
  • setup systemd service for stable diffusion