Linux 服务器性能优化实战
服务器性能优化是运维工程师的必备技能。本文分享实战经验。
一、CPU 优化
监控工具
# 实时查看 CPU 使用率
top
查看各进程 CPU 占用
ps aux --sort=-%cpu | head -10
查看 CPU 负载
uptime
优化建议
- 使用 nice/renice 调整进程优先级
- 使用 taskset 绑定 CPU 核心
- 避免频繁的上下文切换
二、内存优化
监控命令
free -h
vmstat 1 5
Swap 配置
# 创建 2GB Swap
dd if=/dev/zero of=/swapfile bs=1M count=2048
mkswap /swapfile
swapon /swapfile
三、磁盘 I/O 优化
# 监控磁盘 I/O
iostat -x 1
查看磁盘使用情况
df -h
du -sh /*
四、网络优化
# 查看网络连接
netstat -tlnp
ss -tlnp
抓包分析
tcpdump -i eth0 port 80
五、内核参数调优
# /etc/sysctl.conf
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
vm.swappiness = 10