# 实时监控CPU使用率
top
htop
# 查看CPU负载
uptime
cat /proc/loadavg
# 查看CPU核心温度(需要lm-sensors)
sensors
# 查看内存使用情况
free -h
vmstat 1 5
# 检测内存泄漏
valgrind --leak-check=full your_application
# 查看磁盘使用情况
df -h
du -sh /path/to/directory
# 监控磁盘I/O
iostat -x 1
iotop
# 系统日志
/var/log/syslog
/var/log/messages
# 内核日志
dmesg
journalctl -k
# 认证日志
/var/log/auth.log
# 查找错误信息
grep -i error /var/log/syslog
grep -i fail /var/log/syslog
# 使用logwatch分析日志
logwatch --detail high
# 检查内核oops消息
dmesg | grep -i "Oops"
dmesg | grep -i "segfault"
# 检查内核panic
journalctl -k | grep -i "kernel panic"
# 查看当前内核参数
sysctl -a
# 检查关键参数
sysctl vm.swappiness
sysctl vm.overcommit_memory
# 查看网络连接状态
netstat -tulnp
ss -tulnp
# 检查丢包率
ping -c 100 example.com | grep "packet loss"
# 网络带宽测试
iperf3 -c server_ip
# 检查防火墙规则
iptables -L -n
nft list ruleset
# 检查被拒绝的连接
grep "DROP" /var/log/syslog
# 查看所有服务状态
systemctl list-units --type=service --state=running
# 检查失败的服务
systemctl --failed
# 查看服务日志
journalctl -u service_name -n 50
# 查看僵尸进程
ps aux | grep 'Z'
# 检查异常进程
ps aux --sort=-%cpu | head
ps aux --sort=-%mem | head
# 安装常用监控工具
sudo apt install sysstat dstat lm-sensors net-tools
# 安装Prometheus和Node Exporter
# 配置Grafana仪表板监控系统各项指标
# CPU压力测试
stress --cpu 8 --timeout 300
# 内存压力测试
stress --vm 4 --vm-bytes 1G --timeout 300
# 磁盘I/O压力测试
fio --name=test --ioengine=libaio --rw=randrw --bs=4k --numjobs=16 --size=1G --runtime=60 --time_based
# 检查系统启动时间
systemd-analyze
systemd-analyze blame
通过以上全面的检测方法,您可以系统地评估Linux系统的稳定性,及时发现并解决潜在问题,确保系统长期稳定运行。