要减少CentOS系统的内存占用,可以采取以下几种方法:
systemctl list-units --type=service --state=running
systemctl stop <service_name>
systemctl disable <service_name>
sysctl vm.swappiness=10
要使其永久生效,编辑/etc/sysctl.conf
文件并添加:vm.swappiness=10
systemctl list-unit-files --type=service --state=enabled
systemctl disable <service_name>
sudo apt-get clean
sudo rm -rf /tmp/*
htop
代替top
。sudo sysctl -w vm.vfs_cache_pressure=50
这个值越低,系统越倾向于保留文件系统缓存。sudo modprobe zram num_devices=1
sudo systemctl enable zram-config
sudo systemctl start zram-config
htop
或free -m
等工具定期监控内存使用情况,以便及时发现问题。通过以上方法,可以有效地减少CentOS系统的内存占用,提高系统的性能和稳定性。