优化 CentOS Minimal(最小化安装)主要围绕精简启动服务、释放内存、优化磁盘与网络、提升安全性几个方面。下面按实用优先级给你一套通用优化方案,适用于物理机、虚拟机或云服务器。
yum update -y
yum install -y vim net-tools wget curl lsof rsync
查看当前启动项:
systemctl list-unit-files | grep enabled
常见可关闭服务(按实际情况):
systemctl disable postfix
systemctl disable firewalld # 若用其他防火墙
✅ Minimal 本身服务很少,这是最安全的一步
systemctl disable kdump
kdump 在服务器上通常没用,可节省内存
swapoff -a
sed -i '/swap/d' /etc/fstab
编辑:
vim /etc/sysctl.conf
加入:
vm.swappiness = 0
vm.dirty_ratio = 10
vm.dirty_background_ratio = 5
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 1024 65535
net.core.somaxconn = 4096
应用:
sysctl -p
journalctl --vacuum-time=7d
vim /etc/systemd/journald.conf
SystemMaxUse=50M
echo deadline > /sys/block/sda/queue/scheduler
永久生效(grub):
vim /etc/default/grub
追加:
elevator=deadline
vim /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
vim /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
vim /etc/selinux/config
SELINUX=disabled
systemctl set-default multi-user.target
✅ 不要安装:
gnomekdex11✅ 推荐保留:
sshdnetworkcrontop
htop # 需安装
free -h
df -h
systemd-analyze
CentOS Minimal 的优化核心:少服务、少日志、少开销、稳内核
如果你愿意,可以告诉我:
我可以给你一份针对性优化清单,甚至直接出一个 optimize.sh 脚本。