CentOS dropped 最佳实践
一 问题定位与快速处置
journalctl -xe、tail -n 200 /var/log/messages;ping 8.8.8.8、traceroute 8.8.8.8;ip addr、ethtool <iface>;df -h、free -m、top/vmstat/iostat;sudo iptables -L -n -v --line-numbers、cat /proc/net/ip_conntrack | wc -l、cat /proc/sys/net/ipv4/ip_conntrack_max;二 常见根因与对应处置
sudo sysctl -w net.ipv4.netfilter.ip_conntrack_max=100000;/etc/sysctl.conf 添加 net.ipv4.netfilter.ip_conntrack_max = 100000 并执行 sysctl -p;net.netfilter.nf_conntrack_tcp_timeout_established)并评估连接复用/长连接策略。sudo iptables -L -n -v --line-numbers;必要时临时将默认策略设为 ACCEPT 验证,再精细化规则;sudo iptables-save > /etc/iptables/rules.v4;firewalld 时仅放行必要服务(如 SSH/HTTP/HTTPS),变更后 firewall-cmd --reload。/etc/sysconfig/network-scripts/ifcfg-<iface> 或使用 nmcli/ip 修正,重启网络服务并复测连通性。/etc/security/limits.conf 增加 * soft nofile 65536、* hard nofile 65536;df -h 定位大占用目录,清理 /var/log、/tmp,必要时扩容或迁移日志。三 推荐配置与优化参数
/etc/sysctl.conf,执行 sysctl -p 生效)
net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.ipv4.tcp_rmem = 4096 87380 16777216net.ipv4.tcp_wmem = 4096 65536 16777216net.ipv4.tcp_mem = 786432 1048576 26777216net.ipv4.tcp_fin_timeout = 30net.ipv4.tcp_keepalive_time = 120net.ipv4.tcp_syncookies = 1net.ipv4.netfilter.ip_conntrack_max = 100000(按内存与业务评估调整);sudo iptables -A INPUT -p tcp --dport 22 -m connlimit --connlimit-above 5 -j DROP/etc/security/limits.conf:
* soft nofile 65536* hard nofile 65536firewall-cmd --reload;PermitRootLogin no、PasswordAuthentication no、PubkeyAuthentication yes、按需更改端口并限制来源 IP。四 长期预防与运维建议
sudo yum update -y(CentOS 7)或 sudo dnf update -y(CentOS 8/Stream),关键系统建议启用自动更新策略。/home、/etc 等关键目录(如 rsync/tar);firewalld/iptables 实施白名单与速率限制,减少资源被滥用导致的“dropped”。