5.6 KiB
title, type, aliases, tags
| title | type | aliases | tags | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Ubuntu Server | entity |
|
|
Ubuntu Server
Overview
Ubuntu Server 是由 Canonical 维护的 Linux 服务器操作系统,提供服务器优化的发行版,不包含图形桌面环境。Ubuntu Server 24.04 LTS 是当前的长期支持版本(LTS),默认使用 systemd 作为初始化系统,SSH 默认使用 ssh.socket(按需激活)替代传统的 sshd 持续运行模式。
Key Characteristics
|| 特性 | 说明 | |------|------| | 维护周期 | LTS 版本 5 年安全更新(Extended Security Maintenance 额外 5 年)| | 默认初始化系统 | systemd | | SSH 默认配置 | ssh.socket(按需激活),可切换为 ssh.service | | 软件包管理 | APT (apt/apt-get) | | 内核 | 通用 Linux 内核,支持云镜像、容器优化镜像等 | | 适用场景 | 云服务器、物理服务器、容器宿主机、边缘计算 |
Ubuntu Server 24.04 的关键变化
1. SSH 默认使用 Socket Activation
Ubuntu 24.04 SSH 服务默认使用 ssh.socket(按需激活):
- ssh.socket:无 SSH 连接时不运行 sshd 进程,节省资源
- ssh.service:传统模式,sshd 持续运行
- 切换方法:
# 切换到传统模式(推荐服务器)
sudo systemctl disable --now ssh.socket
sudo systemctl enable --now ssh.service
# 切回按需模式
sudo systemctl disable --now ssh.service
sudo systemctl enable --now ssh.socket
2. Netplan 网络配置
Ubuntu Server 使用 Netplan(YAML 配置)管理网络:
# /etc/netplan/00-installer-config.yaml
network:
version: 2
renderer: networkd # 或 NetworkManager
ethernets:
eth0:
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
sudo netplan apply # 应用配置
sudo netplan generate # 生成 systemd-networkd 配置
sudo netplan debug # 调试配置
3. Snap vs APT
Ubuntu 提供了两套包管理生态:
- APT:传统 Debian 包管理,deb 包,/var/lib/apt/lists 存储索引
- Snap:Canonical 开发的容器化包格式,自包含依赖,自动更新
- 典型场景:FRP 建议使用 APT 安装二进制或手动解压,不建议 snap
Common Operations
安装软件
sudo apt update # 更新软件包索引
sudo apt install -y <package> # 安装软件包
sudo apt remove <package> # 卸载软件包
sudo apt autoremove # 清理不再需要的依赖
系统更新
sudo apt update && sudo apt upgrade -y # 更新所有包
sudo apt full-upgrade -y # 包含内核更新的完整升级
sudo do-release-upgrade # 升级到新版本
用户管理
sudo adduser <username> # 创建用户
sudo usermod -aG sudo <username> # 添加到 sudo 组
sudo visudo # 编辑 sudoers 文件
防火墙 (UFW)
sudo ufw status # 查看状态
sudo ufw allow 22/tcp # 开放 SSH
sudo ufw allow 80/tcp # 开放 HTTP
sudo ufw enable # 启用防火墙
sudo ufw disable # 禁用防火墙
服务管理 (systemd)
sudo systemctl status <service> # 查看服务状态
sudo systemctl enable --now <service> # 开机自启并立即启动
sudo systemctl restart <service> # 重启服务
sudo journalctl -u <service> -f # 查看服务日志
Snap 操作
snap list # 列出已安装的 snap
snap install <package> # 安装 snap
snap remove <package> # 卸载 snap
snap refresh # 更新所有 snap
Ubuntu Server vs Ubuntu Desktop
| 方面 | Ubuntu Server | Ubuntu Desktop |
|---|---|---|
| 默认包 | 无 GUI,服务器工具 | GUI 桌面环境 |
| 内核 | 服务器优化内核 | 桌面优化内核 |
| SSH | 已预装 | 需手动安装 |
| 资源占用 | 轻量(~500MB RAM) | 较重(~2GB RAM) |
| 适用场景 | 云服务器、NAS、容器宿主机 | 开发工作站 |
| 更新频率 | LTS 优先稳定性 | 更频繁的新特性 |
Home Server Applications on Ubuntu Server
|Ubuntu Server 是家庭服务器的理想选择: |- NAS 存储:Samba/NFS/RAID 配置,NFS 永久挂载到 Synology NAS |- Docker 容器:Portainer/Transmission/Jellyfin/Navidrome |- FRP 内网穿透:frpc 连接公网 VPS |- NFS 客户端:通过 nfs-common 挂载 Synology NAS 共享文件夹,配合 rsync 实现增量备份 |- rsync 自动化:定时任务执行 rsync 增量同步到 NAS,配合挂载点检查防止数据写入本地磁盘
Related Concepts
- systemd — Ubuntu Server 的默认初始化系统
- UFW 防火墙 — Ubuntu Server 推荐的防火墙工具
- Docker — Ubuntu Server 常用容器运行时
- 内网穿透 — FRP 在 Ubuntu Server 上的应用场景
- Cron定时任务 — Ubuntu Server 定时任务管理
Related Entities
- VPS — Ubuntu Server 常部署在公网 VPS 上作为 frps 服务端
- 群晖 NAS — Ubuntu Server vs 群晖 NAS 的功能对比
- frp — 在 Ubuntu Server 上运行的 frpc 客户端
References
- Ubuntu Server Documentation: https://ubuntu.com/server/docs
- Ubuntu 24.04 LTS Release Notes: https://discourse.ubuntu.com/t/noble-numbat-release-notes/