跳转到内容
搜索 RunEntLinux 文档

仅搜索 RunEntLinux 通用文档,各发行版文档使用各自的搜索入口。

    浏览当前文档目录

    常见错误速查

    本页收录了 EL 系统(AlmaLinux、Rocky Linux、CentOS 等)日常管理中最常见的错误信息及其解决方案,按类别组织,方便快速查找。

    软件包不在已启用的仓库中。

    确认包名拼写并搜索
    $ dnf search <关键词>
    检查是否需要启用 EPEL 仓库
    $ sudo dnf install -y epel-release
    $ dnf search <包名>

    “This command has to be run with superuser privileges”

    Section titled ““This command has to be run with superuser privileges””

    需要 root 权限。在命令前加 sudo。

    使用 sudo 运行
    $ sudo dnf install <包名>

    如果用户不在 sudoers 列表中:

    将用户加入 wheel 组(需要 root 操作)
    $ su -
    # usermod -aG wheel <用户名>

    “Error: Failed to download metadata for repo ‘xxx’”

    Section titled ““Error: Failed to download metadata for repo ‘xxx’””

    仓库元数据下载失败。可能是网络问题或仓库 URL 过期。

    清除缓存后重试
    $ sudo dnf clean all
    $ sudo dnf makecache
    检查仓库配置文件
    $ cat /etc/yum.repos.d/<仓库名>.repo
    如果仓库不再需要,禁用它
    $ sudo dnf config-manager --set-disabled <仓库ID>
    # EL10 的包管理器仍是 DNF 4(4.20),这条写法可用;只有将来切到 DNF 5 才需要改成 disable <repo> 子命令

    对于已 EOL 的 CentOS 8,官方仓库已下线。需要迁移到 AlmaLinux 或 Rocky Linux。

    “Error: Transaction check error: file xxx from install of yyy conflicts with file from package zzz”

    Section titled ““Error: Transaction check error: file xxx from install of yyy conflicts with file from package zzz””

    软件包文件冲突。

    允许替换冲突包
    $ sudo dnf install <包名> --allowerasing
    查看两个包的冲突文件
    $ rpm -ql <包1> | sort > /tmp/pkg1.txt
    $ rpm -ql <包2> | sort > /tmp/pkg2.txt
    $ comm -12 /tmp/pkg1.txt /tmp/pkg2.txt

    “Curl error (28): Timeout was reached”

    Section titled ““Curl error (28): Timeout was reached””

    下载超时。网络问题或镜像站不可达。

    测试到镜像站的连通性
    $ curl -I https://mirror.example.com/
    切换到速度更快的镜像(以 AlmaLinux 为例)
    $ sudo sed -i 's|^mirrorlist=|#mirrorlist=|g' /etc/yum.repos.d/almalinux*.repo
    $ sudo sed -i 's|^# baseurl=https://repo.almalinux.org|baseurl=https://mirrors.aliyun.com|g' /etc/yum.repos.d/almalinux*.repo
    $ sudo dnf makecache

    32 位和 64 位版本的同一软件包版本不一致。

    同步修复
    $ sudo dnf distro-sync <包名>
    如果不需要 32 位版本
    $ sudo dnf remove <包名>.i686

    ”Job for xxx.service failed because the control process exited with error code”

    Section titled “”Job for xxx.service failed because the control process exited with error code””

    服务启动失败。

    查看服务状态和错误详情
    $ systemctl status <服务名>
    查看完整的服务日志
    $ journalctl -u <服务名> -n 50 --no-pager
    检查配置文件语法(以 nginx 为例)
    $ nginx -t
    检查配置文件语法(以 httpd 为例)
    $ httpd -t

    服务被屏蔽,无法启动。

    取消服务屏蔽
    $ sudo systemctl unmask <服务名>
    $ sudo systemctl start <服务名>

    “xxx.service: Failed with result ‘exit-code’”

    Section titled ““xxx.service: Failed with result ‘exit-code’””

    服务启动后异常退出。

    查看退出状态码
    $ systemctl show <服务名> -p ExecMainStatus
    查看最后几条日志
    $ journalctl -u <服务名> -e --no-pager

    常见原因:配置文件语法错误、端口被占用、权限不足、依赖服务未启动。

    检查端口是否被其他进程占用
    $ sudo ss -tlnp | grep :<端口号>

    “Failed to start xxx.service: Unit not found”

    Section titled ““Failed to start xxx.service: Unit not found””

    服务单元文件不存在。

    确认软件包已安装
    $ rpm -qa | grep <包名>
    查找正确的服务名
    $ systemctl list-unit-files | grep <关键词>

    ”Permission denied” 但文件权限正确

    Section titled “”Permission denied” 但文件权限正确”

    最常见的 SELinux 问题。文件的 Unix 权限正确,但 SELinux 安全上下文不匹配。

    检查是否有 AVC 拒绝记录
    $ sudo ausearch -m avc -ts recent
    安装并使用 sealert 获取建议
    $ sudo dnf install -y setroubleshoot-server
    $ sudo sealert -a /var/log/audit/audit.log | head -60
    恢复文件的默认 SELinux 上下文
    $ sudo restorecon -Rv /path/to/files

    “SELinux is preventing xxx from yyy access on zzz”

    Section titled ““SELinux is preventing xxx from yyy access on zzz””

    SELinux 策略阻止了某个操作。

    查看详细信息和修复建议
    $ sudo ausearch -m avc -ts recent | audit2why
    如果是已知的合法操作,生成并安装策略模块
    $ sudo ausearch -m avc -ts recent | audit2allow -M my_policy
    $ sudo semodule -i my_policy.pp

    例如将 Apache 配置为监听 8888 端口:

    查看 SELinux 允许的 HTTP 端口
    $ sudo semanage port -l | grep http_port_t
    添加自定义端口
    $ sudo semanage port -a -t http_port_t -p tcp 8888

    Web 服务无法访问用户主目录内容

    Section titled “Web 服务无法访问用户主目录内容”
    启用 httpd 访问用户目录的布尔值
    $ sudo setsebool -P httpd_enable_homedirs on
    允许 httpd 连接网络(如反向代理)
    $ sudo setsebool -P httpd_can_network_connect on

    没有到达目标的路由。

    检查路由表
    $ ip route show
    检查是否有默认路由
    $ ip route show default

    如果没有默认路由:

    临时添加默认路由
    $ sudo ip route add default via <网关IP>
    通过 nmcli 永久配置网关
    $ sudo nmcli connection modify "连接名" ipv4.gateway <网关IP>
    $ sudo nmcli connection up "连接名"

    目标端口没有服务在监听。

    确认目标端口是否在监听
    $ sudo ss -tlnp | grep :<端口>
    确认服务是否在运行
    $ systemctl status <服务名>

    DNS 解析失败。

    检查 DNS 配置
    $ cat /etc/resolv.conf
    测试 DNS 服务器是否可达
    $ ping -c 2 $(grep nameserver /etc/resolv.conf | head -1 | awk '{print $2}')
    手动指定 DNS 测试
    $ dig @8.8.8.8 <域名>

    端口已被其他进程占用。

    查找占用端口的进程
    $ sudo ss -tlnp | grep :<端口>
    $ sudo lsof -i :<端口>
    终止占用进程(确认安全后)
    $ sudo kill <PID>

    磁盘空间不足。

    查看磁盘使用情况
    $ df -h
    找出最大的目录
    $ sudo du -sh /* 2>/dev/null | sort -rh | head -10
    快速释放空间
    $ sudo dnf clean all
    $ sudo journalctl --vacuum-size=100M
    $ sudo find /tmp -type f -atime +7 -delete

    如果 df -h 显示还有空间但仍报错:

    检查 inode 使用率
    $ df -i

    inode 耗尽通常是某个目录下有大量小文件:

    找出 inode 使用最多的目录
    $ sudo find / -xdev -printf '%h\n' | sort | uniq -c | sort -rn | head -10

    “Structure needs cleaning” / 文件系统错误

    Section titled ““Structure needs cleaning” / 文件系统错误”

    文件系统损坏。

    卸载分区后执行文件系统检查
    $ sudo umount /dev/sda2
    $ sudo fsck -y /dev/sda2

    警告: 绝对不要在已挂载的文件系统上运行 fsck。如果是根分区,需要从救援模式操作。

    文件系统被强制切换为只读模式,通常是检测到磁盘错误。

    检查系统日志中的磁盘错误
    $ dmesg | grep -i -E '(error|fail|read.only|EXT4-fs)'
    尝试重新挂载为读写
    $ sudo mount -o remount,rw /

    如果无法重新挂载,说明磁盘有硬件问题,需要从救援模式修复。

    “/boot 空间不足导致内核安装失败”

    Section titled ““/boot 空间不足导致内核安装失败””
    查看 /boot 分区使用情况
    $ df -h /boot
    列出已安装的内核
    $ rpm -qa kernel-core | sort -V
    删除旧内核,只保留最新的两个
    $ sudo dnf remove --oldinstallonly --setopt installonly_limit=2 kernel

    ”Operation not permitted”(即使是 root)

    Section titled “”Operation not permitted”(即使是 root)”

    可能是文件设置了不可变属性。

    查看文件的扩展属性
    $ lsattr <文件路径>

    如果看到 i 标志(immutable):

    移除不可变属性
    $ sudo chattr -i <文件路径>

    命令不在 PATH 中,或者对应的软件包未安装。

    查找命令属于哪个包
    $ dnf provides <命令名>
    如果是 sbin 下的命令,root 用户使用完整路径
    $ /usr/sbin/<命令名>
    确认 PATH 环境变量
    $ echo $PATH

    “cannot create regular file: Permission denied”

    Section titled ““cannot create regular file: Permission denied””
    检查目标目录的权限
    $ ls -la <目标目录>
    检查目录的 SELinux 上下文
    $ ls -laZ <目标目录>
    确认目录的 ACL 规则
    $ getfacl <目标目录>

    ”WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!”

    Section titled “”WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!””

    服务器密钥发生变化(常见于重装系统或迁移后)。

    确认安全后移除旧的主机密钥
    $ ssh-keygen -R <主机名或IP>

    “Permission denied (publickey,gssapi-keyex,gssapi-with-mic)”

    Section titled ““Permission denied (publickey,gssapi-keyex,gssapi-with-mic)””

    密钥认证失败,且服务端禁用了密码认证。

    检查 SSH 服务端配置
    $ sudo grep -E '(PasswordAuthentication|PubkeyAuthentication|PermitRootLogin)' /etc/ssh/sshd_config
    检查密钥文件权限(客户端)
    $ ls -la ~/.ssh/
    $ chmod 700 ~/.ssh
    $ chmod 600 ~/.ssh/id_rsa
    $ chmod 644 ~/.ssh/id_rsa.pub
    检查 authorized_keys 权限(服务端)
    $ chmod 700 ~/.ssh
    $ chmod 600 ~/.ssh/authorized_keys