translated

This commit is contained in:
geekpi 2015-05-21 21:07:36 +08:00
parent c356a2c2bb
commit 0e1c622fbf
2 changed files with 64 additions and 66 deletions

View File

@ -1,66 +0,0 @@
translating----geekpi
How to Use tmpfs on RHEL / CentOS 7.0
================================================================================
Today we will talk about tmpfs CentOS 7 a file system that will keep all files and folders in the virtual memory of the operating system as opposed to actually writing them to the disk. This means that all the content in tmpfs is temporary in the sense that its not permanently written to the disk and in case the tmpfs is unmounted, the system is rebooted or the power is cut all content will be lost. From a technical point of view tmpfs puts everything in the kernel internal cache and then grows or shrinks to accommodate the files it contains ans is able to swap unneeded pages out of swap space.
By default CentOS uses tmpfs for various things as you can see from the output of the df h command:
# df h
![df](http://blog.linoxide.com/wp-content/uploads/2015/05/tmpfs1.jpg)
/dev - directory contains the special device files for all the devices.
/dev/shm contains shared memory allocation
/run - used for system logs
/sys/fs/cgroup - used for cgroups, a kernel feature to limit, police and account the resource usage of certain processes
One use of tmpfs is to obviously use it as a /tmp folder, you can do this in 2 ways:
### Using systemctl to enable tmpfs in /tmp ###
You can use the systemctl command to enable tmpfs in the /tmp folder, first use the following command to check if this feature is not already enabled:
# systemctl is-enabled tmp.mount
Will show the current status of settings you can use the following command to enable it:
# systemctl enable tmp.mount
![systemctl](http://blog.linoxide.com/wp-content/uploads/2015/05/tmpfs3.jpg)
This will have the system controlling the /tmp folder and mount a tmpfs in it.
### Manually mounting a /tmp/fs ###
You can also manually add a tmpfs in /tmp by adding the following line to /etc/fstab:
tmpfs /tmp tmpfs size=512m 0 0
And then running the mount command like this:
# mount a
![df](http://blog.linoxide.com/wp-content/uploads/2015/05/tmpfs2.jpg)
This should make the tmpfs show in df h, also it will automatically mount it the next time you reboot.
### Creating a tmpfs on the fly ###
If for some reason you wish to create a tmpfs in a folder on the fly you can always use the following command:
# mount -t tmpfs -o size=1G tmpfs /mnt/mytmpfs
Of course you can specify any size you wish in the size option and any mount point you wish, just remember it must be a valid directory.
--------------------------------------------------------------------------------
via: http://linoxide.com/file-system/use-tmpfs-rhel-centos-7-0/
作者:[Adrian Dinu][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://linoxide.com/author/adriand/

View File

@ -0,0 +1,64 @@
如何在RHEL/CentOS 7.0中使用tmpfs
================================================================================
7中的tmpfs这是一个将所有文件和文件夹写到虚拟内存中而不是实际写到磁盘中的虚拟文件系统。这意味中tmpfs中所有的内容都是临时的在取消挂载、系统重启或者电源切断后内容都将会丢失。技术的角度上来说tmpfs将搜有的内容放在内核内部缓存中并且会增大或者缩小来容纳文件并可从交换空间中交换处不需要的页。
CentOS默认使用tmpfs做的事可用df -h命令的输出来看
# df h
![df](http://blog.linoxide.com/wp-content/uploads/2015/05/tmpfs1.jpg)
/dev - 含有针对所有设备的设备文件的目录
/dev/shm 包含共享内存分配
/run - 用于系统日志
/sys/fs/cgroup - 用于cgrpups 一个针对特定进程限制、管制和审计资源利用的内核特性
/tmp目录 你可以用下面的两种方法来做到:
### 使用systemctl来在/tmp中启用tmpfs ###
你可以使用systemctl命令在tmp目录启用tmpfs 首先用下面的命令来检查这个特性是否可用:
# systemctl is-enabled tmp.mount
这会显示当先的状态,你可以使用下面的命令来启用它:
# systemctl enable tmp.mount
![systemctl](http://blog.linoxide.com/wp-content/uploads/2015/05/tmpfs3.jpg)
这会控制/tmp目录并挂载tmpfs。
### 手动挂载/tmp/文件系统 ###
你可以在/etc/fstab中添加下面这行在/tmp挂载tmpfs。
tmpfs /tmp tmpfs size=512m 0 0
接着运行这条命令
# mount a
![df](http://blog.linoxide.com/wp-content/uploads/2015/05/tmpfs2.jpg)
这应该就会在df -h中显示tmpfs了同样也会在你下次重启是会自动挂载。
### 立即创建tmpfs ###
如果由于一些原因你写昂立即创建tmpfs你可以使用下面的命令
# mount -t tmpfs -o size=1G tmpfs /mnt/mytmpfs
当然你可以在size选项中指定你希望的大小和希望的挂载点只要记住是有效的目录就行了。
--------------------------------------------------------------------------------
via: http://linoxide.com/file-system/use-tmpfs-rhel-centos-7-0/
作者:[Adrian Dinu][a]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://linoxide.com/author/adriand/