要使用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
在進行上述操作之前,建議備份重要數據,以防意外刪除。此外,定期執行這些清理和維護任務,可以幫助保持系統的最佳性能。