温馨提示×

centos stream8怎么优化

小樊
42
2026-09-02 20:57:16
栏目: 智能运维

CentOS Stream 8 是 RHEL 的上游滚动发行版,已经于 2024-05-31 结束维护(EOL),官方不再提供安全更新。因此“优化”要分两层来看:

  1. 如果还能用(测试 / 内网 / 临时环境):做系统、性能、安全方面的常规优化
  2. 如果是生产环境:最优先的建议是 迁移到其他系统

下面我从「还能用时的优化」和「迁移建议」两方面说。


一、CentOS Stream 8 仍可用时的优化建议

1. 系统基础优化

(1)关闭无用服务

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

常见可关闭:

systemctl disable --now postfix
systemctl disable --now firewalld   # 如有其他防火墙

(2)时间同步

dnf install -y chrony
systemctl enable --now chronyd

(3)SELinux(按需)

getenforce
# 如不需要可设为 permissive
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=permissive/' /etc/selinux/config

2. 性能优化

(1)文件描述符

cat >> /etc/security/limits.conf <<EOF
* soft nofile 65535
* hard nofile 65535
EOF

(2)内核参数(Web / 高并发场景)

cat >> /etc/sysctl.conf <<EOF
net.core.somaxconn = 65535
net.ipv4.tcp_tw_reuse = 1
vm.swappiness = 10
EOF
sysctl -p

(3)I/O 调度(SSD)

cat /sys/block/sda/queue/scheduler
# 推荐 none / mq-deadline
echo mq-deadline > /sys/block/sda/queue/scheduler

3. 软件源与包管理

Stream 8 已 EOL,官方源可能不可用,可切换为 vault 源

sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo
dnf makecache

⚠️ 注意:vault 源 无安全更新


4. 安全优化(仅限非生产)

  • 禁止 root SSH 登录
  • 使用 key 登录
  • 配置基础防火墙(iptables / nftables)

二、强烈建议:尽快迁移(重要)

为什么不建议继续优化 Stream 8

  • ❌ 无安全补丁
  • ❌ 无 CVE 修复
  • ❌ 新软件无法安装

推荐替代方案

场景 推荐
生产服务器 Rocky Linux 8/9、AlmaLinux 8/9
想继续用 RHEL 生态 RHEL(免费 16 台)
新项目 Rocky 9 / Alma 9
容器 / 云原生 Ubuntu 22.04 / 24.04

迁移方式(近似 1:1)

  • migrate2rocky
  • almalinux-deploy

三、总结一句话

CentOS Stream 8 已经 EOL,优化只能“延寿”,不能“保命”。
生产环境请尽快迁移到 Rocky / Alma / RHEL。

如果你愿意,可以告诉我:

  • 物理机 / 云服务器
  • 用途(Web / 数据库 / K8s)
  • 是否生产环境

我可以给你一套 针对性优化或迁移方案

0