Docker是一个容器化平台,它允许你将应用程序及其依赖项打包到轻量级、可移植的容器中。容器类似于虚拟机,但更加高效。
核心概念:
在博客系统的运维中,数据备份是至关重要的环节。VanBlog作为一个现代化的博客系统,提供了完善的自动备份功能,不仅支持本地JSON数据备份,还集成了阿里云盘云端备份。本文将深入分析这个功能的实现原理、架构设计和优化过程。
VanBlog的自动备份功能位于 /admin/site/setting?tab=autoBackup
,主要包含以下特性:
--skip
参数避免重复传输在文章的增删改操作后,系统现在会自动触发标签同步功能,无需手动点击"同步标签数据"按钮。这个功能通过异步方式实现,不会影响用户体验。
原系统存在以下性能瓶颈:
渲染 = 把动态数据转换成静态HTML文件的过程
VanBlog使用Next.js的 ISR(Incremental Static Regeneration 增量静态再生成) 技术:
这个博客的方法是我看数据库数据的,不懂的不要轻易使用,直接用博客系统带的备份方案,直接导出json 和 图片。
VanBlog的数据主要存储在MongoDB中,包含以下重要数据:
需要保留的数据(文章数据):
articles
- 文章内容drafts
- 草稿categories
- 分类tags
- 标签(如果有的话)customPages
- 自定义页面moments
- 动态viewers
- 浏览量统计visits
- 访问记录需要重新配置的数据(系统配置):
metas
- 站点信息(包含域名配置)users
- 用户信息settings
- 系统设置tokens
- API令牌UV 是一个由 Astral 团队开发的高性能 Python 环境管理工具,它集成了包管理、虚拟环境管理和 Python 版本管理等功能。以下是使用 UV 管理 Python 环境的主要步骤和方法:
UV 可以通过多种方式安装:
bash展开代码pip install uv
bash展开代码curl -LsSf https://astral.sh/uv/install.sh | sh
powershell展开代码irm https://astral.sh/uv/install.ps1 | iex
uv --version
验证安装。vmware 的 dns 问题 导致 git pull失败:
nslookup github.com
github.com
的 DNS 解析是否正确,确认是否返回 GitHub 的真实 IP(如 20.205.243.166
)。echo "nameserver 8.8.8.8" > /etc/resolv.conf
github.com
指向 127.0.0.1
。ssh-keygen -f "/root/.ssh/known_hosts" -R "github.com"
ssh -T git@github.com
yes
后即可正常认证。更离谱的是,有时候这个文件只是软连接,可以看看这样:
bash展开代码ls -l /etc/resolv.conf
sudo rm /etc/resolv.conf
echo "nameserver 8.8.8.8" > /etc/resolv.conf
sudo chattr +i /etc/resolv.conf # 锁定文件(防止被覆盖)
sudo systemctl stop systemd-resolved # 禁用 systemd-resolved(可选)
sudo systemctl disable systemd-resolved
在 Ubuntu 服务器上执行以下命令:
bash展开代码# 安装必要的包
sudo apt update
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
# 添加 Caddy 官方 GPG 密钥
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
# 添加 Caddy 仓库
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
# 安装 Caddy
sudo apt update
sudo apt install caddy
/.well-known/acme-challenge/
路径发送HTTP请求验证域名控制权清理无用镜像/容器/卷/网络
使用以下命令一键清理所有未被使用的资源(包含停止的容器、悬空镜像、未使用的网络和卷):
bash展开代码docker system prune -a --volumes
-a
:删除所有未被容器引用的镜像(不仅仅是悬空镜像)。--volumes
:删除未被使用的卷(⚠️ 确保卷中无重要数据!)。单独清理不同资源
停止的容器:
bash展开代码docker container prune
悬空镜像(未被任何容器引用):
bash展开代码docker image prune
未被使用的卷:
bash展开代码docker volume prune
构建缓存(Builder Cache):
bash展开代码docker builder prune
在 VMware 中扩容虚拟磁盘后,Linux 系统并不会自动识别新增的空间,需要手动扩展分区和文件系统。本教程以 GPT 分区表 + ext4/xfs 文件系统为例,详细介绍如何安全扩展 /dev/sda3
分区,使其占用全部可用空间。
sudo
bash展开代码echo "nameserver 8.8.8.8" > /etc/resolv.conf
看是否可以正常解析:
bash展开代码nslookup github.com
确定里面没有乱指:
bash展开代码vim /etc/hosts
一个极其快速的 Python 包和项目管理工具,用 Rust 编写。
我们在日常开发中,经常要用到这些工具:
pip
:安装依赖pipx
:安装命令行工具poetry
或 rye
:管理项目和虚拟环境pyenv
:切换 Python 版本virtualenv
:创建虚拟环境pip-tools
:锁定依赖版本twine
:发布包临时有效:
展开代码export http_proxy="http://127.0.0.1:10828" export https_proxy="http://127.0.0.1:10828" sudo -E apt update # -E 保留环境变量 sudo -E apt upgrade