优化 CentOS Minimal(最小化安装)主要是为了:减小体积、提升安全性、加快启动速度、降低资源占用。下面按 系统配置、内核、服务、网络、存储、安全、日常维护 等方面给你一份实践清单(适用于 CentOS 7 / CentOS 8 Stream / Rocky / Alma 类似)。
yum update -y # CentOS 7
dnf update -y # CentOS 8+
查看并删除无用软件:
rpm -qa | wc -l
典型可删:
yum remove -y nano sendmail ftp telnet
编辑:
vi /etc/sysctl.conf
常用优化:
vm.swappiness = 10
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
减少启动等待时间:
vi /etc/default/grub
GRUB_TIMEOUT=2
更新:
grub2-mkconfig -o /boot/grub2/grub.cfg
查看服务:
systemctl list-unit-files --type=service | grep enabled
禁用示例:
systemctl disable postfix
systemctl disable firewalld # 如用 iptables 或云安全组
保留常用:
| 原服务 | 替代 |
|---|---|
| firewalld | iptables / nftables |
| postfix | 不装 |
| tuned | 关闭 |
grubby --update-kernel=ALL --args="ipv6.disable=1"
或:
vi /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
vi /etc/resolv.conf
nameserver 223.5.5.5
nameserver 8.8.8.8
vi /etc/fstab
UUID=xxx / ext4 defaults,noatime 0 0
package-cleanup --oldkernels --count=1
vi /etc/ssh/sshd_config
推荐:
Port 2222
PermitRootLogin no
PasswordAuthentication no
UseDNS no
重启:
systemctl restart sshd
firewall-cmd --set-default-zone=drop
firewall-cmd --permanent --add-port=2222/tcp
firewall-cmd --reload
vi /etc/selinux/config
SELINUX=disabled
vi /etc/systemd/journald.conf
SystemMaxUse=50M
tophtopvmstatnetstat -tunlpvi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
yum clean all
dnf clean all
rm -rf /usr/share/doc/*
rm -rf /usr/share/man/*
✅ 容器基础镜像
✅ 云服务器
✅ 边缘设备
✅ 纯 CLI 环境
禁用 IPv6
禁用 SELinux
优化 SSH
禁用无用服务
noatime
sysctl 网络优化
如果你愿意,我可以:
你现在是 物理机 / 虚拟机 / 云服务器 / Docker 基础镜像 哪种?