记一下不常用的,基于Debian
Docker
安装
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
更换国内源
echo "{\"registry-mirrors\": [\"http://hub-mirror.c.163.com\"]}" >> /etc/docker/daemon.json
systemctl restart docker
服务器体检脚本
融合怪一键脚本
curl -L https://gitlab.com/spiritysdx/za/-/raw/main/ecs.sh -o ecs.sh && chmod +x ecs.sh && bash ecs.sh
IP体检
bash <(curl -Ls IP.Check.Place)
使用acme.sh配置域名证书
后续考虑写个一键脚本
以域名为a.example.com,acme.sh版本为v3.0.8为例
curl https://get.acme.sh | sh -s email=youremail
source ~/.bashrc
acme.sh --set-default-ca --server letsencrypt
mkdir -p /var/www/letsencrypt
mkdir -p /etc/nginx/ssl/a.example.com
echo "server {
listen 80;
listen [::]:80;
server_name a.example.com;
location /.well-known/acme-challenge {
root /var/www/letsencrypt;
}
location / {
rewrite ^/(.*)$ https://\$host/\$1 permanent;
}
}" >> /etc/nginx/conf.d/a.example.com.conf
nginx -s reload
acme.sh --issue -d a.example.com -w /var/www/letsencrypt
cp /root/.acme.sh/a.example.com_ecc/a.example.com* /etc/nginx/ssl/a.example.com/
cp /root/.acme.sh/a.example.com_ecc/fullchain.cer /etc/nginx/ssl/a.example.com/
acme.sh --install-cert -d a.example.com \
--key-file /etc/nginx/ssl/a.example.com/a.example.com.key \
--fullchain-file /etc/nginx/ssl/a.example.com/a.example.com.cer \
--ca-file /etc/nginx/ssl/a.example.com/a.example.com.ca.cer \
--reloadcmd "nginx -s reload"
sed -i '4i\
listen 443 ssl;\
ssl_certificate /etc/nginx/ssl/a.example.com/a.example.com.cer;\
ssl_certificate_key /etc/nginx/ssl/a.example.com/a.example.com.key;\
ssl_trusted_certificate /etc/nginx/ssl/a.example.com/a.example.com.ca.cer;\
' /etc/nginx/conf.d/a.example.com.conf
nginx -s reload
安装php
apt install php8.2 php8.2-cli php8.2-{bz2,curl,mbstring,intl} php8.2-fpm php8.2-mysql -y
Rclone挂载Gdrive
连接服务器采用以下命令,将服务器的端口映射到本地的端口,后面要用到,用于访问浏览器
ssh -L localhost:53682:localhost:53682 user@ip
配置rclone
curl https://rclone.org/install.sh | sudo bash
rclone config
选择google drive,其他都默认即可,后面会有一个链接,在浏览器打开用于google授权,获取token。rclone配置完成。
挂载
mkdir /gdrive
apt install -y fuse3
rclone mount gdrive: /gdrive --allow-other --allow-non-empty --vfs-cache-mode off --daemon
我采用-–vfs-cache-mode off,不使用本地缓存,不建议。
详细配置可参考 https://rclone.cn/rclone_mount.html
取消挂载:
fusermount -qzu /gdrive
ffmpeg
转为m3u8格式
ffmpeg -i a.mp4 -c:v h264_videotoolbox -b:v 3M -s 1920x1080 -hls_time 10 -hls_list_size 0 a/a.m3u8
-c:v采用h264_videotoolbox硬编码,也可选用hevc_videotoolbox,这两个选择都是在mac m2芯片可选的,服务器上不一定有,可采用libx264软编码。经过测试,hevc编码的m3u8无法在ios浏览器直接播放。
yt-dlp
支持下载很多视频网站视频,自测了yt和bilibili,b站电影不可用。bilibili需要配置cookie,在本地使用的话可以加上--cookies-from-browser chrome
安装
需要python3环境,不支持低版本,没记错的话要3.9以上
pip3 install yt-dlp
自选版
yt-dlp -F 'url'
yt-dlp -f 401+140 --recode-video mp4 'url'
无脑版
yt-dlp -f "bestvideo[ext=mp4][vcodec^=avc]+bestaudio" --recode-video mp4 'url'
vcodec^=avc: avc格式能在ios设备直接播放。
自动化备份脚本
可以备份多个目录,每个目录保存最新的十份
#!/bin/bash
SOURCE_DIRS=("/data" "/www/wwwroot")
BACKUP_DIR="/gdrive"
if [ ! -d "$BACKUP_DIR" ]; then
mkdir -p "$BACKUP_DIR"
fi
for DIR in "${SOURCE_DIRS[@]}"; do
DIR_NAME=$(basename "$DIR")
DIR_BACKUP_DIR="${BACKUP_DIR}/${DIR_NAME}"
if [ ! -d "$DIR_BACKUP_DIR" ]; then
mkdir -p "$DIR_BACKUP_DIR"
fi
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
ZIP_FILE="${DIR_NAME}_${TIMESTAMP}.zip"
cd "$(dirname "$DIR")" || exit
zip -r -q "$ZIP_FILE" "$(basename "$DIR")" -x "*.DS_Store"
mv "$ZIP_FILE" "$DIR_BACKUP_DIR"
cd "$DIR_BACKUP_DIR" || exit
ls -t | tail -n +11 | xargs rm -f
done
添加定时任务
crontab -e
添加
0 0 * * * /path/backup2gdrive.sh