交换空间太小,使用dd的方式扩展2G空间。
ubuntu@ubuntu-42:/usr/local/tomcat$ free -h
total used free shared buff/cache available
Mem: 7.6G 6.0G 855M 13M 765M 1.3G
Swap: 2.0G 2.0G 2.9M
ubuntu@ubuntu-42:/usr/local/tomcat$ sudo dd if=/dev/zero of=/home/swap bs=1024 count=2048000 #示意扩展2G的空间。
ubuntu@ubuntu-42:/usr/local/tomcat$ sudo mkswap /home/swap
ubuntu@ubuntu-42:/usr/local/tomcat$ sudo swapon /home/swap
ubuntu@ubuntu-42:/usr/local/tomcat$ free -h
total used free shared buff/cache available
Mem: 7.6G 6.0G 131M 13M 1.5G 1.4G
Swap: 4.0G 2.0G 2.0G
如果在原有基础上再次扩展,会报错:
$ sudo dd if=/dev/zero of=/home/swap bs=1024 count=2048000
dd: failed to open '/home/swap': Text file busy
解决:需要先关闭swap,再重新分配,即执行
$ sudo swapoff -a
结束。