Linux 安装
三种装法:物理机/虚拟机、云主机、容器;以及分区怎么划。
Key Points学习用虚拟机或 WSL 最省事;生产用云主机;只想跑个命令用容器。分区至少要有 / 和 swap。
三种装法
| Way | Effort | Best for |
|---|---|---|
| Virtual machine | Low, reversible | Learning, trying distros |
| Cloud host | Minutes, costs money | Anything with a public IP |
| Container | Seconds | Running commands, not a full system |
| Bare metal / dual boot | High risk | Daily driver |
虚拟机里装
Bash
# VirtualBox / VMware:新建虚拟机 → 挂 ISO → 启动 → 按向导装
# 建议配置:2 CPU、4GB 内存、20GB 磁盘、网络选 NAT + 端口转发分区怎么划
| Mount | Size | Why |
|---|---|---|
/ | 20-40GB | Root filesystem |
swap | = memory, or 2GB | Hibernate and OOM cushion |
/home | Rest | Survives reinstall |
/var | 10-20GB | Logs and databases can explode |
装完先做
Bash
sudo apt update && sudo apt upgrade -y # Debian/Ubuntu
sudo dnf upgrade -y # RHEL/Rocky
sudo apt install -y vim curl git htop # 常用工具
sudo systemctl enable --now ssh # 允许远程登录A separate
/var is old ops wisdom: logs filling the root filesystem locks you out entirely. On containers or cloud hosts, at least configure log rotation.三种装法
| 方式 | 成本 | 适合 |
|---|---|---|
| 虚拟机 | 低,可回滚 | 学习、试发行版 |
| 云主机 | 几分钟,要花钱 | 需要公网 IP 的场景 |
| 容器 | 秒级 | 跑命令,不是完整系统 |
| 物理机/双系统 | 风险高 | 日常主力机 |
虚拟机里装
Bash
# VirtualBox / VMware:新建虚拟机 → 挂 ISO → 启动 → 按向导装
# 建议配置:2 CPU、4GB 内存、20GB 磁盘、网络选 NAT + 端口转发分区怎么划
| 挂载点 | 大小 | 原因 |
|---|---|---|
/ | 20-40GB | 根文件系统 |
swap | 等于内存,或 2GB | 休眠与内存不足缓冲 |
/home | 剩余 | 重装系统不丢数据 |
/var | 10-20GB | 日志与数据库容易暴涨 |
装完先做
Bash
sudo apt update && sudo apt upgrade -y # Debian/Ubuntu
sudo dnf upgrade -y # RHEL/Rocky
sudo apt install -y vim curl git htop # 常用工具
sudo systemctl enable --now ssh # 允许远程登录给
/var 单独分区是运维的老经验:日志写满根分区会让整机登录不进去。用容器或云主机时,至少给日志配好轮转。