“CentOS Minimal”本身就是一个精简版系统(没有 GUI、很少服务),但如果你是要把它用于生产/服务器/容器宿主/性能场景,可以从下面几个维度做优化。下面以 CentOS 7 / CentOS 8 Stream(Minimal) 通用为主。
Minimal 默认服务不多,但仍可精简:
systemctl list-unit-files --type=service | grep enabled
常见可关闭(视用途):
systemctl disable --now postfix
systemctl disable --now firewalld # 若用 iptables 或云安全组
⚠️ 如果是公网服务器,不建议直接关 firewalld,应配置规则。
timedatectl set-timezone Asia/Shanghai
yum install -y chrony
systemctl enable --now chronyd
编辑 /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
/etc/security/limits.d/99-nofile.conf
* soft nofile 1000000
* hard nofile 1000000
Minimal 默认已是 xfs,挂载时建议:
mount -o noatime,nodiratime /dev/sda1 /data
永久:/etc/fstab
/dev/sda1 /data xfs defaults,noatime,nodiratime 0 0
journalctl --vacuum-size=50M
/etc/systemd/journald.conf
Storage=persistent
SystemMaxUse=100M
/etc/sysctl.d/99-disable-ipv6.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
GRUB 也可禁用(可选)。
yum install -y tuned
systemctl enable --now tuned
tuned-adm profile throughput-performance
常用 profile:
balancedthroughput-performancelatency-performancenetwork-latency/etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
ClientAliveInterval 60
systemctl restart sshd
firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload
getenforce
只装必要:
yum install -y vim curl wget net-tools bind-utils
yum repolist
关闭:
yum-config-manager --disable repo-name
cloud-init(云环境)qemu-guest-agent(KVM)container-selinuxyum install -y htop iotop atop
定期:
yum update -y
CentOS Minimal 的优化核心:关服务、调内核、限资源、强安全、用 tuned。
如果你能告诉我:
我可以给你更精确的一套配置。