CentOS Stream 8 已经是 RHEL 8 的“滚动预览”版本,底层和 RHEL 8 基本一致。优化性能通常从 内核参数、系统服务、文件系统、资源限制、网络、应用层 几个方面入手。下面给你一套比较实用的优化清单(偏通用服务器场景)。
dnf update -y
保持内核和补丁最新,很多性能和安全问题会随更新修复。
查看开机启动服务:
systemctl list-unit-files --type=service | grep enabled
常见可关闭(视用途而定):
systemctl disable --now firewalld # 若用云安全组或硬件防火墙
systemctl disable --now postfix
systemctl disable --now bluetooth
/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
/etc/security/limits.conf* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
systemctl edit xxx.service
添加:
[Service]
LimitNOFILE=65535
推荐:
noatime/etc/fstab 示例:
/dev/sda1 /data xfs defaults,noatime,nodiratime 0 0
查看:
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"
dnf install -y tuned
systemctl enable --now tuned
tuned-adm profile throughput-performance
可选:
latency-performance(低延迟)virtual-guest(虚拟机)ethtool -L eth0 combined 8
echo f > /sys/class/net/eth0/queues/rx-0/rps_cpus
dnf install -y sysstat htop iotop net-tools lsof
常用:
top
htop
iostat -x 1
vmstat 1
ss -antp
virtual-guest tuned如果你能说明 用途(Web / DB / 容器 / K8s) 和 硬件(CPU/内存/磁盘),我可以给你更精准的优化配置。