centos7和centos8 命令差别?

CentOS 7 和 CentOS 8 虽然都属于 Red Hat Enterprise Linux(RHEL)衍生的发行版,但它们之间在底层架构、默认工具和命令行管理方式上有显著差别。以下是 CentOS 7 与 CentOS 8 常用命令和系统管理方面的差异总结:


🔧 一、初始化系统 / 进程管理

功能 CentOS 7 CentOS 8
初始化系统 SysVinit + systemd 混合使用 完全使用 systemd
启动服务 service <服务名> start systemctl start <服务名>
开机自启服务 chkconfig <服务名> on systemctl enable <服务名>
查看运行级别 runlevel systemctl get-default
切换运行级别 init <level> systemctl set-default <target>

📦 二、软件包管理器

功能 CentOS 7 CentOS 8
默认包管理器 yum dnf(yum 的下一代)
安装软件包 yum install 包名 dnf install 包名
升级软件包 yum update dnf upgrade
清除缓存 yum clean all dnf clean all
搜索包 yum search 包名 dnf search 包名
查看依赖关系 yum deplist 包名 dnf repoquery --requires 包名

💡 CentOS 8 中推荐使用 dnf,虽然仍支持 yum,但它是 dnf 的软链接。


🖥️ 三、网络管理

功能 CentOS 7 CentOS 8
网络配置文件位置 /etc/sysconfig/network-scripts/ifcfg-* 使用 nmclinmtui,配置文件位于 /etc/NetworkManager/system-connections/
网络重启命令 systemctl restart network nmcli connection reload
查看 IP 地址 ifconfig(需安装 net-tools) 推荐使用 ip addrnmcli device show
防火墙 iptablesfirewalld 默认使用 nftables 后端的 firewalld

🔐 四、防火墙管理

功能 CentOS 7 CentOS 8
默认防火墙 firewalld(使用 iptables 后端) firewalld(使用 nftables 后端)
开放端口 firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
同样使用 firewall-cmd,但底层是 nftables

📁 五、文件系统 & 挂载

功能 CentOS 7 CentOS 8
默认文件系统 XFS(也支持 ext4) XFS(仍是默认)
挂载配置文件 /etc/fstab(格式类似) /etc/fstab
LVM 支持 支持 更好支持 LVM 及 Stratis(新文件系统管理器)

🔄 六、模块化 & 应用流(Application Streams)

功能 CentOS 7 CentOS 8
模块化支持 不支持 引入了 Application Streams(AppStream)仓库,允许并行安装多个版本的应用程序(如 Python 3.6 和 3.9)
安装模块化应用 N/A dnf module install <module-name>:<stream>

🐍 七、Python 版本

功能 CentOS 7 CentOS 8
默认 Python Python 2.x(兼容性为主) Python 3.x(默认为 Python 3.6)
Python 命令 python(指向 Python 2) python(指向 Python 3)
安装 Python 3 需额外安装 已默认安装

🛠️ 八、其他常用命令变化

功能 CentOS 7 CentOS 8
用户添加 useradd useradd(功能一致)
修改密码 passwd 用户名 同上
查看日志 journalctl 存在,但不如 CentOS 8 常用 推荐使用 journalctl -u <服务名> 查看服务日志
时间同步 chronydntpd 推荐使用 chronydtimedatectl 命令更强大
主机名设置 hostnamectl set-hostname name 同上

✅ 总结对比表

项目 CentOS 7 CentOS 8
init 系统 SysVinit + systemd 完全 systemd
包管理器 yum dnf(兼容 yum)
网络管理 ifcfg 文件 + network 服务 NetworkManager + nmcli
防火墙 firewalld (iptables) firewalld (nftables)
Python Python 2.x 默认 Python 3.x 默认
模块化支持 不支持 支持 AppStream 模块化
默认内核 3.10.x 4.18.x 或更高
SELinux 支持 支持
安全模块 SELinux SELinux + 多种安全增强
容器支持 有限支持 Docker 原生支持 Podman、Buildah、Skopeo 等容器工具

📚 推荐阅读

  • Red Hat Enterprise Linux 8 Documentation
  • CentOS 8 Release Notes
  • YUM vs DNF Cheat Sheet

如果你正在从 CentOS 7 迁移到 CentOS 8,建议重点关注以下几点:

  • 替换 yumdnf
  • systemctl 替代旧的 servicechkconfig
  • 使用 nmcli 或图形界面配置网络
  • 注意 Python 版本变化
  • 了解 AppStream 模块机制

如需具体某个命令的用法对比,欢迎继续提问!