[KVM Ubuntu] Configuring NFS Server and NFS Client sides

RomanRoman Moderator
edited September 5 in KVM Based Servers
Introduction

NFS (Network File System) is used for sharing files and folders between Linux servers. It allows you to mount your local file systems over a network and remote hosts to interact with them as they are mounted locally on the same server. In this tutorial you will learn how to set up NFS on KVM based Linux server.

Installing and Configuring

1. First you have to configure NFS server

1.1. Install NFS packages with the following commands:
apt-get update
apt-get install nfs-kernel-server

1.2 Start the service and check it's status :
service nfs-kernel-server start
service nfs-kernel-server status

1.3 We would recommend to make configuration so that this service would start after reboot
nano /etc/rc.local

Add this line at the bottom:
/etc/init.d/nfs-kernel-server restart

1.4 Create a directory you want to share and edit the follow file to set rules for sharing:
mkdir /home/test
nano /etc/exports

Paste this line, which sets the specific client to be able to access the directory, with certain rules:
/home/test       NFS_client_IP_or_hostname(rw,sync,no_root_squash,no_subtree_check)
Note.
Here are some possible rules you can configure:
rw - the filesystem is writable;
ro - the filesystem is exported read-only; this is the default;
root_squash - map root UID/GID to anonymous UID/GID (nobody/nogroup); this is the default;
all_squash - map all UIDs/GIDs to anonymous UID/GID (nobody/nogroup);
no_root_squash - do not map root (nor any other) UID/GID to anonymous UID/GID (nobody/nogroup);
sync - reply clients after data have been stored to stable storage; this is the default;
async - reply clients before data have been stored to stable storage; improves performance, but should only be used on ro filesystems

Export directory(-ies) with command:
exportfs -a

2. Steps to configure NFS Client side:
apt-get update
apt-get install nfs-common

2.1. Create a directory and mount the remotely shared directory on it:
mkdir -p /nfs/home
mount NFS_server_IP_or_hostname:/home/test /nfs/home

NFS configuration is done. You should now be able to see mounted directory:
df -h

Results should be like this:
Filesystem            Size  Used Avail Use% Mounted on
/dev/simfs            160G  754M  160G   1% /
devtmpfs              2.0G     0  2.0G   0% /dev
tmpfs                 2.0G     0  2.0G   0% /dev/shm
tmpfs                 2.0G  9.2M  2.0G   1% /run
tmpfs                 5.0M     0  5.0M   0% /run/lock
tmpfs                 2.0G     0  2.0G   0% /sys/fs/cgroup
none                  2.0G     0  2.0G   0% /run/shm
NFS_server_IP_or_hostname:/home/test  160G  738M  160G   1% /nfs/home/

Tagged:
Sign In or Register to comment.