当前位置:首页>Linux>Linux 运维必备:100 个常见故障与原因速查手册

Linux 运维必备:100 个常见故障与原因速查手册

  • 2026-10-11 06:14:19
Linux 运维必备:100 个常见故障与原因速查手册
整理自一线运维实战笔记,覆盖文件目录、网络、用户、软件包、磁盘、服务等 8 大类共 100 个高频报错。

目录

  • 一、文件和目录类(25 个)

  • 二、网络连接类(15 个)

  • 三、系统基础配置类(10 个)

  • 四、用户与权限类(15 个)

  • 五、脚本与定时任务类(10 个)

  • 六、软件包管理类(10 个)

  • 七、磁盘与文件系统类(10 个)

  • 八、服务与进程类(5 个)


一、文件和目录类

1. File exists — 文件/目录已存在

[root@hostname ~]# mkdir /datamkdir: cannot create directory '/data': File exists

原因:目标目录已存在。解决:先 ls 检查,或用 mkdir -p 忽略存在错误。

2. No such file or directory — 文件或目录不存在

[root@hostname ~]# cd whqzn-bash: cd: whqzn: No such file or directory

常见诱因:

  • 路径书写错误

  • mkdir 未加 -p 创建多层目录

  • touch 时上层目录不存在

3. command not found — 命令找不到

[root@hostname ~]# mkdiy-bash: mkdiy: command not found

原因:命令拼写错误 或 未安装对应软件包。可用 yum provides <cmd> 反查。

4. invalid option — 无效参数

[root@hostname ~]# touch -p /tmp/a.txttouch: invalid option --'p'

原因:命令不支持该参数。查 --help 或 man。

5. cp: overwrite? — 是否覆盖

cp: overwrite '/tmp/a.txt'?

解决:y 覆盖 / n 取消;批量场景用 \cp 或 cp -f。

6. rm: remove regular empty file? — 是否删除

默认 root 会有 rm 别名为 rm -i 的交互确认,可用 \rm 或 -f 跳过。

7. Is a directory — 不能对目录直接操作

rm: cannot remove '/data/': Is a directoryE502: "/oldboy" is a directory

解决:rm -rf 删除目录;vi 请指向具体文件。

8. descend into directory — 是否进入目录

rm -r 递归删除时的交互提示,加 -f 可静默。

9. Invalid level, must be greater than 0

tree -L-F2 /

原因:tree -L 后面必须紧跟数字,参数顺序写错。

10. E212: Can't open file for writing

vi 保存时上级目录不存在或无写权限。

11. E37: No write since last change

vi 中修改了内容却用 :q 退出。解决::q! 强退,或 :wq 保存。

12. w: NN column window is too narrow

窗口太窄导致 w 无法显示,放大终端或用 who 替代。

13. Not a directory

touch /whqzn /whqzn.txt   # 多打了一个空格ls: cannot access /whqzn/: Not a directory

教训:路径中意外空格是新手高频翻车点。

14. tar: Cannot open — 特殊字符污染

从网页/微信复制命令时经常带全角空格或不可见字符,导致 tar 报 \200\202 类错误。解决:手敲命令。

15. You have mail in /var/spool/mail/root

系统告警邮件堆积。处理:cat /var/spool/mail/root 查看,或清空 > /var/spool/mail/root。

16. Permission denied — 权限拒绝

最常见错误。排查顺序:

  1. ls -l 看文件权限位

  2. id 看当前用户与所属组

  3. 检查 SELinux(getenforce)和 ACL(getfacl)

17. W10: Warning: Changing a readonly file

vim 编辑只读文件。root 可 :wq! 强制保存。

18. no properly formatted MD5 checksum lines found

md5sum -c 时 MD5 文件格式错误。正确格式:<md5>  <filename>(两个空格)。

19. E45: 'readonly' option is set

文件被标记只读。:wq! 强写,或 chmod +w 修改权限。

20. cp: omitting directory

cp /whqzn/ /tmp/cp: omitting directory '/whqzn/'

解决:加 -r 递归。

21. Unexpected EOF in archive

tar 包损坏或下载不完整。解决:重新下载并校验 MD5/SHA。

22. gzip: stdin: not in gzip format

压缩包不是 gzip 或已损坏。用 file xxx.tar.gz 确认真实类型。

23. tar: Removing leading '/' from member names

tar 打包绝对路径时的正常警告,可忽略。

24. ln: failed to create hard link — Invalid cross-device link

硬链接不能跨文件系统。解决:改用软链接 ln -s。

25. Argument list too long

rm *、cp * 遇到海量文件时报错。解决:find . -type f -delete 或 ls | xargs -n 100 rm。


二、网络连接类

26. Connection Failed — 远程连接失败

Could not connect to 'x.x.x.x' (port 233): Connection failed.

排查:

  1. 目标端口是否监听:ss -lntp | grep 22

  2. 防火墙:firewall-cmd --list-all / iptables -L

  3. 网络可达性:ping + telnet x.x.x.x 22

27. Could not resolve host — 无法解析主机

