NFS Server and Client Setup

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
2
# install nfs package
yum -y install nfs-utils

Then enable and start nfs server:

1
2
3
4
5
6
7
8
9
10
11
# the rpc by default should be on, but may not
# rpc is called remote producture call
# nfs server needs this to access and operate on others
systemctl enable rpcbind
systemctl start rpcbind

systemctl enable nfs-server.service
systemctl start nfs-server.service
# create server side shared folder
mkdir –p /data
chmod –R 755 /data

Edit /etc/exports file to expose shared folder

1
2
3
4
5
6
vi /etc/exports 

# any client can access this folder
/data *(rw,insecure,async,no_root_squash)
# or specific client can access this folder
/data <client ip>(rw,insecure,async,no_root_squash)

Then export the shared folder:

1
2
exportfs -a
systemctl restart nfs-server.service

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
2
3
4
5
6
# install nfs package
yum -y install nfs-utils

# create client side shared folder
mkdir -p /mntiis
chmod -R 0755 /mntiis

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
2
3
<server ip>:/data /mntiis nfs defaults 0 0
# or with other mount options
<server ip>:/data /mntiis nfs defaults,timeo=10,retrans=3,rsize=1048576,wsize=1048576 0 0

Enable mount:

1
2
3
mount /mntiis
# or reload all in fstab file
mount -a

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
2
yum install -y autofs
systemctl start autofs
0%