Created
December 24, 2014 07:34
-
-
Save rasefon/82e07c8448b240915e6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
阿里云服务器默认是没有swap的。而且阿里云服务器中在/etc/rc.d/rc.local脚本中将所有fstab中要求挂载的swap分区都给关闭了。所以在阿里云服务器上添加swap分区,重启之后都会失效。 | |
建立swap分区(1GB为例) | |
我们在var目录下建立一个swap分区文件,命名为swapfile。使用该文件启动swap。 | |
这里我们创建的是1G的swap分区,需要更大的可以自行修改下面的数据。 | |
dd if=/dev/zero of=/var/swapfile bs=1024 count=1048576 | |
/sbin/mkswap /var/swapfile | |
/sbin/swapon /var/swapfile | |
自动挂载 | |
添加到fstab文件中让系统引导时自动启动 | |
echo "/var/swapfile swap swap defaults 0 0" >>/etc/fstab | |
但是文章开始提到阿里云将要求挂载的swap分区都给关闭了。 | |
我们需要编辑/etc/rc.d/rc.local文件,将文件中的swapoff行注释或删掉。 | |
sed -i 's/swapoff -a/#swapoff -a/g' /etc/rc.d/rc.local | |
这样阿里云添加Swap分区后,就算重启也不会消失。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment