This blog is for Network file system NFS with only one
server. 但NFS有新版本支持multi-server了。
For distributed file system (multiple servers): openAFS, GlusterFS (native support on Redhat/centOS).
For cluster file systems: GFS2 (linux native support)
So, what is the difference among network, distributed and cluster file systems?. 补充一点: Distributed or netowrk file system also ensure data availability across multiple server nodes and can usually handle nodes being added and removed more gracefully. Don’t make assumptions about how well this will work; be sure to test not only for performance and latency, but also for the impact of changes to the cluster and for failure scenarios.
NFS是一个概念(protocol),它不是一个文件系统的类型,它是一种文件系统的共享方式, 这里默认使用本地Linux的文件系统类型了。
NFS allows remote hosts to mount filesystems
(can be any) over a network and interact with those filesystems as though they are mounted locally.
NFS lets you leverage storage space in a different location and allows you to write onto the same space from multiple servers or clients in an effortless manner. It, thus, works fairly well for directories that users need to access frequently.
常见用法,比如分享home directories so if switch to different host, just mount them, supports diskless machines, but be careful with UIDs and GIDs, ensure they are the same person on each machine.
Server Setup
Acutally there are many other package may needed, this video may give you more details.
1 | # install nfs package |
Then enable and start nfs server:
1 | # the rpc by default should be on, but may not |
Edit /etc/exports
file to expose shared folder
1 | vi /etc/exports |
Then export the shared folder:
1 | exportfs -a |
Check shared folder is up showmount -e <server ip>
:
1 | showmount -e localhost |
If you change the content in /etc/exports
, need to reload:
1 | exportfs -ra |
Check mount options:
1 | exportfs -v |
Client Setup
First create or using existing folder as folder to mount, here I use /mntiis
folder in client machine
1 | # install nfs package |
If you use non-persistent mount in command line, this connection will disappear after rebooting:
1 | mount <server ip>:/data /mntiis |
For persistent mount, go to /etc/fstab
file, add this line
1 | <server ip>:/data /mntiis nfs defaults 0 0 |
Enable mount:
1 | mount /mntiis |
Verify all set, you can see the /mntiis
in the output:
1 | df -hk |
When you remove the entry in /etc/fstab
filem, also unmount the folder, otherwise you will see /mntiis
is marked by ?
in filesystem:
1 | umount /mntiis |
Mount On-demand
You can set NFS auto mount on-demand via autofs
, this can avoid wasting resources by unmounting mount point when not using and mounting it when access again.
1 | yum install -y autofs |