

用于查看 服务器运行状态、CPU、内存、负载等信息。
命令 | 作用 | 示例 |
|---|---|---|
uptime | 查看系统运行时间和负载 | uptime |
top | 实时查看CPU、内存使用 | top |
htop | 增强版top | htop |
vmstat | 查看系统性能 | vmstat 1 |
mpstat | 查看CPU使用率 | mpstat -P ALL |
free | 查看内存 | free -h |
uname | 查看系统信息 | uname -a |
示例:
uptime
输出:
10:20:01 up 15 days, 2 users, load average: 0.20, 0.18, 0.15
说明:
当服务器 CPU占用高或系统卡顿时使用。
查看CPU占用:
top
查看占用CPU最高进程:
top -o %CPU
查看进程:
ps -ef
查看CPU排序:
ps aux --sort=-%cpu | head
结束进程:
kill -9 PID
查看内存使用:
free -h
输出:
total used free buff/cache
查看内存占用高进程:
ps aux --sort=-%mem | head
查看详细内存:
cat /proc/meminfo
查看磁盘空间:
df -h
示例:
Filesystem Size Used Avail Use%
/dev/sda1 100G 95G 5G 95%
查看目录大小:
du -sh *
查看最大文件:
du -sh * | sort -rh | head
查找大文件:
find / -size +500M
查看磁盘IO:
iostat -x 1
网络故障是 运维最常见问题之一。
ping
示例:
ping 192.168.1.1
作用:
ip addr
或
ifconfig
ip route
或
route -n
示例:
default via 192.168.1.1
查看端口监听:
netstat -tulnp
或
ss -lntp
示例:
ss -lntp | grep 80
traceroute
示例:
traceroute www.baidu.com
作用:
nslookup
示例:
nslookup www.baidu.com
或
dig www.baidu.com
查看端口占用:
lsof -i:80
查看连接数:
netstat -an | grep ESTABLISHED
统计连接数:
netstat -nat | wc -l
网络问题最强工具之一。
抓包:
tcpdump
示例:
抓80端口
tcpdump -i eth0 port 80
抓指定IP
tcpdump host 192.168.1.10
保存抓包文件
tcpdump -w test.pcap
查看服务状态:
systemctl status nginx
启动服务:
systemctl start nginx
重启服务:
systemctl restart nginx
开机启动:
systemctl enable nginx
查看所有服务:
systemctl list-units --type=service
日志是排障最重要依据。
实时查看日志:
tail -f /var/log/messages
查看最后100行:
tail -100 log.log
查看系统日志:
journalctl -xe
按服务查看:
journalctl -u nginx
查看当前用户:
whoami
查看登录用户:
who
查看用户历史命令:
history
查看权限:
ls -l
修改权限:
chmod 755 file
修改用户:
chown user:user file
查看进程:
ps -ef
查找进程:
ps -ef | grep nginx
杀掉进程:
kill -9 PID
运维工程师最常用组合:
查看服务器状态:
top
free -h
df -h
uptime
网络检查:
ip addr
ping
traceroute
服务检查:
systemctl status 服务
netstat -tulnp
日志检查:
tail -f /var/log/messages
运维圈经典口诀:
服务器排障四步
看负载
查进程
看磁盘
查日志
网络排障四步
看IP
Ping网关
查路由
抓包
服务排障三步
端口
进程
日志