Skip to content
VDS · 操作系统

AlmaLinux 和 CentOS Stream:用 dnf 代替 apt

如何将 Debian 的说明适配到 RHEL 系列:命令和软件包对应关系、用 firewalld 代替 ufw、SELinux 以及 EPEL 仓库。

更新于 2026年8月23日

AlmaLinux 9 和 10 以及 CentOS Stream 9 的用法与 Debian 和 Ubuntu 不同。下面我们来梳理一下最容易让人踩坑的地方。

命令对照

Debian / UbuntuAlmaLinux / CentOS Stream
apt update && apt upgradednf upgrade
apt install packagednf install package
apt remove packagednf remove package
apt search stringdnf search string
apt list --installeddnf list installed
ufwfirewall-cmd
sudo 组wheel 组
/etc/apt/sources.list/etc/yum.repos.d/

软件包名称也不一样:apache2 在这里叫 httpd,nginx 名称相同,mysql-server 叫 mariadb-server,python3-pip 还是 python3-pip,但 dnsutils 叫 bind-utils。

初始步骤

dnf upgrade -y
dnf install -y curl nano git htop tar policycoreutils-python-utils
timedatectl set-timezone Europe/Moscow
hostnamectl set-hostname my-vds

创建一个拥有管理员权限的用户:

adduser artem
passwd artem
usermod -aG wheel artem

EPEL 仓库

许多常见的软件包并不在基础仓库中,而是在 EPEL 里:

dnf install -y epel-release
dnf upgrade -y
dnf install -y btop fail2ban

防火墙

这里不用 ufw,而是用 firewalld:

systemctl enable --now firewalld
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
firewall-cmd --list-all

不加 --permanent,规则会在重启后消失;不加 --reload,规则不会立即生效。这两部分都需要。

SELinux

这是各种莫名其妙故障的主要来源:文件权限没问题,服务也在运行,但就是无法访问。查看模式:

getenforce

常见情况及解决办法:

setsebool -P httpd_can_network_connect 1
semanage port -a -t http_port_t -p tcp 8080
restorecon -Rv /var/www

第一条允许 Web 服务器发起出站连接(在反向代理到应用程序时需要),第二条允许监听非标准端口,第三条用于在从他人目录复制文件后修复文件标签。

您可以查看实际发生了什么:

ausearch -m avc -ts recent

您不必完全禁用 SELinux:几乎在所有情况下,上面三种方法中的一种就足够了。

其他不同之处

  • Apache Web 服务器叫 httpd,其配置文件位于 /etc/httpd/,而不是 /etc/apache2/。
  • nginx 没有 sites-available 和 sites-enabled 目录——配置文件放在 /etc/nginx/conf.d/*.conf。
  • Web 服务器用户是 nginx 或 apache,而不是 www-data。在使用 chown 时这一点很重要。

客户机代理

dnf install -y qemu-guest-agent
systemctl enable --now qemu-guest-agent

如果您还不确定是否要选择这个系统家族,请参阅如何选择操作系统。您可以通过重装更换操作系统,但这会完全丢失数据。