Was trying to mount a NFS shared folder on CentOS 6.4 from CentOS 5.9 and found a really tricky problem. I’ve added the /etc/fstab
entry, but once I ran mount /my/folder
it stuck for 2-3 minutes and came back saying
mount.nfs: Input/output error
Things I’ve Tried
This is all the things I’ve tried with no success:
- Ensured network connection was ok. I checked the firewall / iptables and made sure the client machine can connect to NFS server
- Checked my
/etc/hosts
file, ensured no dodgy entries
- Double checked
/etc/exports
and ran exportfs -r
on the NFS server
- Ran
showmount -e [host_ip]
to check the NFS server really does advertise the shared folders
- Ran
rpcinfo -p [host_ip]
to check the version and supporting services are available
- Rebooting the server many times
Solution
Thanks to , the solution was to add nolock
option to the /etc/fstab
file.
10.0.10.10:/my/folder /mnt/nfs/my/folder nfs nolock 0 0
CentOS manual is pretty vague as well on what this option really does, but oh well it seems to do the job for time being
nolock — Disables file locking. This setting is occasionally required when connecting to older NFS servers.
Scenario
We are building a second web server with a hope of installing a load balancer soon. We came into a problem where we have to synchronize the file contents between multiple servers. The solution we’re opting is to install and mount a shared network folder (NFS) visible from both web servers. The shared folder lives on its own server (aka file system server).
It is assumed:
- The file system server host (Master) is 12.0.10.10
- The client is 12.0.20.20
- The folder to be shared on master is /var/www/vhosts
- The folder will be mounted to /mnt/nfs/var/www/vhosts on client
Creating a NFS Share on the File System Server
Perform these steps on the file system server (aka “Master”):
- Install nfs-utils and nfs-utils-lib package using yum:
yum install nfs-utils nfs-utils-lib
Use yum list installed
to check if the packages are already installed
- Turn on nfs service so it automatically starts on boot
chkconfig nfs on
Use chkconfig --list
to check status of all services
- Start rpcbind and nfs service
service rpcbind start
service nfs start
- Edit /etc/exports file and add following line at the end
/var/www/vhosts 12.0.20.20(rw,sync,no_root_squash,no_subtree_check)
See here for explanation of the options
- Run following command to apply the changes
exportfs -a
Mounting it on the Client
Following steps will mount the network folder permanently (folder will automatically re-mount on server reboot). Perform this on the client server:
- Similar to server, ensure nfs-utils and nfs-utils-lib are installed
yum install nfs-utils nfs-utils-lib
- Create the directory that will hold the mount (mount point)
mkdir -p /mnt/nfs/var/www/vhosts
- Edit /etc/fstab file and append following line
12.0.10.10:/var/www/vhosts /mnt/nfs/var/www/vhosts nfs defaults 0 0
- Run
mount /mnt/nfs/var/www/vhosts
to apply the mounting. Check if the mounting is successful using df -h
OS User on Master and Client
To ensure file system operations are consistent, consider propagating same OS user setup between the master and client. Note that although same username exists on both master and client they don’t necessarily have the same UID.
- Checking uid and group of user jim:
$ id jim
uid=506(jim) gid=505(xyzco) groups=505(xyzco)
(jim has uid 506 and belongs to group xyzco)
- Adding a new user jim with uid 506
useradd -u 506 jim
- Adding jim to the group xyzco
usermod -G xyzco jim
- Setting / resetting password for jim
passwd jim
Thanks To
Additional Reading
Gerry's software development journey of trial, errors and re-trials