Featured image of post Ubuntu 发行版实战:22.04 / 24.04 server 装机、换源、netplan、LVM、ufw 防火墙

Ubuntu 发行版实战:22.04 / 24.04 server 装机、换源、netplan、LVM、ufw 防火墙

2024 视角下的 Ubuntu 装机全流程——Ubuntu 22.04 LTS 装机 U 盘制作(Rufus/UltraISO)、清华/中科大/Ubuntu cn 源切换、netplan 静态 IP、systemd-resolved DNS、ufw 防火墙、LVM on RAID10、24.04 安装流程

一、为什么是 2024 年这一份

2024 年这个时间点是 Ubuntu 的关键节点:

  • Ubuntu 22.04 LTS (Jammy Jellyfish) —— 2022-04 发布,2027-04 维护到期,2024 主力
  • Ubuntu 24.04 LTS (Noble Numbat) —— 2024-04 发布,2027-04 起进入主流
  • netplan 已成 Ubuntu 网络配置唯一方式(interfaces 退场)
  • systemd-resolved 是 DNS 解析默认
  • ufw 是 iptables 之上最常用的防火墙前端
  • Linux Mint 21.2 “Victoria”(2022)基于 Ubuntu 22.04 LTS,内核 5.15

这一篇覆盖 Ubuntu 22.04 / 24.04 server 装机、U 盘制作、换源(清华 / 中科大 / 阿里云)、netplan 静态 IP、systemd-resolved DNS、ufw 防火墙、LVM on RAID10、Linux Mint 美化——Ubuntu 装机一站式手册。

阅读建议:本文按"先看版本 → 选对应章节"组织。22.04 与 24.04 大部分操作通用,差异点单独标注。

二、Ubuntu 22.04 装机流程

2.1 下载镜像

1
2
3
4
# 官方下载
https://cn.ubuntu.com/download/server/step1

# 22.04.2 live-server-amd64.iso

2.2 U 盘制作工具

工具平台特点
RufusWindows轻量、绿色版、首选
imageUSBWindows老牌工具
UltraISOWindows老牌但被 Rufus 取代
balenaEtcher跨平台macOS / Linux 也用
1
2
# Rufus 4.0 绿色版
https://github.com/pbatard/rufus/releases/download/v4.0/rufus-4.0p.exe

2.3 U 盘写入步骤

  1. 打开 Rufus
  2. 选择下载的 ISO
  3. 选择 U 盘
  4. 默认设置(MBR / FAT32)即可
  5. 点"开始"等完成

关于 UEFI vs Legacy:UEFI 模式建议选 GPT;Legacy 模式选 MBR。Rufus 默认是 MBR + BIOS,UEFI 需要手动改。

三、换源:清华 / 中科大 / 阿里云

3.1 清华源(22.04)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 备份
mv /etc/apt/sources.list /etc/apt/sources.listbak

# 写入清华源
cat > /etc/apt/sources.list << "EOF"
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
EOF

apt update

# 还原
mv /etc/apt/sources.listbak /etc/apt/sources.list

3.2 中科大源

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
cat << "EOF" > /etc/apt/sources.list
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
EOF

3.3 sed 一键替换

1
2
# 默认 cn.archive.ubuntu.com 替换为清华
sed -i 's/http://cn.archive.ubuntu.com/https://mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list

四、netplan 网络配置

4.1 静态 IP(22.04)

1
vim /etc/netplan/00-installer-config.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
network:
  ethernets:
    eno1:
      dhcp4: false
      addresses:
        - 192.168.10.127/24
      routes:
        - to: default
          via: 192.168.10.1
      nameservers:
        addresses: [211.138.24.66, 114.114.114.114, 192.168.10.1]
    eno2:
      dhcp4: true
    eno3:
      dhcp4: true
    eno4:
      dhcp4: true
  version: 2
1
netplan apply

YAML 严格缩进:netplan 对 YAML 缩进敏感,缩进错一个空格都可能报错。

