1. Start with host identity and uptime

Collect a baseline before troubleshooting. These commands are read-only and safe to run on a production host.

hostnamectl
uname -a
uptime
who
中文说明:先确认主机名、内核版本、运行时间和当前登录用户。排障时记录时间点,便于与日志对应。

2. Inspect CPU and memory

lscpu
free -h
top

free -h reports memory in human-readable units. On Linux, the available column is generally more useful than treating all cached memory as unavailable. In top, check load average, CPU states and processes sorted by resource use.

ps aux --sort=-%cpu | head -n 10
ps aux --sort=-%mem | head -n 10

3. Inspect disks and inodes

lsblk -f
df -hT
df -ih
du -xhd1 /var 2>/dev/null | sort -h

df -hT shows filesystem capacity and type. df -ih checks inode exhaustion; a filesystem can fail to create files even when byte capacity remains.

Do not delete large files blindly. Identify the owning service and retention policy first. Removing an open log file may not release disk space until the process closes it.

4. Inspect processes and listening sockets

ps -eo pid,ppid,comm,%cpu,%mem --sort=-%cpu | head
sudo ss -tulpn
sudo lsof +L1 2>/dev/null | head

ss -tulpn lists listening TCP/UDP sockets and, with suitable privileges, owning processes. Treat exposed listeners as an inventory to review, not as proof that a service is vulnerable.

5. Build a concise diagnostic snapshot

{
  echo "=== $(date -Is) ==="
  hostnamectl
  uptime
  free -h
  df -hT
  sudo ss -tulpn
} 2>&1 | tee "$HOME/host-snapshot.txt"

Keep snapshots in a controlled location. They can contain hostnames, usernames, IP addresses and service details; redact them before sharing publicly.

6. Troubleshooting sequence

  1. Check whether the symptom is CPU, memory, disk, network or application-specific.
  2. Compare current values with a known-good baseline.
  3. Identify the responsible process or service.
  4. Read relevant logs before restarting anything.
  5. Change one variable at a time and verify the result.

Key takeaways

  • Prefer read-only inspection before remediation.
  • Check both disk blocks and inodes.
  • Correlate resource metrics with service logs.
  • Protect diagnostic output because it may reveal infrastructure details.

References & further reading

Commands are examples for a representative Ubuntu/Linux environment. Review paths, versions, access requirements and maintenance impact before applying them to production systems.