CentOS Stream 8 已于 2024-05-31 正式 EOL(停止维护),官方不再提供安全更新和软件源。因此,“优化”的第一要务是:评估是否继续使用该版本。
下面分 现状说明 → 必要加固 → 可选优化 → 迁移建议 四部分来说明。
✅ CentOS Stream 8 已不建议用于生产环境
✅ 强烈建议迁移到:
如果你必须继续用 CentOS Stream 8(如老系统、硬件限制),以下是可行的优化与加固方案。
官方源已失效,需切换到归档源:
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
⚠️ 此后 不再有安全更新
编辑:
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
vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
systemctl disable --now bluetooth
systemctl disable --now cups
systemctl disable --now postfix
dnf install -y chrony
systemctl enable --now chronyd
dnf install -y tuned
systemctl enable --now tuned
tuned-adm recommend
tuned-adm profile throughput-performance
常用 profile:
throughput-performance(服务器)latency-performance(低延迟)virtual-guest(虚拟机)# 防火墙
systemctl enable --now firewalld
# SELinux(不建议直接关闭)
getenforce
如必须调试:
setenforce 0
vi /etc/ssh/sshd_config
建议:
PermitRootLogin no
PasswordAuthentication no
UseDNS no
ClientAliveInterval 60
systemctl restart sshd
| 方案 | 适用场景 |
|---|---|
| AlmaLinux 8 | 最平滑替代 |
| Rocky Linux 8 | 稳定、社区活跃 |
| AlmaLinux 9 | 新系统首选 |
| CentOS Stream 9 | 想继续用 Stream |
dnf install -y epel-release
dnf install -y almalinux-deploy
almalinux-deploy
CentOS Stream 8 的“最优优化”就是:尽快迁移或隔离。
如果你愿意,可以告诉我:
我可以给你 一套针对你场景的精确优化方案或迁移步骤。