Linux 系统优化实战记录

背景

最近公司服务器负载持续走高,经常出现响应缓慢。经过一周排查和优化,系统性能提升约40%,这里分享下优化过程。

一、监控与问题定位

1. CPU 分析

top -bn1 | head -20
uptime
htop

2. 内存使用

free -h
ps aux --sort=-%mem | head -11

3. 磁盘 I/O

iostat -x 1 5
iotop -o

二、优化措施

1. 内核参数调优

fs.file-max = 65535
net.core.somaxconn = 32768
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_tw_reuse = 1
vm.swappiness = 10

sudo sysctl -p

2. 启用 TCP BBR

echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sudo sysctl -p

3. 优化磁盘挂载

/dev/sda1  /  ext4  defaults,noatime  0  1

三、效果对比

• 平均响应时间:850ms → 320ms(提升 62%)

• CPU 使用率:85% → 45%

• 并发处理能力:500/s → 1200/s

← 返回首页

💬 评论 (12)

陈晨
2026-02-09
这些参数我也在用,效果确实明显。swappiness 设成 10 后内存利用率高多了。
D
David Chen
2026-02-10
TCP BBR is amazing! We saw a 50% improvement in latency for our international traffic after enabling it.
刘强
2026-02-10
TCP BBR 真的强!我们用了之后跨境访问速度提升明显。推荐所有人都开启。
S
Sarah Johnson
2026-02-11
Great article! Question: would these settings work well on Ubuntu 24.04 LTS? Or are there any specific considerations?
张伟(博主)
2026-02-11
@Sarah Johnson Yes, these work perfectly on Ubuntu 24.04 LTS! BBR is built into kernel 4.9+, so no issues there.
赵磊
2026-02-12
mark,回头试试。我们服务器也是这个问题,负载一直居高不下。
R
Raj Patel
2026-02-13
What about net.ipv4.tcp_fastopen? Should we enable it as well for better performance?
周杰
2026-02-14
请问 net.ipv4.tcp_tw_reuse 这个参数在高并发场景下稳定吗?会不会有副作用?
张伟(博主)
2026-02-14
@Raj Patel Yes, tcp_fastopen=3 is recommended! @周杰 tcp_tw_reuse 很稳定,我们生产环境跑了2年没问题。
孙丽
2026-02-16
noatime 挂载选项真的有用吗?会不会影响某些应用的功能?
M
Michael Brown
2026-02-18
Excellent writeup! We're managing 20+ servers and these optimizations will help a lot. Thanks for sharing! 🚀
马云飞
2026-02-20
收藏了!准备用 Ansible 批量部署这些配置到我们的服务器集群。

发表评论