当Linux服务器出现网络阻塞时,可以采取以下系统化的处理措施:
# 查看当前网络连接状态
netstat -antp
ss -antp
# 查看连接数统计
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
# 实时查看网络流量
iftop -n
nload
# 查看网卡统计信息
ip -s link
# 查看占用网络资源最多的进程
nethogs
# 按网络使用排序进程
ps aux --sort=-%net
# 临时调整(重启失效)
sysctl -w net.ipv4.tcp_tw_reuse=1
sysctl -w net.ipv4.tcp_fin_timeout=30
sysctl -w net.core.somaxconn=65535
# 永久调整(写入/etc/sysctl.conf)
echo "net.ipv4.tcp_tw_reuse = 1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_fin_timeout = 30" >> /etc/sysctl.conf
echo "net.core.somaxconn = 65535" >> /etc/sysctl.conf
sysctl -p
# 检查iptables/nftables规则
iptables -L -n -v
nft list ruleset
# 检查连接限制
cat /proc/sys/net/netfilter/nf_conntrack_max
# 使用tcpdump抓包分析
tcpdump -i eth0 -w capture.pcap
# 使用Wireshark分析(需下载到本地)
# 或使用tshark命令行分析
tshark -r capture.pcap
ethtool eth0
通过以上系统化的排查和优化步骤,可以有效解决大多数Linux服务器的网络阻塞问题。