

uname -a # 查看系统内核版本
hostnamectl # 查看系统版本
arch # 查看系统架构
uptime # 查看运行时间和负载
who # 当前登录用户
w # 登录用户及其行为
top
重点关注:
htop
优点:更直观,可按 CPU 排序
lscpu
cat /proc/cpuinfo
free -h
vmstat 1 5
cat /proc/meminfo
现象 | 可能原因 |
|---|---|
内存高 | 程序内存泄漏 |
swap 高 | 内存不足 |
cache 高 | 正常现象 |
df -h
排错重点:
du -sh *
du -sh /* | sort -hr
df -i
磁盘没满但写不了文件 → inode 用完
iostat -x 1
重点看:
ip a
ifconfig
ping 8.8.8.8
netstat -tunlp
ss -tunlp
排错场景:
tcpdump -i eth0 port 80
ip route
route -n
nslookup www.baidu.com
dig www.baidu.com
ps -ef
ps aux
ps -ef | grep nginx
kill -9 PID
lsof -i:80
lsof -p PID
Linux 排错核心就是看日志。
/var/log/messages
/var/log/syslog
查看:
tail -f /var/log/messages
/var/log/nginx//var/log/mysqld.logsystemctl status nginx
journalctl -xe
journalctl -u nginx
lsof -i:8080
ss -lntp | grep 8080
ls -l
chmod
chown
id 用户名
① 查看服务状态
systemctl status 服务名
② 查看端口
ss -lntp
③ 查看日志
journalctl -u 服务名
④ 查看磁盘
df -h
⑤ 查看权限
ls -l
ipconfig
netstat -ano
tasklist
taskkill /PID
ping
tracert