通過Linux清理和優化可以顯著提升服務器的性能。以下是一些常用的方法和步驟:
sudo rm -rf /tmp/*
sudo journalctl --vacuum-time=2weeks
sudo rm -f /var/log/*.log.*
dpkg --list | grep linux-image
sudo apt-get purge linux-image-<舊版本號>
/etc/security/limits.conf 文件,增加文件描述符的限制。* soft nofile 65536
* hard nofile 65536
/etc/sysctl.conf 文件,進行以下優化:net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
sysctl -p
sudo apt-get clean
sudo apt-get autoclean
sudo yum clean all
echo deadline > /sys/block/sda/queue/scheduler
top或htop監控內存使用:top
htop
sudo swapoff -a
sudo rm /swapfile
cron任務進行定期清理:
編輯 /etc/crontab 文件,添加定期清理任務。0 0 * * * root /path/to/cleanup_script.sh
vmstat監控系統性能:vmstat 1
iostat監控磁盤I/O:iostat -x 1
netstat監控網絡連接:netstat -tuln
通過以上步驟,你可以有效地清理和優化Linux服務器,提升其性能。記得在進行任何重大更改之前備份重要數據。