作为IT工程师,快速定位Linux系统故障需要系统化的方法和丰富的经验。以下是我总结的故障定位流程和常用工具:
# 查看系统负载
uptime
# 查看内存使用情况
free -h
# 查看磁盘空间
df -h
# 查看CPU使用率
top -n 1
# 查看占用CPU高的进程
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head
# 查看占用内存高的进程
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
/var/log/messages
- 通用系统消息/var/log/syslog
- 系统日志/var/log/kern.log
- 内核日志/var/log/dmesg
- 启动和硬件相关消息/var/log/auth.log
- 认证相关日志# 实时查看最新日志
tail -f /var/log/syslog
# 查看特定时间段的日志
journalctl --since "2023-01-01 00:00:00" --until "2023-01-02 12:00:00"
# 过滤错误消息
grep -i error /var/log/syslog
# 检查网络连接状态
netstat -tulnp
ss -tulnp
# 检查路由表
ip route
# 测试网络连通性
ping -c 4 example.com
traceroute example.com
# 检查DNS解析
dig example.com
nslookup example.com
# 查看CPU使用率
mpstat -P ALL 1 5
# 查看CPU运行队列
vmstat 1 5
# 详细内存统计
vmstat -s
# 查看内存泄漏
valgrind --leak-check=full your_application
# 查看磁盘I/O
iostat -x 1 5
# 查看磁盘等待
iotop
top
查看CPU、内存使用情况iostat
检查磁盘I/Odmesg
检查是否有硬件错误journalctl -u service_name
netstat -tulnp | grep port_number
ldd /path/to/binary
df -h
确认问题分区du -sh *
定位大文件journalctl --vacuum-size=100M
strace:跟踪系统调用
strace -p PID
strace -f command
perf:性能分析
perf top
perf stat -e cycles,instructions,cache-references,cache-misses,branch-instructions,branch-misses command
tcpdump:网络抓包
tcpdump -i eth0 -w capture.pcap
通过以上系统化的方法,可以快速定位大多数Linux系统故障。记住,良好的日志记录和监控是预防和快速解决问题的关键。