DNS 问题。检查 /etc/resolv.conf 与网卡 DNS 配置。

28. Nothing to do — 无需操作

  • 软件已是最新

  • 包名写错(如 treea)

  • 需要装的是命令所属包(用 yum provides 查)

29. No package xxx available — 找不到软件包

yum 源未配置或包名错误。yum repolist 检查源。

30. Name or service not known

ping baidu.com 报此错,通常是 DNS 未生效或未联网。

31. No route to host — 此路不通

防火墙 / SELinux / 路由表问题。快速验证:

systemctl stop firewalldsetenforce 0

32. Connection Refused — 连接被拒

目标端口未监听,或防火墙 REJECT。

33. Connection timed out — 连接超时

网络不通、防火墙 DROP、路由黑洞。

34. Protocol mismatch — 协议不匹配

telnet 探测到 SSH 端口后立即断开是正常现象;若真业务报此错,检查协议版本。

35. Network is unreachable

路由表缺省网关缺失。route -n 或 ip r 检查。

36. Host key verification failed

SSH 目标主机 key 变化。解决:ssh-keygen -R x.x.x.x 清除旧 key。

37. Permission denied (publickey,password)

SSH 认证失败。检查 /etc/ssh/sshd_config 的 PasswordAuthentication、AllowUsers、~/.ssh/authorized_keys 权限(应 600)。

38. Too many authentication failures

密钥太多被强制断开。解决:ssh -o IdentitiesOnly=yes -i <key> user@host。

39. Address already in use — 端口被占用

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

解决:ss -lntp | grep :80 找出占用进程。

40. Temporary failure in name resolution

DNS 临时故障。检查 /etc/resolv.conf 或本地 DNS 缓存服务。


三、系统基础配置类

41. Device does not seem to be present — 网卡不存在

systemctl restart network# Job for network.service failed

排查:journalctl -xe 看具体网卡名,注意 eth0 vs ens33 命名差异。

42. 修改主机名后命令行未生效

hostname 是临时修改;永久修改需 hostnamectl set-hostname xxx 或改 /etc/hostname,然后重连终端。

43. unexpected EOF while looking for matching "

/etc/profile 或 shell 脚本中引号未闭合。定位到具体行修复即可。

44. syntax error: unexpected end of file

脚本中 if/for/while/case 未闭合。用 bash -n script.sh 静态检查。

45. bad interpreter: No such file or directory

脚本 shebang 错误,或从 Windows 拷贝导致 CRLF。解决:dos2unix script.sh。

46. locale: Cannot set LC_ALL to default locale

系统语言包未装。解决:localedef -i en_US -f UTF-8 en_US.UTF-8。

47. Read-only file system — 只读文件系统

磁盘/inode 出问题后系统自动置为只读。dmesg | tail 查 IO 错误,必要时 fsck 修复。

48. clock skew detected — 时钟偏移

NTP 未同步。解决:chronyc sources / ntpdate ntp.aliyun.com。

49. Failed to start Network Manager

NetworkManager 与传统 network 冲突。选一个用即可。

50. sudo: unable to resolve host

/etc/hosts 中缺主机名记录。解决:加一行 127.0.0.1 <hostname>。


四、用户与权限类

51. user 'xxx' already exists

用户已存在,useradd 前先 id user 判断。

52. no such user

用户不存在,useradd 或核实拼写。

53. Only root can do that.

[user@hostname]$ echo 123456 | passwd --stdin userOnly root can do that.

非交互式改密仅 root 可用。

54. Only root can specify a user name.

普通用户执行 passwd <username> 会被拒。普通用户只能 passwd 改自己。

55. Creating mailbox file: File exists / home directory already exists

删除用户时未加 -r,家目录/邮箱残留。解决:userdel -r user 或手动清理。

56. user xxx is currently used by process NNNN

usermod -u 2222 nginxusermod: user nginx is currently used by process 7540

解决:先停服务再改 UID。

57. /etc/sudoers: syntax error near line NNN

sudoers 语法错误。必须用 visudo 编辑,否则可能失去 sudo 权限。

58. sudo: no tty present and no askpass program specified

crontab 或脚本中 sudo 需要密码。解决:sudoers 里给该用户加 NOPASSWD:。

59. su: Authentication failure

密码错误、或该用户被 passwd -l 锁定。passwd -u user 解锁。

60. chown: invalid user

目标用户不存在,或写错了用户名。

61. Operation not permitted

即使 root,也可能因 chattr +i(immutable)而无法操作。解决:chattr -i file。

62. groupadd: group 'xxx' already exists

组已存在,getent group xxx 校验。

63. Login incorrect

tty/ssh 登录密码错,或 PAM 限制(如 pam_tally2 锁定)。

64. Maximum number of tries exceeded

连续输错密码触发锁定。pam_tally2 --user=xxx --reset。

65. useradd: cannot open /etc/passwd

/etc/passwd 被 chattr +i 锁定,或磁盘满。


五、脚本与定时任务类

66. no crontab for root

root 无定时任务,正常提示,不是错误。

67. no crontab for root - using an empty one

