如何在centos6.x 下建立swap文件
来源:互联网 发布:robotart软件多少钱 编辑:程序博客网 时间:2024/05/16 03:48
原文出处
https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-centos-6
Check for Swap Space
Before we proceed to set up a swap file, we need to check if any swap files have been enabled by looking at the summary of swap usage.
在我们开始建立一个swap文件之前我们需要先检查是否已经有swap并正在使用了。通过swap查看summary来看
swapon -s
If nothing is returned, the summary is empty and no swap file exists.
如果什么都没有返回,summary就是空的并没有swap文件被显示出来
Check the File System
After we know that we do not have a swap file enabled, we can check how much space we have on the server with the df
command. The swap file will take 512MB— since we are only using up about 7% of the /dev/hda, we can proceed.
在我们确定我们没有swap文件被启用后,我们可以检查我们的服务器有多少空间。使用df命令来查看。swap文件将会占用512MB。因为我们现在只用了/dev/hda的7%,所以是可行的
dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/hda 20642428 1347968 18245884 7% /
Create and Enable the Swap File
Now it’s time to create the swap file itself using the dd command :
现在是通过dd命令来创建swap文件的时候了
sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k
“of=/swapfile” designates the file’s name. In this case the name is swapfile.
"of=/swapfile" 指定了文件的名字,在这个例子中文件名是 swapfile
Subsequently we are going to prepare the swap file by creating a linux swap area:
随后我们要通过创建linux swap区域来初始化swap文件
sudo mkswap /swapfile
The results display:
执行结果是
Setting up swapspace version 1, size = 536866 kB
Finish up by activating the swap file:
最后我们激活swap文件
sudo swapon /swapfile
You will then be able to see the new swap file when you view the swap summary.
现在当你查看swap summary的时候你就可以看到那个新的swap文件了
swapon -sFilenameTypeSizeUsedPriority/swapfile file5242800-1
This file will last on the server until the machine reboots. You can ensure that the swap is permanent by adding it to the fstab file.
这个文件会一直存在直到你重启。如果你想让这个文件永久保留,可以通过添加以下行到fstab文件里
Open up the file:
打开fstab文件
sudo nano /etc/fstab
Paste in the following line:
把下面这行粘贴进去
/swapfile swap swap defaults 0 0
To prevent the file from being world-readable, you should set up the correct permissions on the swap file:
为了防止匿名用户访问这个文件,我们要设置一下swap文件的权限
chown root:root /swapfile chmod 0600 /swapfile
- 如何在centos6.x 下建立swap文件
- 如何在VMware下安装Centos6.x
- OS X 下如何为文件和文件夹建立密码保护
- Linux建立Swap文件
- 如何在Linux下增加Swap
- 如何在Linux下增加Swap (转)
- 如何在Linux下增加Swap
- centos6下增加swap空间
- Linux下swap文件的建立与应用
- 如何在CentOS6.5下编译64位的Hadoop2.x?
- 如何在CentOS6.5下编译64位的Hadoop2.x(一)
- centos6.x 网卡建立bond
- 在不增加swap分区的情况下使用swap文件来增加swap
- 如何在自定义文件下创建cocos2d-x项目
- 在CentOS6.6下建立c++11开发环境
- 如何在centos6.5下安装wxPython
- 如何在centos6下安装gcc
- 在什么情况下使用Oracle密码文件?如何建立密码文件?
- CSS预处理器SASS | LESS等简介
- select 2级联动和checkbox全选框联动
- Nanopi2 Fire 编写SPI驱动
- EF映射——linq to Entity ,不支持方法 get_item(int 32) 无法转换为存储表达式
- Linux多线程编程
- 如何在centos6.x 下建立swap文件
- [leetcode] 40. Combination Sum II
- Bootstrap学习小结
- 深度使用react-native的热更新能力,必须知道的一个shell命令
- [leetcode] 236. Lowest Common Ancestor of a Binary Tree
- 启动Activity时的方法调用(应用层)(MVC模式)
- ROM、PROM、EPROM、EEPROM、Flash ROM分别指什么?
- [leetcode] 131. Palindrome Partitioning
- JAVA学习笔记13:IO&类集