4.2 改回 DHCP

1
2
3
4
5
6
7
8
9
cat > /etc/netplan/00-installer-config.yaml << "EOF"
network:
  ethernets:
    eno1:
      dhcp4: true
  version: 2
EOF

netplan apply

五、systemd-resolved DNS

5.1 配置

1
vim /etc/systemd/resolved.conf
1
2
3
4
5
6
7
8
9
[Resolve]
# Some examples of DNS servers which may be used for DNS= and FallbackDNS=:
# Cloudflare: 1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com ...
# Google:     8.8.8.8#dns.google 8.8.4.4#dns.google ...
# Quad9:      9.9.9.9#dns.quad9.net ...
#DNS=
DNS=114.114.114.114

systemctl restart systemd-resolved

5.2 验证

1
2
3
resolvectl status
# 或
cat /run/systemd/resolve/resolv.conf

关于 /etc/resolv.conf:Ubuntu 17.10+ 的 /etc/resolv.conf 是软链接到 /run/systemd/resolve/stub-resolv.conf手动修改 /etc/resolv.conf 重启后失效。正确做法是改 /etc/systemd/resolved.conf

六、ufw 防火墙

6.1 启用与默认策略

1
2
3
4
# 启用
ufw enable
# 默认拒绝入站
ufw default deny

6.2 查看规则

1
ufw status numbered
1
2
3
4
5
6
Status: active
     To                         Action      From
     --                         ------      ----
[ 1] 22/tcp                     ALLOW IN    Anywhere
[ 2] 80/tcp                     ALLOW IN    Anywhere
[ 3] 443/tcp                    ALLOW IN    Anywhere

6.3 添加规则

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 允许指定端口
ufw allow 22

# 允许指定服务
ufw allow ssh

# 允许指定 IP
ufw allow from 192.168.1.0/24

# 允许指定 IP + 端口
ufw allow from 192.168.1.100 to any port 3306

6.4 删除规则

1
2
3
4
5
# 按编号删除
ufw delete 3

# 按规则删除
ufw delete allow 3690

6.5 禁用

1
ufw disable

七、磁盘挂载到已有目录

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 1. 查磁盘
fdisk -l

# 2. 假设要把 /dev/sdb1 挂到 /home
# 如果 /home 已有内容,先备份
cp -r /home /home.bak

# 3. 卸载(如果已挂)
umount /home

# 4. 创建文件系统
mkfs.ext4 /dev/sdb1

# 5. 挂载
mount /dev/sdb1 /home

