解决Ubuntu虚拟机性能瓶颈的多维度方法
使用top(实时进程监控,按CPU/内存排序)、htop(增强版top,支持颜色和树状视图)、df -h(磁盘空间使用率)、free -m(内存及swap使用情况)、iostat -x 1(磁盘IO负载)等命令,识别占用资源过高的进程(如高CPU的Xorg、高内存的chrome或java进程)。针对异常进程,可选择终止(kill -9 PID)或优化其配置(如限制进程的CPU使用率,通过cpulimit工具)。
apt-get clean、rm -rf /tmp/*)和旧日志(journalctl --vacuum-time=1w,删除一周前日志)。sudo apt install xfce4,然后通过startxfce4启动)。swappiness值(控制swap使用频率,默认60,建议10-30):sudo sysctl vm.swappiness=10,并添加到/etc/sysctl.conf持久化;dirty_ratio(脏页写入阈值,默认20%,建议10-15%):sudo sysctl vm.dirty_ratio=10,减少写回操作对IO的影响。sudo apt autoremove --purge)、无用的软件包(sudo apt autoclean)和缓存(sudo apt clean),释放磁盘空间。/etc/fstab中为磁盘添加noatime(禁用访问时间更新)、nodiratime(禁用目录访问时间更新)、discard(启用TRIM,适用于SSD)参数,减少不必要的磁盘写入(示例:UUID=xxx / ext4 defaults,noatime,nodiratime,discard 0 1)。lvcreate -i 2 -I 64 -L 10G vg_name lv_name,-i为条带数,-I为条带大小),提升多磁盘并发IO性能。iostat -x 1(查看磁盘利用率、IO等待时间)、iotop(实时查看进程IO负载)、fio(灵活测试随机/顺序读写性能,如fio --name=randread --filename=testfile --bs=4k --size=1G --readwrite=randread --runtime=60 --time_based)评估优化效果。systemctl list-unit-files --state=enabled查看开机自启服务,禁用不需要的服务(如bluetooth、cups,sudo systemctl disable bluetooth),减少系统启动时间和资源占用。zram-config创建压缩的交换空间(sudo apt install zram-config),提升swap性能(无需额外磁盘空间)。