Home Linux CentOS: NFS – quick install

CentOS: NFS – quick install

by Kliment Andreev
0 comment
Reading Time: 2 minutes

NFS (Network File System) is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a computer network much like local storage is accessed. NFS, like many other protocols, builds on the Open Network Computing Remote Procedure Call (ONC RPC) system. The NFS is an open standard defined in Request for Comments (RFC), allowing anyone to implement the protocol. That’s what Wikipedia says.
NFS is used as a file system when two or more instances need access to the same file system. E.g. SQL clusters, VM clusters, Docker Swarm, etc…
In this post, I’ll describe a very quick install on a server and show you how to mount that on another CentOS box.

Server Install

On the server (in my case 192.168.1.91) I’ll install the NFS server, start it, make sure it starts at boot and then I’ll allow the firewall to accept the NFS clients. If you have SELinux enabled, it’s automatically configured.

yum -y install nfs-utils
systemctl start nfs-server
systemctl enable nfs-server
firewall-cmd --permanent --zone=public --add-service nfs
firewall-cmd --reload

Let’s create an empty directory, configure the permissions and create the NFS share.

mkdir /nfs
chown nfsnobody:nfsnobody /nfs
chmod 755 /nfs

We have to tell the NFS server about the share. Execute this line that will add the correct line in /etc/exports. That’s where the NFS server expects its shares defined.

echo "/nfs    *(rw,sync,no_root_squash,no_subtree_check)" >> /etc/exports

The * means that all IPs can have access to this share. Do man 5 exports to see all available options. We have to tell the NFS server to export the share now.

exportfs -a

Check the exported share.

exportfs -s
/nfs  *(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)

Client install

On the client, we’ll have to install the NFS client. It’s the same package.

yum -y install nfs-utils

There is no need to start any service or change any firewall settings.
Let’s mount the share. I’ll mount it under /mnt/nfs which is a new directory on the client.

mkdir -p /mnt/nfs
mount 192.168.1.91:/nfs /mnt/nfs

If you create a file on the share now and go back to the server you’ll see that the file is there.

echo "NFS test" > /mnt/nfs/nfs.txt

In order to mount this share anytime you boot the client, you’ll have to add it to /etc/fstab so it mounts on boot.

echo "192.168.1.91:/nfs       /mnt/nfs    nfs     defaults 0 0" >> /etc/fstab
0 comment
0

Related Articles

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More