一、系统与网络诊断
1. 查看实时网络连接与端口占用
Linux
netstat -tulnp | grep 80 检查80端口占用进程
ss -antp 替代netstat,显示更详细的TCP连接
lsof -i :22 查看22端口(SSH)的进程信息
Windows
netstat -ano | findstr "LISTENING" 查看监听端口
tasklist | findstr "PID" 根据PID查进程名
2. 测试网络连通性与延迟
ping 8.8.8.8 基础连通性测试
traceroute www.baidu.com Linux追踪路由路径
tracert www.baidu.com Windows追踪路由路径
mtr -r www.baidu.com 实时监控路由跳数及丢包(Linux)
3. 带宽与流量监控
Linux实时流量监控
iftop -i eth0 按IP显示实时流量(需安装iftop)
nload eth0 简易带宽监控
sar -n DEV 1 10 统计网卡流量(每秒1次,共10次)
Windows流量统计
Performance Monitor(perfmon.msc)中添加“Network Interface”计数器
---
二、日志分析与故障排查
1. 关键日志检索
Linux日志过滤
tail -f /var/log/syslog 实时追踪系统日志
grep "error" /var/log/messages 筛选错误日志
journalctl -u nginx --since "2023-08-01" --until "2023-08-02" 按时间查看服务日志
Windows事件日志
Get-EventLog -LogName System -EntryType Error -Newest 10 PowerShell查系统错误
2. 进程与资源占用分析
top Linux动态查看进程资源占用
htop 更友好的交互式监控工具
ps aux --sort=-%mem | head -10 按内存占用排序进程
free -h 查看内存使用情况
iostat -x 1 10 监控磁盘I/O性能
---
三、配置备份与恢复
1. 网络设备配置备份
Cisco交换机(SSH/Telnet)
show running-config 查看当前配置
copy running-config tftp://192.168.1.100/backup.cfg 备份到TFTP服务器
华为交换机
display current-configuration
tftp 192.168.1.100 put vrpcfg.zip 通过TFTP备份
2. Linux配置文件备份
使用tar压缩备份
tar -czvf /backup/nginx_conf_$(date +%F).tar.gz /etc/nginx/
使用rsync同步到远程服务器
rsync -avz /etc/nginx/ user@backup-server:/backup/nginx/
---
四、安全加固与防火墙
1. 防火墙规则管理
Linux(iptables/ufw)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT 允许SSH端口
ufw allow 80/tcp Ubuntu简化命令
firewall-cmd --permanent --add-port=443/tcp firewalld(CentOS)
Windows防火墙
netsh advfirewall firewall add rule name="Allow HTTP" dir=in action=allow protocol=TCP localport=80
2. SSH安全配置
修改SSH端口并禁用密码登录
sed -i 's/Port 22/Port 2222/' /etc/ssh/sshd_config
echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
systemctl restart sshd
---
常用场景速查表
场景 命令/操作
网站无法访问 `curl I http //域名` 查看HTTP状态码,`telnet 域名 80` 测试端口连通性
DNS解析失败 `dig 域名 +trace` 或 `nslookup 域名 8.8.8.8` 指定DNS服务器测试
磁盘空间不足告警 `df h` 查看分区使用率,`du sh * \ sort h` 定位大文件
服务进程崩溃自动重启 `systemctl enable now nginx` 设置开机自启,或使用`supervisor`监控进程
---