Showing posts with label nfs. Show all posts
Showing posts with label nfs. Show all posts

Tuesday, August 13, 2019

Installing NFS server and client on ubuntu 18.04

Assuming the nfs server's ip address is 10.20.30.40 and the client is 10.20.30.50.

NFS Server


Install nfs-kernel-server
$ sudo apt update; sudo apt install nfs-kernel-server -y

Start nfs service
$ sudo systemctl start nfs-server

Create the export directory
$ sudo mkdir /sharing

Change permission and ownership of export directory
$ sudo chown nobody.nogroup /sharing
$ sudo chmod 777 /sharing

Allow the export directory to be accessed by client. The options are rw for read write, sync for server to write any change to disk from applying and no_subtree_check to prevent subtree checking
$ echo "/sharing 10.20.30.50(rw,sync,no_subtree_check)" | sudo tee -a /etc/exports

Export the above setting to NFS table of exports
$ sudo exportfs -a

Check if the NFS table of exports has been updated
$ sudo exportfs 
/sharing           10.20.30.50

NFS Client

Install nfs-common
$ sudo apt update; sudo apt install nfs-common

Mount the nfs export directory
$ sudo mount 10.20.30.40:/sharing /mnt

Check if client can write to the export directory and the file written, appeared in the server
$ mount | grep nfs
$ touch /mnt/newfile
$ rm /mnt/newfile

To make the mount point permanent, append it to /etc/fstab
$ echo "10.20.30.40:/sharing /mnt nfs4 defaults 0 0" | sudo tee -a /etc/fstab

Test mount from /etc/fstab
$ sudo umount /mnt; sudo mount -a



Tuesday, June 11, 2013

Unmounting stuck nfs mounts

This usually happened when the nfs server is down, you cannot umount the nfs mount, because the system will say "not found or server not reachable"

$ sudo umount /opt/logs/production

umount.nfs: nfs.local:/var/lib/backup: not found / mounted or server not reachable

umount.nfs: nfs.local:/var/lib/backup: not found / mounted or server not reachable

To fix this, you need to force mount it with lazy flag:

$ sudo umount -f -l /opt/logs/production

where -f is to do force unmount, and -l is for lazy unmounting. From man:
"Lazy  unmount.  Detach  the  filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore."

That's all folks.

Monday, August 25, 2008

NFS quick howto for centos 5

To use nfs successfully, you have to configure the server and the client. In this example, the client is 192.168.0.3 and the server is 192.168.0.1. The folder to be shared is /home/sharing, and to be mounted to /mnt on the client

On the server

  1. Make directory that you want to use.
    • # mkdir /home/sharing
  2. Edit /etc/exports, insert the client machine's ip
    • # vi /etc/exports
      • Add this line:
        • /home/sharing 192.168.0.3/255.255.255.255(rw,sync)
      • Save
  3. Edit /etc/hosts.allow
    • # vi /etc/hosts.allow
      • Add this line:
        • portmap: 192.168.0.0/255.255.255.0
      • Save
  4. Start nfs and portmap
    • # /etc/init.d /nfs start
    • # /etc/init.d/portmap start
On the client
  1. Start portmap
    • # /etc/init.d/portmap start
  2. Mount the nfs folder
    • # mount 192.168.0.1:/home/sharing /mnt
  3. Check /var/log/messages for any error that might occur
    • # tailf /var/log/messages
  4. Use mount to check if the folder is mounted properly
    • # mount
      • This should be the output:
        • 192.168.0.1:/home/sharing on /mnt type nfs (rw,addr=192.168.0.1)
  5. Edit /etc/fstab to mount the shared folder on boot
    • # vi /etc/fstab
      • Add this line
        • 192.168.0.1:/mnt/sdb1/backup /mnt nfs rw,hard,intr 0 0
      • Save
You can use 'man exports' to see the options available for /etc/exports