Home » Random Goodies » NFS Server & Client Setup Ubuntu or CentOS

NFS Server & Client Setup Ubuntu or CentOS

What easier way to share data across multiple operating systems than using NFS. In this article I will be going over setting up NFS servers on both CentOS and Ubuntu, then the remote mounts using options found to be optimal in most production environments.

Now for some action…

On Ubuntu things are rather smooth, first the pre-reqs:

[email protected]:~# sudo apt-get install -y portmap nfs-kernel-server

Now to whitelist client connections. You need to know the following:

File: /etc/exports
Client IP: 2.2.2.2
Bitmask: 32
Local Directory: /home6/backups

Open the file and add the following:

/home6/backups 2.2.2.2/32(rw,sync,no_root_squash,no_subtree_check)

Now restart the daemon:

[email protected]:~# service nfs-kernel-server restart
* Stopping NFS kernel daemon [ OK ]
* Unexporting directories for NFS kernel daemon... [ OK ]
* Exporting directories for NFS kernel daemon... [ OK ]
* Starting NFS kernel daemon [ OK ]
[email protected]:~#

To check your changes took affect properly:

[email protected]:~# exportfs
/home6/backups
2.2.2.2/32
[email protected]:~#

The install for CentOS is rather similar, and simple:

[email protected] [~]# yum install -y nfs-utils nfs-utils-lib

Same configuration file and mount options work. We will assume as above:

File: /etc/exports
Client IP: 2.2.2.2
Bitmask: 32
Local Directory: /home6/backups
Open the file and add the following:

/home6/backups 2.2.2.2/32(rw,sync,no_root_squash,no_subtree_check)

Now restart the daemon:
[email protected] [~]# service rpcbind restart && service nfs restart

And that’s pretty much it. Note, when modifying /etc/exports on either of the two, you will only need to:

# service nfs reload

To get some stats on the client about your new NFS mount, here are a couple examples:

Run on client or server:
[email protected] [~]# nfsiostat

1.1.1.1:/home6/backups mounted on /backup:

op/s rpc bklog
0.02 0.00
read: ops/s kB/s kB/op retrans avg RTT (ms) avg exe (ms)
0.000 0.000 0.000 0 (0.0%) 0.000 0.000
write: ops/s kB/s kB/op retrans avg RTT (ms) avg exe (ms)
0.000 0.000 0.000 0 (0.0%) 0.000 0.000
[email protected] [~]#

Run on client:
[email protected] [~]# nfsstat
Server rpc stats:
calls badcalls badclnt badauth xdrcall
0 0 0 0 0

Client rpc stats:
calls retrans authrefrsh
6114972 0 6115172

Client nfs v3:
null getattr setattr lookup access readlink
0 0% 607728 9% 1774069 29% 1529123 25% 499594 8% 305 0%
read write create mkdir symlink mknod
21 0% 515576 8% 433780 7% 97065 1% 66 0% 1 0%
remove rmdir rename link readdir readdirplus
76869 1% 2090 0% 325788 5% 0 0% 4557 0% 238347 3%
fsstat fsinfo pathconf commit
44 0% 8 0% 0 0% 10055 0%

[email protected] [~]#

Enjoy!