腾讯云开启 swap 分区

淮城一只猫 奇技淫巧
阅读量 0 评论量 0

前言

自从使用 MySQL8 大版本后,每次升级 ghost 就会提示内存不够的错误:

Loading...
载入代码中...
Message: You are recommended to have at least 150 MB of memory available for smooth operation. It looks like you have ~90.246093375MB available

但如果你要执行 ghost update --no-mem-check 来无视内存检测的话,你会发现在编译依赖包终端直接卡死,也就是说内存增大是必须的,群里的腾讯云工程师告诉我腾讯云默认是不开启 swap 功能,所以这里简单做一下开启 swap 过程。

开启 swap

先使用 free -m 命令查看 swap 是否开启:

Loading...
载入代码中...
11:20:29 ubuntu@VM-104-68-ubuntu ~ → free -m total used free shared buff/cache available Mem: 980 671 64 2 244 157 Swap: 0 0 0

创建在 /root/swap 的 2G 目录来作为交换分区的文件:

Loading...
载入代码中...
dd if=/dev/zero of=/root/swap bs=2048 count=1048576

设置改文件为交换文件:

Loading...
载入代码中...
mkswap /root/swap

修改权限:

Loading...
载入代码中...
chmod 600 /root/swap

启用交换分区文件

Loading...
载入代码中...
swapon /root/swap

设置自启动,否则服务器无法进入系统,修改 /etc/fstab 文件,在最后一行添加:

Loading...
载入代码中...
/root/swap swap swap defaults 0 0

查看是否开启交换分区:

Loading...
载入代码中...
11:20:29 ubuntu@VM-104-68-ubuntu ~ → free -m total used free shared buff/cache available Mem: 980 671 64 2 244 157 Swap: 2047 59 1988

类似上述说明正常使用了,期间升级 ghost 也不会出现内存不足的问题。

如果后期升级配置或者不再需要删除分区如下:

Loading...
载入代码中...
swapoff /root/swap rm -f /root/swap
喵~