要使用CentOS Cleanup来优化系统性能,可以按照以下步骤进行操作:
使用以下命令清理YUM缓存:
sudo yum clean all
使用以下命令删除无用的软件包和依赖:
sudo yum autoremove
使用以下命令删除旧内核,只保留最近的几个内核版本:
sudo package-cleanup --oldkernels --count=2
清理 /var/log
目录中不必要的日志文件:
find /var/log/ -type f -name "*.log" -mtime +30 -exec rm -f {} \;
清理 /tmp
目录中的临时文件和YUM缓存:
sudo rm -rf /tmp/*
sudo yum clean all
使用 df
和 du
命令查看和管理磁盘空间:
df -h
du -sh /var/*
编辑 /etc/sysctl.conf
文件,添加或修改内核参数以提高性能:
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = "1024 65535"
net.ipv4.tcp_max_syn_backlog = 8192
net.core.somaxconn = 1024
net.core.netdev_max_backlog = 2000
net.ipv4.tcp_max_orphans = 32768
net.ipv4.tcp_syncookies = 1
然后执行以下命令使更改生效:
sudo sysctl -p
确保系统和所有已安装的软件包都是最新的:
sudo yum update -y
提供额外的软件包,提高系统性能和功能:
sudo yum install epel-release -y
同步系统时间,保持系统的稳定性和性能:
sudo yum install ntp -y
sudo systemctl enable ntps
sudo systemctl start ntpd
根据需求禁用不需要的服务:
systemctl list-unit-files --typeservices
sudo systemctl disable service_name
为文件系统添加 noatime
和 nodiratime
选项:
/dev/sda1 / ext4 defaults,noatime,nodiratime 0 0
通过调整 vm.swappiness
和相关参数优化内存性能:
vm.swappiness = 10
在进行上述操作之前,建议备份重要数据,以防意外删除。此外,定期执行这些清理和维护任务,可以帮助保持系统的最佳性能。