外观
服务器与发行版选择
发行版决定的不只是 yum 还是 apt,还决定软件包版本、systemd 版本、内核特性、支持周期。选错了,后面每个中间件都要额外编译。
一、先看这台机器是什么
bash
cat /etc/os-release
uname -r
getconf GNU_LIBC_VERSIONtext
NAME="Rocky Linux"
VERSION="9.4 (Blue Onyx)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.4"
PLATFORM_ID="platform:el9"
5.14.0-427.37.1.el9_4.x86_64
glibc 2.34三条信息决定了一切:
ID_LIKE决定包管理器和目录规范。- 内核版本决定 eBPF、cgroup v2、io_uring 等特性可用性。
- glibc 版本决定二进制程序能不能跑(很多预编译包要求 glibc 2.17/2.28+)。
二、主流选择
| 发行版 | 包管理 | 支持周期 | 适用 |
|---|---|---|---|
| Rocky Linux 9 | dnf | 到 2032 | 企业服务器首选(CentOS 替代) |
| AlmaLinux 9 | dnf | 到 2032 | 同 Rocky,二选一 |
| Ubuntu 22.04 / 24.04 LTS | apt | 5 年(可扩展 10 年) | 云原生、AI、开发环境 |
| Debian 12 | apt | 约 5 年 | 稳定优先,软件包偏旧 |
| CentOS 7 | yum | 已 EOL(2024-06) | 只维护存量,不新建 |
| CentOS Stream 9/10 | dnf | 跟随 RHEL 滚动 | 想提前验证 RHEL 特性 |
CentOS 7 已停止维护
2024 年 6 月 EOL 后不再有安全更新。存量机器要么迁 Rocky/Alma,要么买 RHEL 订阅。新项目一律不要用。
选择建议:
text
传统企业应用、中间件 → Rocky 9 或 Alma 9
容器 / K8s / AI 工具链 → Ubuntu 22.04 LTS
追求极致稳定、不折腾 → Debian 12三、版本差异带来的实际影响
| 差异 | 后果 |
|---|---|
| glibc 2.17(CentOS 7) vs 2.34(Rocky 9) | 新版预编译二进制在 CentOS 7 上跑不了 |
| systemd 219 vs 252 | 新版 unit 指令(如 Restart=on-abnormal 的细节)行为不同 |
| 内核 3.10 vs 5.14 | eBPF、cgroup v2、io_uring 不可用 |
| OpenSSL 1.0.2 vs 3.0 | TLS 1.3、部分加密套件不可用 |
| 默认 Python 2 vs 3 | 脚本兼容性 |
查 glibc 是排查"二进制跑不起来"的第一步:
bash
ldd --version
./some-binarytext
./some-binary: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by ./some-binary)只能换发行版、用容器跑,或在目标系统上重新编译。
四、包管理器速查
| 操作 | dnf/yum | apt |
|---|---|---|
| 更新索引 | dnf makecache | apt update |
| 升级全部 | dnf update | apt upgrade |
| 装包 | dnf install nginx | apt install nginx |
| 卸包 | dnf remove nginx | apt remove nginx |
| 搜索 | dnf search nginx | apt search nginx |
| 看包信息 | dnf info nginx | apt show nginx |
| 看文件属于谁 | rpm -qf /usr/sbin/nginx | dpkg -S /usr/sbin/nginx |
| 看包里的文件 | rpm -ql nginx | dpkg -L nginx |
| 已装列表 | rpm -qa | grep nginx | dpkg -l | grep nginx |
| 清缓存 | dnf clean all | apt clean |
五、离线安装
内网机器没有外网时:
bash
# RHEL 系:连同依赖一起下载
dnf install --downloadonly --downloaddir=/tmp/rpms nginx
# 拷到目标机器
rpm -ivh /tmp/rpms/*.rpm
# Debian 系
apt download nginx
apt-get install --download-only nginx更省事的做法是搭本地仓库(createrepo / apt-mirror),或者用容器镜像分发。
六、检查清单
拿到新机器,先跑:
bash
cat /etc/os-release | head -4
uname -r
getconf GNU_LIBC_VERSION
systemctl --version | head -1
openssl version
python3 --versiontext
VERSION="9.4 (Blue Onyx)"
5.14.0-427.37.1.el9_4.x86_64
glibc 2.34
systemd 252 (252-32.el9_4.7)
OpenSSL 3.0.7 1 Nov 2022
Python 3.9.18把这五项记到资产表里,后面装中间件时对照版本要求。
七、踩过的坑
| 现象 | 根因 | 处置 |
|---|---|---|
预编译二进制报 GLIBC_2.28 not found | 系统 glibc 太老 | 换系统或用容器 |
| 装了 nginx 但版本很老 | 发行版自带源版本旧 | 加官方源或源码编译 |
dnf update 后服务起不来 | 内核/库大版本升级 | 生产禁止无脑全量升级 |
| CentOS 7 上装不了新软件 | EOL 源失效 | 换 Rocky/Alma |
apt 报 held packages | 包被 hold | apt-mark showhold 查,确认后 unhold |