Donnerstag, 18. April 2013

NFS on RedHat based Servers

How to mount a folder on a RedHat based server (client) from an other server (server).

This short blog describe how you can mount a folder from an other unix server with NFS. After the mount process you got read/write access to the mounted folder.

Prerequisite
  • nfs-utils
  • rpcbind (yum install nfs-utils rpcbind)

1. Create a user on both servers with the same UID and Group

To access the mounted directory later on you have to create a user with the same UID on both server, otherwise you can't write to the mounted folder.

useradd testuser -u 1200

2. Settings for the "server" Server

Open "/etc/exports with your favourite text editor from the server.  For each directory you'd like to give access, you have to add the following line. In this example we share the "testFolder" for the client with the IP 10.2.3.4. You can use hostnames, IP's, netmasks and wildcards to identify the client
/tmp/testFolder 10.2.3.4(rw,sync)
After you added the mount points you have to reload your configuration
exportfs -ar
Now we have to start the services 
service rpcbind start
service nfs start
service nfslock start
If you like to have your services started after a reboot, you have to add them to the "chkconfig"
chkconfig --level 2345 rpcbind on
chkconfig --level 2345 nfs on
chkconfig --level 2345 nfslock on

3. Settings for the "client" server

On the client you need to start the following two services. 
service rpcbind start
service nfslock start
chkconfig --level 2345 rpcbind on
chkconfig --level 2345 nfslock on
Now you need to create a folder as a mount point and then mount the NFS Server
mkdir /tmp/myMountFolder
mount -o rw -t nfs 10.0.0.122:/tmp/testFolder /tmp/myMountFolder/
You can easy unmount the mount point
umount /tmp/myMountFolder/
If you like to have your mounts created at startup you can edit "/etc/fstab"
10.0.0.122:/tmp/testFolder   /tmp/myMountFolder/  nfs rsize=8192,wsize=8192,timeo=14,intr 0 0