Auto-sync: 2026-04-22 04:02

This commit is contained in:
2026-04-22 04:03:04 +08:00
parent 24218550d2
commit de096f2f88
232 changed files with 16604 additions and 514 deletions

View File

@@ -0,0 +1,120 @@
# 软链接策略
> 使用符号链接Symbolic Link实现软件版本管理和无缝切换的最佳实践。
## Overview
软链接策略是一种软件版本管理技术,通过创建指向不同版本目录的符号链接,实现:
- 简化启动命令
- 实现无缝版本升级
- 避免配置文件中的硬编码路径
## Core Concept
```
/opt/frp/
├── frp_0.65.0_darwin_arm64/ # 实际安装目录
├── frp_0.66.0_darwin_arm64/ # 新版本目录
└── current -> frp_0.65.0_darwin_arm64/ # 软链接指向 current
```
## Why Use Symlinks?
| 优势 | 说明 |
|------|------|
| 简化路径 | 启动命令使用 `/opt/frp/current/frpc` 而非长版本号路径 |
| 快速升级 | 只需修改软链接,无需更新配置或启动脚本 |
| 版本回滚 | 出现问题时快速切换回旧版本 |
| 保持兼容性 | 配置文件中使用稳定路径,升级不受影响 |
## Implementation
### 创建软链接
```bash
# 创建指向特定版本的软链接
ln -sfn /opt/frp/frp_0.65.0_darwin_arm64 /opt/frp/current
# 验证
ls -la /opt/frp/current
# lrwxr-xr-x 1 user staff 35 Apr 14 10:00 /opt/frp/current -> frp_0.65.0_darwin_arm64
```
### 升级版本
```bash
# 1. 下载并解压新版本
wget https://github.com/fatedier/frp/releases/download/v0.66.0/frp_0.66.0_darwin_arm64.tar.gz
tar -xzf frp_0.66.0_darwin_arm64.tar.gz
# 2. 停止旧版本服务
launchctl stop com.frpc.client
# 或
pkill frpc
# 3. 切换软链接
ln -sfn /opt/frp/frp_0.66.0_darwin_arm64 /opt/frp/current
# 4. 验证
ls -la /opt/frp/current # 确认指向新版本
# 5. 启动服务
launchctl start com.frpc.client
```
### 回滚版本
```bash
# 停止服务
launchctl stop com.frpc.client
# 切换回旧版本
ln -sfn /opt/frp/frp_0.65.0_darwin_arm64 /opt/frp/current
# 启动服务
launchctl start com.frpc.client
```
## Launchd Integration
```xml
<key>ProgramArguments</key>
<array>
<string>/opt/frp/current/frpc</string> <!-- 使用软链接路径 -->
<string>-c</string>
<string>/opt/frp/current/frpc.toml</string>
</array>
```
## Best Practices
### Directory Structure
```
/opt/<software>/
├── <software>_v1.0.0/
├── <software>_v1.1.0/
├── <software>_v1.2.0/
├── current -> <software>_v1.2.0/
└── configs/ # 可选:配置文件独立存放
├── v1.0.0.toml
├── v1.1.0.toml
└── current.toml -> v1.2.0.toml
```
### Naming Convention
- 版本目录:`<name>_v<major>.<minor>.<patch>_<platform>_<arch>`
- 软链接名称:`current`(行业标准)或 `<name>-latest`
### Security Considerations
1. **保持链接目标存在**:删除旧版本前确保软链接已切换
2. **使用绝对路径**`ln -sfn` 使用绝对路径避免相对路径问题
3. **验证后再启动**:切换后验证软链接,再启动服务
## Use Cases
- **FRP**:版本升级无需修改 launchd plist
- **Docker**:使用 `:latest` 标签的软链接等价物
- **Node.js**nvm 使用软链接管理多版本
- **Python**pyenv 使用软链接切换版本
## Related Concepts
- [[frp]] — 软链接策略的典型应用场景
- [[launchd]] — 使用软链接路径的服务管理
- [[内网穿透]] — 需要版本管理的服务
## References
- `man ln`
- `man readlink`