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

8 comments:

  1. Doesn't work. I started with a full installation, then used yum to get nfs-utils and nfs-utils-lib. After I follow these instructions, the NFS Daemon always comes up as [Failed].

    ReplyDelete
  2. I had trouble starting the nfs service before portmap. When I started portmap first, then the nfs service started with no errors.

    ReplyDelete
  3. NSF ver 2 and 3 require portmap service to be running before nfs service can start. If you use NFS ver 4, you don't have to worry about it, because it is not used.

    ReplyDelete
  4. # Server-side:
    yum install -y nfs-utils nfs-utils-lib
    echo "/home/software 192.168.11.141(rw,sync)" >> /etc/exports
    echo "/home/scripts 192.168.11.141(rw,sync)" >> /etc/exports
    echo "portmap: 192.168.11.0/255.255.255.0" >> /etc/hosts.allow
    exportfs -a -v
    for i in nfs portmap; do chkconfig $i on; done
    for i in tcp udp; do iptables -A INPUT -p $i -m $i -m multiport --dports 1110,2049 -j ACCEPT; done
    iptables-save > /etc/sysconfig/iptables
    service portmap start
    service nfs start
    #
    # Client-side:
    service portmap start
    chkconfig portmap on
    cd /
    mkdir fx6-share
    mount 192.168.11.64:/home/software /fx6-share
    # Make it stick:
    echo "192.168.11.64:/home/software /fx6-share nfs defaults 0 0" >> /etc/fstab
    echo "192.168.11.64:/home/scripts /fx6-scripts nfs defaults 0 0" >> /etc/fstab
    mount -a
    # EOF

    ReplyDelete
  5. This is an ultimate post. I just tried the steps only one time. And my nfs is well set. But, only one question. --> From the client machine can't I mount the nfs other than /mnt ? I want to mount it as ther server to /home/sharing. Possible ?

    And what option shall I use to get permission from the client to create or delete file in /mnt ?

    spisteel@gmail.com

    ReplyDelete
  6. Awesome, this worked great - no fuss - no nonsense - it just works - thank-you very much!

    One thing to note: I was getting READONLY mode until I added no_root_squash to the arguments in /etc/exports on the Server.

    ReplyDelete
  7. Got some strange problems while mounting nfs on a ubuntu client machine (mount throw message about wrong filesystem, option, superblock etc). Installing nfs-common solved it. Hope that it will be helpful to someone.

    ReplyDelete
  8. Got some strange problems while mounting nfs on a ubuntu client machine (mount throw message about wrong filesystem, option, superblock etc). Installing nfs-common solved it. Hope that it will be helpful to someone.

    ReplyDelete