温馨提示×

Centos Stream8 如何优化

小樊
46
2026-08-18 18:21:58
栏目: 智能运维

CentOS Stream 8 已于 2024-05-31 正式 EOL(停止维护),官方不再提供安全更新和软件源。因此,“优化”的第一要务是:评估是否继续使用该版本

下面分 现状说明 → 必要加固 → 可选优化 → 迁移建议 四部分来说明。


一、先说结论(重要)

CentOS Stream 8 已不建议用于生产环境
✅ 强烈建议迁移到:

  • AlmaLinux 8 / Rocky Linux 8(RHEL 8 系列)
  • AlmaLinux 9 / Rocky Linux 9
  • CentOS Stream 9(如果你仍想用 Stream)

如果你必须继续用 CentOS Stream 8(如老系统、硬件限制),以下是可行的优化与加固方案。


二、基础系统优化(仍在使用时的必要操作)

1️⃣ 修复软件源(EOL 后必须)

官方源已失效,需切换到归档源:

sed -i 's|mirrorlist=|#mirrorlist=|g' /etc/yum.repos.d/CentOS-*.repo
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=https://vault.centos.org|g' /etc/yum.repos.d/CentOS-*.repo

然后:

dnf clean all
dnf makecache

⚠️ 此后 不再有安全更新


2️⃣ 内核与系统参数优化(通用)

内核参数

编辑:

vi /etc/sysctl.d/99-optimize.conf

常用优化(服务器):

# 网络
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_reuse = 1
net.core.somaxconn = 4096
net.ipv4.ip_local_port_range = 10000 65535

# 内存
vm.swappiness = 10
vm.overcommit_memory = 1

# 文件
fs.file-max = 1000000

生效:

sysctl --system

3️⃣ 文件描述符限制

vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535

4️⃣ 关闭无用服务

systemctl disable --now bluetooth
systemctl disable --now cups
systemctl disable --now postfix

5️⃣ 时间同步(必须)

dnf install -y chrony
systemctl enable --now chronyd

三、性能与安全优化(可选)

✅ 使用 tuned

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

常用 profile:

  • throughput-performance(服务器)
  • latency-performance(低延迟)
  • virtual-guest(虚拟机)

✅ 防火墙与 SELinux

# 防火墙
systemctl enable --now firewalld

# SELinux(不建议直接关闭)
getenforce

如必须调试:

setenforce 0

✅ SSH 安全优化

vi /etc/ssh/sshd_config

建议:

PermitRootLogin no
PasswordAuthentication no
UseDNS no
ClientAliveInterval 60
systemctl restart sshd

四、CentOS Stream 8 的未来建议(强烈)

✅ 迁移方案对比

方案 适用场景
AlmaLinux 8 最平滑替代
Rocky Linux 8 稳定、社区活跃
AlmaLinux 9 新系统首选
CentOS Stream 9 想继续用 Stream

✅ 原地迁移示例(Stream 8 → AlmaLinux 8)

dnf install -y epel-release
dnf install -y almalinux-deploy
almalinux-deploy

五、总结一句话

CentOS Stream 8 的“最优优化”就是:尽快迁移或隔离。

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

  • ✅ 这是 物理机 / 虚拟机 / 云服务器
  • ✅ 用途(Web / 数据库 / 容器 / 桌面)
  • ✅ 是否可重装

我可以给你 一套针对你场景的精确优化方案或迁移步骤

0