温馨提示×

centos stream8怎样优化性能

小樊
50
2026-09-08 22:37:40
栏目: 智能运维

CentOS Stream 8 已经是 RHEL 8 的“滚动预览”版本,底层和 RHEL 8 基本一致。优化性能通常从 内核参数、系统服务、文件系统、资源限制、网络、应用层 几个方面入手。下面给你一套比较实用的优化清单(偏通用服务器场景)。


一、系统基础优化

1. 更新系统

dnf update -y

保持内核和补丁最新,很多性能和安全问题会随更新修复。

2. 关闭不必要的服务

查看开机启动服务:

systemctl list-unit-files --type=service | grep enabled

常见可关闭(视用途而定):

systemctl disable --now firewalld   # 若用云安全组或硬件防火墙
systemctl disable --now postfix
systemctl disable --now bluetooth

二、内核与系统参数优化

1. 调整 /etc/sysctl.conf

# 网络连接
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 8192

# 文件句柄
fs.file-max = 1000000

# 内存
vm.swappiness = 10
vm.dirty_ratio = 10
vm.dirty_background_ratio = 5

应用配置:

sysctl -p

三、文件描述符与用户限制

1. 修改 /etc/security/limits.conf

* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535

2. 确认 systemd 限制

systemctl edit xxx.service

添加:

[Service]
LimitNOFILE=65535

四、磁盘与文件系统优化

1. 使用合适的文件系统

推荐:

  • XFS(默认,稳定)
  • 大文件 / 高并发:XFS + noatime

2. 挂载优化

/etc/fstab 示例:

/dev/sda1 /data xfs defaults,noatime,nodiratime 0 0

3. 磁盘调度器(SSD 必看)

查看:

cat /sys/block/sda/queue/scheduler

SSD 推荐 none 或 mq-deadline:

echo mq-deadline > /sys/block/sda/queue/scheduler

永久配置(grub):

grubby --update-kernel=ALL --args="elevator=mq-deadline"

五、CPU 与性能模式

1. 开启高性能模式

dnf install -y tuned
systemctl enable --now tuned
tuned-adm profile throughput-performance

可选:

  • latency-performance(低延迟)
  • virtual-guest(虚拟机)

六、网络性能优化

1. 开启多队列(网卡)

ethtool -L eth0 combined 8

2. 开启 RPS / RFS(多核软中断)

echo f > /sys/class/net/eth0/queues/rx-0/rps_cpus

七、内存与 Swap

  • 服务器建议 swap ≤ 2G 或关闭
  • swappiness 调低(前面已写)

八、监控与诊断工具

dnf install -y sysstat htop iotop net-tools lsof

常用:

top
htop
iostat -x 1
vmstat 1
ss -antp

九、常见场景建议

  • Web 服务:重点调 TCP + 文件句柄
  • 数据库:重点调 vm + IO + 内核参数
  • 虚拟机:开启 virtual-guest tuned

如果你能说明 用途(Web / DB / 容器 / K8s) 和 硬件(CPU/内存/磁盘),我可以给你更精准的优化配置。

0 踩