在 Debian(以及其它 Linux 发行版)上,进程占用内存高通常要先“看清楚是谁、为什么高”,再决定怎么处理。下面按排查 → 定位 → 处理 → 预防的顺序说明。
free -h
或
top
# 或
htop
重点关注:
used 高不代表异常(Linux 会利用内存做缓存)available,如果很小才说明真紧张ps aux --sort=-%mem | head
或
top -o %MEM
处理:
innodb_buffer_pool_size-Xmxpm.max_childrensystemctl restart mysql
判断:
处理:
[Service]
MemoryMax=512M
然后:
systemctl daemon-reload
systemctl restart xxx
Linux 会缓存文件:
free -h
如果 buff/cache 很大但 available 够,不用管。
手动释放(不推荐,除非测试)
sync && echo 3 > /proc/sys/vm/drop_caches
ps aux | awk '$8=="Z"'
处理:
查看:
swapon --show
如果没开:
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
htop / glances 实时监控systemd 限制资源apt update && apt upgrade
你可以贴出:
free -h 输出ps aux --sort=-%mem | head 结果我可以直接告诉你该改哪里、怎么改。