温馨提示×

centos minimal怎么优化

小樊
54
2026-10-05 17:42:22
栏目: 智能运维

“CentOS Minimal”本身就是一个精简版系统(没有 GUI、很少服务),但如果你是要把它用于生产/服务器/容器宿主/性能场景,可以从下面几个维度做优化。下面以 CentOS 7 / CentOS 8 Stream(Minimal) 通用为主。


一、系统安装后基础优化

1. 关闭不必要服务

Minimal 默认服务不多,但仍可精简:

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

常见可关闭(视用途):

systemctl disable --now postfix
systemctl disable --now firewalld   # 若用 iptables 或云安全组

⚠️ 如果是公网服务器,不建议直接关 firewalld,应配置规则。


2. 时间 & 时区

timedatectl set-timezone Asia/Shanghai
yum install -y chrony
systemctl enable --now chronyd

3. 内核参数优化(重要)

编辑 /etc/sysctl.d/99-optimize.conf:

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

# 网络
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 1024 65535

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

应用:

sysctl --system

4. 文件句柄限制

/etc/security/limits.d/99-nofile.conf

* soft nofile 1000000
* hard nofile 1000000

二、磁盘 & 文件系统优化

1. 文件系统(推荐 xfs)

Minimal 默认已是 xfs,挂载时建议:

mount -o noatime,nodiratime /dev/sda1 /data

永久:/etc/fstab

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

2. 关闭 unnecessary 日志

journalctl --vacuum-size=50M

/etc/systemd/journald.conf

Storage=persistent
SystemMaxUse=100M

三、网络优化(服务器场景)

1. 禁用 IPv6(如不用)

/etc/sysctl.d/99-disable-ipv6.conf

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

GRUB 也可禁用(可选)。


2. 使用 tuned

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

常用 profile:

  • balanced
  • throughput-performance
  • latency-performance
  • network-latency

四、安全优化

1. SSH 优化

/etc/ssh/sshd_config

PermitRootLogin no
PasswordAuthentication no
ClientAliveInterval 60
systemctl restart sshd

2. 防火墙(推荐保留)

firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload

3. SELinux(看场景)

  • 生产:保持 enforcing
  • 内部/测试:可 permissive
getenforce

五、软件 & 包管理优化

1. 精简安装

只装必要:

yum install -y vim curl wget net-tools bind-utils

2. 禁用无用 repo

yum repolist

关闭:

yum-config-manager --disable repo-name

六、如果是“虚拟机 / 云 / 容器宿主”

  • 安装 cloud-init(云环境)
  • 安装 qemu-guest-agent(KVM)
  • 容器宿主:
    • 关 swap
    • 优化 cgroup
    • 用 container-selinux

七、监控 & 维护

yum install -y htop iotop atop

定期:

yum update -y

总结一句话

CentOS Minimal 的优化核心:关服务、调内核、限资源、强安全、用 tuned。

如果你能告诉我:

  • CentOS 版本(7 / 8 / Stream)
  • 用途(Web / 数据库 / 容器 / 桌面 / 云)

我可以给你更精确的一套配置。

0 踩