首次编辑,系统创建空白 crontab。

68. crontab: installing new crontab

定时任务更新成功。

69. bad hour / bad minute / errors in crontab file, can't install

"/tmp/crontab.xxx":3: bad hour

时间字段范围错误。分 0-59,时 0-23,日 1-31,月 1-12,周 0-7。

常见坑:21-00 应写成 21-23,0。

70. /bin/sh^M: bad interpreter

Windows 换行符污染。解决:sed -i 's/\r$//' script.sh 或 dos2unix。

71. command not found(脚本中)

crontab 环境变量极简,$PATH 不含常用路径。解决:脚本内绝对路径调用,或开头 source /etc/profile。

72. Syntax error: "(" unexpected

用 sh 执行了 bash 特有语法(数组、[[ ]])。解决:bash script.sh 或 shebang 写 #!/bin/bash。

73. integer expression expected

if [ $a -eq $b ] 时变量为空或非数字。用 ${a:-0} 兜底。

74. line xx: unexpected token `fi'

if 缺少 then,或分支未闭合。

75. You have new mail in /var/spool/mail/root

定时任务有输出未重定向。解决:脚本末尾 >/dev/null 2>&1。


六、软件包管理类

76. Another app is currently holding the yum lock

Existing lock /var/run/yum.pid: another copy is running as pid NNNN

解决:等它跑完,或 kill 并删除 lock 文件(谨慎)。

77. Cannot find a valid baseurl for repo

yum 源 URL 失效。切换阿里/清华镜像。

78. GPG check FAILED

签名不匹配。临时用 --nogpgcheck,长期建议导入正确 GPG key。

79. Requires: xxx — 依赖冲突

包依赖缺失或版本冲突。yum deplist 排查,或用 --skip-broken。

80. Transaction check error: file conflicts

两个包提供同一文件。选择性卸载冲突包,或加 --replacefiles。

81. rpmdb: Thread died in Berkeley DB library

RPM 数据库损坏。解决:

rm -f /var/lib/rpm/__db*rpm --rebuilddb

82. is needed by (installed) xxx

卸载时被依赖阻挡。评估影响后 rpm -e --nodeps(不推荐日常使用)。

83. Package does not match intended download

下载 RPM 损坏。清缓存 yum clean all。

84. Errno 256 No more mirrors to try

所有源均不可用。检查网络、DNS、源配置。

85. Loaded plugins: fastestmirror ... but no mirrors work

禁用 fastestmirror 插件或换源。


七、磁盘与文件系统类

86. No space left on device — 磁盘空间不足

df -h# 看空间du -sh /* 2>/dev/null | sort -h# 找大目录

注意:文件被进程持有时删除后空间不释放,需 lsof | grep deleted 找到进程重启。

87. No space left on device(其实 inode 满)

df -i 检查 inode。海量小文件场景常见。

88. Input/output error — 磁盘 IO 错误

硬盘/SSD 硬件故障前兆。dmesg、smartctl -a /dev/sda 排查。

89. mount: wrong fs type, bad option, bad superblock

文件系统类型不对或损坏。blkid 看类型,fsck 修复。

90. Device or resource busy — 设备忙

umount 时被占用。解决:lsof +D /mnt 或 fuser -km /mnt。

91. mount point does not exist

挂载点目录不存在,mkdir -p 创建。

92. Cannot allocate memory / OOM killed

内存耗尽,OOM Killer 干掉进程。dmesg | grep -i oom 查证。

93. Stale file handle — NFS 陈旧句柄

NFS 服务端文件已被删或重挂。解决:客户端重挂载。

94. Filesystem xxx has errors, check forced

开机自检发现文件系统错误,进入 emergency mode。fsck -y /dev/xxx 修复。

95. Cannot write: Disk quota exceeded

磁盘配额超限。quota -u user 查配额,edquota 调整。


八、服务与进程类

96. Failed to start xxx.service: Unit not found

服务未安装或名字错。systemctl list-unit-files | grep xxx 确认。

97. Job for xxx.service failed

标准排错三板斧:

systemctl status xxx -l
 journalctl -xeu xxx
 tail -f /var/log/messages

98. bind: Address already in use(服务启动)

端口冲突。ss -lntp | grep :<port> 定位占用者。

99. Too many open files

文件句柄超限。ulimit -n 查;改 /etc/security/limits.conf 与 systemd 服务的 LimitNOFILE。

100. fork: retry: Resource temporarily unavailable

用户进程数超限(nproc)。改 /etc/security/limits.d/*.conf,检查是否有进程泄漏。


写在最后

以上 100 条覆盖了 Linux 日常运维 80% 的报错场景。建议收藏 + 转发给团队新同学,遇到问题直接 Ctrl+F 搜关键字,效率翻倍。

排错通用心法(八字诀):

看日志、查权限、验网络、比配置。

篇幅有限,仍有大量"疑难杂症"未列出——比如内核 panic、containerd 相关报错、LVM 快照失败等。评论区欢迎补充你踩过的坑,我们一起把清单做到 200 条!

最新文章

随机文章