Tuesday, April 19, 2011

NFS Setup on Home Fileserver: Linux to Linux File Sharing

1. Install NFS Server and Client Software

Using the command line (terminal):
me@myhost$ sudo apt-get install nfs-common nfs-kernel-server
or use the Synaptic pacage manager to install the two packages listed on your home file-server. The client machine only needs the "nfs-common" package, which contains the NFS client software. Not completely obvious to a new-comer, but now you know there is no "nfs-client" package.

2. Give Your Computers Fixed IP Addresses

The simplest way to do refer to your computers in a home or SOHO LAN is to use fixed IP addresses. This eliminates an extra step of matching computer names to IP addresses. You can give you system a fixed IP address, even if you use DHCP on your Linksys or other type of router. I give a description how to do this in a separate Linux Fixed IP Address page. Put all the fixed IP addresses you are using in the /etc/hosts file per the example in the default file. I show an example /etc/hosts file on my Virtual Hosts page.


3. Modify the /etc/exports File

The real trick to making files available for NFS sharing is modifying the /etc/exports file. You can do this with a GUI tool by typing sudo gedit /etc/exports in a terminal and supplying the super-user password. The formatted text below is the complete content of a working file. There is one line for each share. I am sharing all the files from a single user's home directory, but that is not necessary. Following the file (folder) to be shared, there is one entry for each client describing the conditions of the mount. For example, rw means both "read" and "write" permissions are given. I added the "no_subtree_check simply to get rid of a notification message. I can't explain why it's there. It works without it. Note there are commas inside the parentheses, but not outside them. There is no whitespace within the parentheses or between them and the IP address. Including spaces will generate an error. The hash marks (pound signs) are for comments.
***This makes your files mountable in an insecure (writeable) fashion. Do not use for sensitive data.***
# /etc/exports: the access control list for filesystems which may be exported to NFS clients.
# See exports(5).
#
# The user's name (SERVER_USER) on the FILE-SERVER needs to be filled in.
# Listed are CLIENT machines fixed IP addresses (edit and add/subtract as needed).
# This file is sensitive to whitespace within each entry
#
/home/USER_NAME/Documents   192.168.1.13(rw,no_subtree_check) 192.168.1.21(rw,no_subtree_check)
/home/USER_NAME/Downloads   192.168.1.13(rw,no_subtree_check) 192.168.1.21(rw,no_subtree_check)
/home/USER_NAME/Music       192.168.1.13(rw,no_subtree_check) 192.168.1.21(rw,no_subtree_check)
/home/USER_NAME/Pictures    192.168.1.13(rw,no_subtree_check) 192.168.1.21(rw,no_subtree_check)
/home/USER_NAME/Templates   192.168.1.13(rw,no_subtree_check) 192.168.1.21(rw,no_subtree_check)
/home/USER_NAME/Videos      192.168.1.13(rw,no_subtree_check) 192.168.1.21(rw,no_subtree_check)

4. Creating Mount Points on the Client Machines

In the home directory of your client machines you MAY need to create folders (a.k.a. mount points) so your computer knows where to put the locations of all the files you have access to on the fileserver. I happen to use most of the same name in both places, but that is not necessary. You may be happy with the default folders that Ubuntu supplies. In my case, I add a folder "Voice" for spoken word recordings and "public_hmtl" for website development.

5. Mounting the Shares from Client Machines

Sure, there is a way you can have shares automatically mounted via NFS, but for a home network it may be more trouble than it's worth. I have read how you can also go into a permanent "hang" if you have it set on your client but your server isn't on at that time. Let me know if you find an easy way. In the meantime, I click on a terminal shortcut that I put in my top panel and type one command when I need access to the files on the server. Alternatively, you can double-click the file and choose "Run In Terminal". The folders stay mounted until one of the comptuers is turned off. Here is the command I use.
me@myhost$ ./mountem.sh
Then I need to enter the super-user password once. The "mounting" of all shares takes about 1 second. No files are actually transferred to the client. Below is the content of the mountem.sh script, with both the server and client usernames left for you to fill in. You would need to edit the fixed IP in this script, which is the IP address of the SERVER. It is a plain text file that should be kept in your home directory and made executeable [chmod u+x mountem.sh].
#
# File to mount NFS directories (folders) for WRITEABLE access.
# To use, update the FIXED IP of server and both USERS.
#
sudo mount 192.168.1.19:/home/SERVER_USER/Documents   /home/CLIENT_USER/Documents -o rw
sudo mount 192.168.1.19:/home/SERVER_USER/Downloads   /home/CLIENT_USER/Downloads -o rw
sudo mount 192.168.1.19:/home/SERVER_USER/Music       /home/CLIENT_USER/Music -o rw
sudo mount 192.168.1.19:/home/SERVER_USER/Pictures    /home/CLIENT_USER/Pictures -o rw
sudo mount 192.168.1.19:/home/SERVER_USER/Templates   /home/CLIENT_USER/Templates -o rw
sudo mount 192.168.1.19:/home/SERVER_USER/Videos      /home/CLIENT_USER/Videos -o rw
Once the software is installed and the two files listed above are set up, there is only about 5 seconds worth of effort each time you want to access your files. They are unreachable in the meantime, in the case you do want to keep others from accessing them.

0 komentar:

Post a Comment