# 6. 还原内容
cp -r /home.bak/* /home/
chown -R <原用户>:<原组> /home/<原用户>

# 7. 写 fstab 永久挂载
echo "UUID=$(blkid -s UUID -o value /dev/sdb1) /home ext4 defaults 0 2" >> /etc/fstab

# 8. 测试
mount -a

八、Ubuntu 24.04 (Noble Numbat) 装机全流程

8.1 RAID10 + LVM 分区方案

服务器场景:4 块 40G 盘做 RAID10 + LVM

用途大小类型
/boot1Gext4
/30Gext4
/home48.9Gext4

可用空间计算:4 块 40G RAID10 可用 80G,分配:1G boot + 30G / + 48.9G /home ≈ 80G(留少量未分配)。

8.2 装机步骤

  1. 启动安装器(VMware 中引导)
  2. 选择语言:English
  3. 选择键盘:English (US)
  4. 选择类型:Ubuntu Server (minimized)
  5. 配置网络
    • 选 eno1
    • 选 Edit IPv4
    • 选 Manual
    • Subnet: 192.168.132.0/24
    • Address: 192.168.132.139
    • Gateway: 192.168.132.2
    • Name servers: 192.168.132.2
    • Search domains: 114.114.114.114
  6. 配置代理:留空
  7. 配置源
    • 替换 http://cn.archive.ubuntu.com/ubuntu/https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
  8. 自定义分区
    • 选第一块盘 /dev/sda
    • Use As Boot Device
    • /dev/sda 留 unformatted
    • /dev/sdb、sdc、sdd 同样 unformatted
  9. 创建 RAID10:4 块盘全部加入
  10. 创建 LVM
    • 在 RAID10 上建 VG(vg0)
    • 建 LV:lv-0(1G 给 /boot)、lv-1(30G 给 /)、lv-2(48.9G 给 /home)
  11. 格式化
    • lv-0 → ext4 → /boot
    • lv-1 → ext4 → /
    • lv-2 → ext4 → /home
  12. 配置用户:username/password
  13. 是否升级到 pro:选 Skip
  14. 安装 OpenSSH Server:勾选
  15. 可选软件:留空
  16. 开始安装
  17. 重启

8.3 装机后基本配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 1. 登录
# 用创建的用户登录

# 2. 启用 root
sudo passwd root
# 输入当前用户密码
# 输入新 root 密码
# 确认 root 密码

# 3. 切换到 root
su
# 输入 root 密码

# 4. 启动 root 远程 SSH
sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
systemctl restart ssh

# 5. 测试远程登录
# 用 ssh root@<host> 验证

# 6. 上传公钥开私钥登录
curl https://<your-internal-file-server>/id_rsa.pub -o /root/id_rsa.pub --create-dirs
mkdir -p /root/.ssh && touch /root/.ssh/authorized_keys
cat /root/id_rsa.pub >> /root/.ssh/authorized_keys
rm -f /root/id_rsa.pub

# 7. 禁用密码登录
sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl restart ssh

8.4 装机后查磁盘

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
lsblk
# NAME            MAJ:MIN RM  SIZE RO TYPE   MOUNTPOINTS
# sda               8:0    0   40G  0 disk
# ├─sda1            8:1    0    1M  0 part
# └─sda2            8:2    0   40G  0 part
#   └─md0           9:0    0 79.9G  0 raid10
#     ├─vg0-lv--0 252:0    0    1G  0 lvm    /boot
#     ├─vg0-lv--1 252:1    0   30G  0 lvm    /
#     └─vg0-lv--2 252:2    0 48.9G  0 lvm    /home
# sdb               8:16   0   40G  0 disk
# └─sdb1            8:17   0   40G  0 part
#   └─md0           9:0    0 79.9G  0 raid10
# ...

8.5 fstab 验证

1
2
3
4
5
6
cat /etc/fstab
# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/vg0/lv-1 during curtin installation
/dev/disk/by-id/dm-uuid-LVM-... / ext4 defaults 0 1

关于 /dev/disk/by-id/dm-uuid-LVM-...:24.04 用 /dev/disk/by-id/ 路径而不是传统的 /dev/vg0/lv-1,这是 curiin 安装器做的"稳定路径"映射,避免 LV 顺序变化时挂错。

九、Linux Mint 21.2 “Victoria” 美化

Linux Mint 21.2 “Victoria”(2022 年发布)底层仍是 Ubuntu 22.04 LTS,内核采用 Linux 5.15

9.1 安装

  1. 选择兼容性安装
  2. 进入桌面点击安装
  3. 选择中文简体
  4. 安装解码器
  5. 键盘布局默认 Chinese
  6. 分区自动
  7. 等待安装
  8. 重启完成

9.2 Windows 11 迁移验证

常用软件列表:Chrome、VSCode、Office、Notion、QQ、微信等。

9.3 美化

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 1. 安装 plank(仿 macOS 的 dock)
sudo apt install -y plank
# 开机自启动
sudo ln -s /usr/share/applications/plank.desktop /etc/xdg/autostart/

# 2. 添加 dock 图标
vim ~/.config/plank/dock1/launchers/firefox.dockitem
# [PlankDockItemPreferences]
# Launcher=file:///usr/share/applications/firefox.desktop

# 3. 装 Numix 主题(圆角图标)
sudo add-apt-repository ppa:numix/ppa
sudo apt update
sudo apt install numix-icon-theme-circle

十、Ubuntu 装机常见问题

10.1 apt-get update 报 GPG 错

1
2
3
4
W: GPG error: ... NO_PUBKEY 648ACFD622F3D138

# 解决:换 HTTPS 源
apt install apt-transport-https ca-certificates

10.2 中文乱码 / locale 设置

1
2
3
4
5
6
# 生成 zh_CN.UTF-8
locale-gen zh_CN.UTF-8
update-locale LANG=zh_CN.UTF-8

# 立即生效
export LANG=zh_CN.UTF-8

10.3 安装 SSH 后 root 登录被拒

1
2
3
4
5
6
# 检查 sshd_config
grep -i "PermitRootLogin\|PasswordAuthentication" /etc/ssh/sshd_config

# 启用 root
sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
systemctl restart ssh

十一、前置知识 / 下一步

  • 想看 Debian 9/10/11 装机 → 翻本系列《Debian 家族发行版全指南》
  • 想看 LVM 详细操作 → 翻本系列《Linux 磁盘与 LVM 深度实践》
  • 想看 netplan 高级配置(VLAN、bridge、bond)→ 翻独立文章
  • 想看 ufw 高级配置(rate limit、IPv6)→ 翻独立文章
  • 想看 Deepin 桌面 + Wine → 翻本系列《Deepin 与 Kali 发行版实战》

十二、参考资源


2024+ 视角:写于 2024-11,半年后 Ubuntu 24.04.2 LTS 已成"实战稳定版"

本文写于 2024-11-15——半年后(2025 年中)Ubuntu 24.04 已发布 24.04.2(2025-02)LTS 更新。

一、Ubuntu 24.04 LTS 半年回顾(2024-11 → 2025-05)

  • Ubuntu 24.04.1 LTS(2024-08):首个点版本,大量 bug 修复
  • Ubuntu 24.04.2 LTS(2025-02):第二个点版本,硬件 enablement kernel(5.15 → 6.8 HWE)。
  • Ubuntu 24.10(2024-10 发布,非 LTS):半年版,体验 Gnome 47。
  • Ubuntu 25.04(2025-04 发布,非 LTS):半年版。
  • LTS 长期支持
    • 标准支持:到 2029-04(5 年)
    • Ubuntu Pro / ESM到 2034-04(10 年)

二、Ubuntu 24.04 LTS 装机后的"坑"

2024-11 装机半年后,最常见的"踩坑"

  • netplan + NetworkManager 双管理器冲突——必须只用一个
  • IPv6 PD 默认开启默认防火墙没放行——手动配置
    1
    
    ufw allow in proto ipv6
    
  • snap store 服务snapd)开机很慢——可以禁掉:
    1
    2
    
    systemctl disable --now snapd.service snapd.socket snapd.seeded.service
    apt purge snapd
    
  • systemd-resolved 与 resolvconf 冲突——apt purge resolvconf

三、Ubuntu 24.04 + AI 生态

  • Ubuntu 24.04 起 官方支持 NVIDIA AI Workbench
  • Snap 商店 集成 LLM 工具(Ollama / LM Studio)。
  • Python 3.12 + CUDA 12.x + PyTorch 2.4 是 2024 AI 训练首选环境。
1
2
3
4
5
6
# 2024 AI 开发环境
sudo apt install -y python3.12 python3.12-venv
curl -fsSL https://ollama.com/install.sh | sh
ollama pull llama3.1:8b
# 本地 LLM 跑通
ollama run llama3.1:8b

四、Linux Mint 22 (Wilma) 2024 发布

  • Linux Mint 22 “Wilma”(2024-08 发布):基于 Ubuntu 24.04 LTS
  • Cinnamon 6.2 桌面(Linux Mint 招牌)。
  • Linux Mint Edge(基于 Debian 13 testing,滚动版)。

五、Ubuntu Pro 2024 变化

  • Ubuntu Pro(2023 起个人免费 5 台机器):
    • 10 年安全更新(LTS 5 年 + ESM 5 年)
    • CIS hardeningFIPS 140-2Livepatch
    • 覆盖 apt 仓库额外 5 年(23,000+ 包)
  • 个人 Pro:免费 5 台机器(2023-09 起)。
  • 企业 Pro:付费,含 Landscape、Ansible、Support。
1
2
3
4
# 启用 Ubuntu Pro
sudo pro attach
sudo pro enable livepatch
sudo pro enable esm-apps esm-infra

六、Netplan 0.106+ 新特性(24.04)

  • Netplan 0.106(2024 起):
    • Open vSwitch 支持
    • TC(traffic control) 配置
    • VRF(Virtual Routing and Forwarding)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# netplan VRF 配置
network:
  version: 2
  vrfs:
    vrf-red:
      table: 1000
      interfaces: [eno1]
  ethernets:
    eno1:
      dhcp4: false

七、UFW 2024 增强

  • UFW 0.36+(2024):ufw app 命令管理应用配置。
  • ufw limit 限速(防爆破):
1
2
3
# 限制 SSH 速率(防爆破)
ufw limit 22/tcp comment "SSH 速率限制"
# 默认每 30 秒 6 次连接
  • ufw route 路由规则(高级用法):
1
2
# 允许从 10.0.0.0/8 到 192.168.1.100:3306
ufw route allow from 10.0.0.0/8 to 192.168.1.100 port 3306 proto tcp

八、Ubuntu Server 24.04 的"云原生"姿势

  • 2024 起 Ubuntu Server 默认安装 multipass + LXD(K8s / 容器)。
  • LXD 5.21+(2024 LTS):支持 GPU 直通(AI 训练 / 推理)。
  • Multipass 1.14+云镜像本地跑(VM-based 容器)。
1
2
3
4
5
# LXD 起 GPU 容器
lxc launch ubuntu:24.04 ai-vm --vm -c limits.cpu=4 -c limits.memory=8GiB --gpu

# Multipass 起 K8s 集群
multipass launch --name k8s-1 --cpus 4 --memory 8G --disk 50G

九、apt 2.7+ 的 DEB822 格式

  • apt 2.7+(Ubuntu 24.04):支持 DEB822 格式.sources 文件)—— 比传统 .list 更结构化。
1
2
3
4
5
6
# /etc/apt/sources.list.d/ubuntu.sources
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
  • 优势支持多个签名 key更清晰的注释snap 集成更顺

十、Ubuntu 24.04 与 snap 的"恩怨"

  • 2024 视角:snap 在 Ubuntu Server 24.04 仍是默认——snap install 装 chromium、code、spotify。
  • 争议
    • snap 应用启动慢(10+ 秒)
    • snap 占用磁盘大(多版本共存)
    • 不能完全卸载 snap(apt purge snapd 后部分应用受影响)
  • 替代
    • apt 装(chromium chromium-browser
    • Flatpak(跨发行版)
    • AppImage(单文件可执行)

十一、Ubuntu 24.04 LTS 装机"经验教训"半年汇总

  • 装好后必做

    1. apt update && apt upgrade -y(首次 24.04.0 → 24.04.2)
    2. 配时区 / NTPtimedatectl set-timezone Asia/Shanghai
    3. 禁用 snap(如果不想要)
    4. 配 sshd:禁止 root 密码登录、强制 ed25519
    5. 配 ufw:放行 22 + 必要端口
    6. 装 fail2ban:防 SSH 爆破
  • 2024 推荐装机方式

    • 云厂商:直接用云市场镜像(Ubuntu 24.04 LTS + 云厂商优化)
    • 本地:Ventoy + Ubuntu 24.04 ISO + manual 分区(LVM on LUKS)
使用 Hugo 构建
主题 StackJimmy 设计