Skip to content

服务器与发行版选择 ​

发行版决定的不只是 yum 还是 apt,还决定软件包版本、systemd 版本、内核特性、支持周期。选错了,后面每个中间件都要额外编译。

一、先看这台机器是什么 ​

bash
cat /etc/os-release
uname -r
getconf GNU_LIBC_VERSION
text
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 9dnf到 2032企业服务器首选(CentOS 替代)
AlmaLinux 9dnf到 2032同 Rocky,二选一
Ubuntu 22.04 / 24.04 LTSapt5 年(可扩展 10 年)云原生、AI、开发环境
Debian 12apt约 5 年稳定优先,软件包偏旧
CentOS 7yum已 EOL(2024-06)只维护存量,不新建
CentOS Stream 9/10dnf跟随 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.14eBPF、cgroup v2、io_uring 不可用
OpenSSL 1.0.2 vs 3.0TLS 1.3、部分加密套件不可用
默认 Python 2 vs 3脚本兼容性

查 glibc 是排查"二进制跑不起来"的第一步:

bash
ldd --version
./some-binary
text
./some-binary: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by ./some-binary)

只能换发行版、用容器跑,或在目标系统上重新编译。

四、包管理器速查 ​

操作dnf/yumapt
更新索引dnf makecacheapt update
升级全部dnf updateapt upgrade
装包dnf install nginxapt install nginx
卸包dnf remove nginxapt remove nginx
搜索dnf search nginxapt search nginx
看包信息dnf info nginxapt show nginx
看文件属于谁rpm -qf /usr/sbin/nginxdpkg -S /usr/sbin/nginx
看包里的文件rpm -ql nginxdpkg -L nginx
已装列表rpm -qa | grep nginxdpkg -l | grep nginx
清缓存dnf clean allapt 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 --version
text
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包被 holdapt-mark showhold 查,确认后 unhold