安装后第一小时:Rocky 9 的 7 项核对(附实测输出)
什么时候该用它
Section titled “什么时候该用它”系统刚装完、还没跑业务,是改配置成本最低的时候。这 7 项核对完,后面装服务、开端口、排障都会少踩坑。能容器实测的给实测输出;依赖 systemd / SELinux 运行态的,明确标「需在真实系统执行」。
1. 版本与仓库
Section titled “1. 版本与仓库”cat /etc/rocky-releasednf repolist --enabledRocky Linux release 9.3 (Blue Onyx)repo id repo nameappstream Rocky Linux 9 - AppStreambaseos Rocky Linux 9 - BaseOSextras Rocky Linux 9 - Extras默认只启用这三个源,CRB 没有启用。需要 glibc-static、*-devel 这类包时,临时 --enablerepo=crb 即可,不必永久打开。
2. 时区与时间同步
Section titled “2. 时区与时间同步”ls -l /etc/localtimetimedatectl statuslrwxrwxrwx. 1 root root 25 ... /etc/localtime -> ../usr/share/zoneinfo/UTC容器里 /etc/localtime 指向 UTC,timedatectl 不可用(无 systemd)。在真实系统上执行 timedatectl set-timezone Asia/Shanghai,并确认 systemctl status chronyd 为 active。
3. 主机名
Section titled “3. 主机名”cat /etc/hostnamehostnamectl容器里 /etc/hostname 是随机容器 ID;真实系统用 hostnamectl set-hostname app01.example.com,改完 hostname -f 应返回 FQDN。
4. SELinux 模式
Section titled “4. SELinux 模式”getenforcesestatus | head -5需在真实系统执行:容器没有 SELinux 运行态,
getenforce会返回Disabled或命令不存在。Rocky 9 安装后默认是 enforcing,不要在部署时用setenforce 0掩盖问题,而是用ausearch/sealert定位。
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 install -y yum-utilssudo dnf -y updatesudo needs-restarting -rNo core libraries or services have been updated since boot-up.Reboot should not be necessary.needs-restarting -r 退出码 0 表示不用重启,1 表示需要。它由 yum-utils 提供(不是 dnf-plugins-core)。
7. 最小化 vs DVD 的差别
Section titled “7. 最小化 vs DVD 的差别”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 分钟核对清单”对一台新装的 Rocky 9 逐条执行并记录结果:
dnf repolist --enabled→ 恰为 baseos/appstream/extras(CRB 未启用)timedatectl status | grep "Time zone"→ 与你期望的时区一致hostname -f→ 返回 FQDN(不是 localhost)getenforce→Enforcingfirewall-cmd --zone=public --list-services→ 只有 cockpit/dhcpv6-client/sshneeds-restarting -r; echo $?→0rpm -q firewalld chrony→ 两个都有输出
- 放行端口:firewall-cmd 放行端口
- 离线装包:离线环境装包
- 安全基线:安全基线