128 lines
5.8 KiB
Markdown
128 lines
5.8 KiB
Markdown
---
|
||
title: "Ubuntu 安装 FRP 0.65.0(x86_64)操作笔记"
|
||
type: source
|
||
tags: [frp, frpc, ubuntu, systemd, x86_64]
|
||
date: 2026-04-14
|
||
---
|
||
|
||
## Source File
|
||
- [[raw/Home Office/Ubuntu 安装 FRP 0.65.0(x86_64)操作笔记.md]]
|
||
|
||
## Summary (用中文描述)
|
||
- **核心主题**:在 Ubuntu Server 24.04(x86_64/amd64)上安装配置 FRP 0.65.0 内网穿透客户端,实现通过公网 VPS 远程访问本地 SSH 服务
|
||
- **问题域**:Linux 服务器运维、内网穿透、服务管理
|
||
- **方法/机制**:通过 FRP(frpc)客户端连接远程 VPS(frps)建立反向隧道,通过 systemd 实现开机自启和进程管理
|
||
- **结论/价值**:提供完整的 Ubuntu Server FRP 运维手册,包含 systemd 服务管理、最佳实践和故障排查指南;与 Mac Mini ARM64 版本形成完整的多平台覆盖
|
||
|
||
## Key Claims (用中文描述)
|
||
- Ubuntu Server 24.04 需手动创建 `/opt/frp` 安装目录
|
||
- FRP 0.65.0 使用 TOML 配置文件格式(frpc.toml)
|
||
- systemd 是 Ubuntu/Linux 生产环境推荐的服务管理方式
|
||
- 通过软链接(symlink)策略可实现版本无缝切换,无需修改 systemd 配置
|
||
- journald 日志是 systemd 环境的推荐日志管理方案
|
||
|
||
## Key Quotes
|
||
> "login to server success" — frpc 成功连接 frps 的日志标志
|
||
> "proxy added: ssh" — SSH 代理成功注册的日志标志
|
||
> "Restart=on-failure + RestartSec=10" — systemd 服务自动恢复配置,确保服务中断后自动重启
|
||
> "升级时只需要切换 symlink,无需修改 systemd 配置" — 软链接策略的核心价值
|
||
|
||
## Key Concepts
|
||
- [[内网穿透]]:通过反向隧道技术,使公网用户能够访问处于 NAT 或防火墙后的内网服务
|
||
- [[frp]]:Fast Reverse Proxy,开源内网穿透工具,包含 frps(服务端)和 frpc(客户端)
|
||
- [[TCP隧道]]:基于 TCP 协议的端口转发机制,将本地端口映射到远程服务器
|
||
- [[systemd]]:Linux 系统和服务管理器,Ubuntu Server 的默认初始化系统,用于管理 FRP 客户端开机自启
|
||
- [[软链接策略]]:通过 `/opt/frp/current` 软链接指向具体版本目录,实现版本切换无需修改 systemd 配置
|
||
|
||
## Key Entities
|
||
- [[VPS]]:公网虚拟专用服务器,运行 frps 作为内网穿透的中转站(IP: 192.227.222.142,端口: 7000)
|
||
- [[frpc]]:FRP 客户端程序,运行在 Ubuntu Server 上,建立与 frps 的反向隧道
|
||
- [[frps]]:FRP 服务端程序,运行在 VPS 上,监听 7000 端口,接收 frpc 连接并转发请求
|
||
- [[Ubuntu Server]]:Canonical 维护的 Linux 服务器操作系统,本次安装目标为 24.04 LTS 版本
|
||
- [[systemd]]:Linux 系统和服务管理器,Ubuntu Server 24.04 的默认初始化系统
|
||
|
||
## Connections
|
||
- [[Ubuntu Server]] ← runs_on ← [[frpc]]
|
||
- [[VPS]] ← runs_on ← [[frps]]
|
||
- [[frpc]] ← creates_tunnel ← [[frps]]
|
||
- [[systemd]] ← manages ← [[frpc]] 进程生命周期
|
||
- [[内网穿透]] ← enables ← [[远程SSH访问]]
|
||
- [[软链接策略]] ← simplifies ← [[版本升级]](无需修改 systemd 配置)
|
||
|
||
## Contradictions
|
||
- 与 [[mac-mini-安装-frp-0-65-0-arm64-操作笔记]] 存在**平台差异**:
|
||
- 差异点:服务管理机制(Ubuntu 用 systemd,macOS 用 launchd)
|
||
- 当前观点:systemd 是 Linux 生产环境标准,配置简单(service 文件 + systemctl 命令)
|
||
- 对方观点:launchd 是 macOS 原生方案,通过 plist + launchctl 管理
|
||
- 结论:两个平台均推荐各自原生的服务管理机制,不存在优劣之分,只是生态差异
|
||
|
||
## Environment Details
|
||
| 项目 | 内容 |
|
||
|------|------|
|
||
| 系统 | Ubuntu Server 24.04 LTS |
|
||
| 架构 | x86_64 (amd64) |
|
||
| 软件 | FRP 0.65.0 |
|
||
| 安装目录 | `/opt/frp/frp_0.65.0_linux_amd64` |
|
||
| 客户端程序 | `frpc` |
|
||
| 配置文件 | `frpc.toml` |
|
||
| 服务管理 | systemd |
|
||
| frps服务器 | 192.227.222.142:7000 |
|
||
| frps认证token | your_token_here |
|
||
| frps映射端口 | 6000(本地 SSH 22 → 远程 6000)|
|
||
|
||
## Installation Steps
|
||
1. 创建安装目录:`sudo mkdir -p /opt/frp && sudo chown -R $(whoami) /opt/frp`
|
||
2. 下载 x86_64 版本:`wget https://github.com/fatedier/frp/releases/download/v0.65.0/frp_0.65.0_linux_amd64.tar.gz`
|
||
3. 解压:`tar -xzf frp_0.65.0_linux_amd64.tar.gz`
|
||
4. 配置 frpc.toml:设置 serverAddr、serverPort、auth.token 和 [[proxies]] 数组
|
||
5. 测试运行:`./frpc -c frpc.toml`,验证 "login to server success"
|
||
6. 创建 systemd 服务文件:`/etc/systemd/system/frpc.service`
|
||
7. 启用开机自启:`sudo systemctl daemon-reload && sudo systemctl enable --now frpc`
|
||
|
||
## Configuration Reference
|
||
```toml
|
||
serverAddr = "192.227.222.142"
|
||
serverPort = 7000
|
||
|
||
[auth]
|
||
token = "your_token_here"
|
||
|
||
[[proxies]]
|
||
name = "ssh"
|
||
type = "tcp"
|
||
localIP = "127.0.0.1"
|
||
localPort = 22
|
||
remotePort = 6000
|
||
```
|
||
|
||
## systemd Service Template
|
||
```ini
|
||
[Unit]
|
||
Description=frp client
|
||
After=network-online.target
|
||
Wants=network-online.target
|
||
|
||
[Service]
|
||
Type=simple
|
||
ExecStart=/opt/frp/frp_0.65.0_linux_amd64/frpc -c /opt/frp/frp_0.65.0_linux_amd64/frpc.toml
|
||
Restart=on-failure
|
||
RestartSec=10
|
||
|
||
[Install]
|
||
WantedBy=multi-user.target
|
||
```
|
||
|
||
## Maintenance Commands
|
||
- 查看状态:`sudo systemctl status frpc`
|
||
- 查看日志:`sudo journalctl -u frpc -f`
|
||
- 重启服务:`sudo systemctl restart frpc`
|
||
- 停止服务:`sudo systemctl stop frpc`
|
||
- 禁用开机自启:`sudo systemctl disable frpc`
|
||
|
||
## Best Practices
|
||
1. **软链接策略**:创建 `/opt/frp/current` → 具体版本目录的软链接,systemd 配置使用 current 路径
|
||
2. **日志管理**:使用 journald(journalctl)管理日志,支持实时流式查看和历史记录
|
||
3. **配置验证**:使用 `./frpc validate -c frpc.toml` 验证配置文件语法后再重启服务
|
||
4. **防火墙检查**:确保 frps 服务器端口(7000)和映射端口(6000)在防火墙中开放
|
||
5. **版本管理**:多版本并存于 `/opt/frp/` 下,通过软链接切换,systemd 配置保持不变
|