AlmaLinux 9:新装系统的 7 项核对
在 almalinux:9 容器(AlmaLinux 9.8,aarch64)中实际执行:cat /etc/almalinux-release、dnf repolist --enabled、ls -l /etc/localtime、cat /etc/hostname、安装 firewalld 后 firewall-offline-cmd、安装 yum-utils 后 needs-restarting -r。日志:plans/content-expansion/evidence/logs/alma-first-steps.log。
timedatectl、getenforce、hostnamectl 依赖 systemd / SELinux 运行态,容器不可用,未在本环境实测。
1. 版本与默认仓库
Section titled “1. 版本与默认仓库”cat /etc/almalinux-releasednf repolist --enabledAlmaLinux release 9.8 (Olive Jaguar)repo id repo nameappstream AlmaLinux 9 - AppStreambaseos AlmaLinux 9 - BaseOSextras AlmaLinux 9 - Extras默认只有这三个源,CRB 未启用。需要 glibc-static、*-devel 时用 --enablerepo=crb 临时开,不必永久启用。
2. 时区与时间同步
Section titled “2. 时区与时间同步”ls -l /etc/localtimelrwxrwxrwx ... /etc/localtime -> ../usr/share/zoneinfo/UTC容器默认 UTC。真实系统上用 timedatectl set-timezone Asia/Shanghai,并确认 systemctl status chronyd 为 active(需真实系统)。
3. 主机名
Section titled “3. 主机名”cat /etc/hostname容器里是随机容器 ID;真实系统用 hostnamectl set-hostname app01.example.com,hostname -f 应返回 FQDN(需真实系统)。
4. SELinux
Section titled “4. SELinux”getenforcesestatus | head -5需真实系统:容器没有 SELinux 运行态。AlmaLinux 9 安装后默认为 enforcing;排查用
ausearch -m avc与sealert,不要用setenforce 0掩盖。
5. 防火墙默认值
Section titled “5. 防火墙默认值”firewall-offline-cmd --get-default-zonefirewall-offline-cmd --zone=public --list-servicespubliccockpit dhcpv6-client ssh默认 zone 是 public,只放行 cockpit、dhcpv6-client、ssh。开新服务记得放行端口:/firewalld-zones/。
6. 更新与重启需求
Section titled “6. 更新与重启需求”sudo dnf -y install yum-utilssudo dnf -y updatesudo needs-restarting -rNo core libraries or services have been updated since boot-up.Reboot should not be necessary.退出码 0 表示不用重启,1 表示需要。命令来自 yum-utils,不是 dnf-plugins-core。
7. 最小化安装的包基线
Section titled “7. 最小化安装的包基线”dnf list installed | wc -lrpm -q firewalld chrony需真实系统:容器是精简 rootfs,包数不可比。真实最小化安装通常 400–600 个包,且不一定预装
firewalld与chrony;用rpm -q确认,缺了用dnf install -y firewalld chrony再systemctl enable --now。
练习:10 分钟核对
Section titled “练习:10 分钟核对”在一台新装 AlmaLinux 9 上逐条执行并记录:
dnf repolist --enabled→ 恰为 baseos/appstream/extrastimedatectl status | grep "Time zone"→ 与预期一致hostname -f→ FQDNgetenforce→Enforcingfirewall-cmd --zone=public --list-services→ 只有三个默认服务needs-restarting -r; echo $?→0rpm -q firewalld chrony→ 两个都有输出
常见问题
为什么 `dnf repolist` 里没有 crb?
CRB 默认不启用。需要构建依赖时用 `--enablerepo=crb` 临时打开,或按需在 repo 文件里永久启用;默认保持关闭可减少包来源混杂。
容器里 `getenforce` 显示 Disabled 正常吗?
正常。容器没有 SELinux 运行态,这个结果不代表真实主机。真实 AlmaLinux 9 安装后默认 enforcing,请在主机上核对。
`needs-restarting` 提示需要重启,能直接重启吗?
先看它报告的是内核还是核心库更新,确认业务已做维护窗口与健康检查再重启;不确定时先 `dnf history list` 看这轮更新装了什么。
- 放行端口:firewall-cmd 放行端口
- 事务回滚:dnf history undo
- 离线装包:离网装包