Setting up and using NFS on Ubuntu
April 10th, 2008Network File System, NFS, has been around since Noah first networked his ark.
Setting up and using NFS on Ubuntu is surprisingly easy. i9000 Networks needed a slightly revised backup solution in one of it’s sites.
Obviously you’ll need two or more servers. One I’ll refer to as the server which will host the backups and the second/subsequent servers, which are the clients, ie. the live servers that need backing up.
Here’s how I did it.
As root, on the backup server,
apt-get install nfs-kernel-server nfs-common portmap
Make sure you tell portmap not to bind to the loopback address, otherwise nothing will be able to connect.
You may need to restart portmap
/etc/init.d/portmap restart
Next, we’ll configure the directory to export. In my particular example, I created a folder called /home/backups
mkdir /home/backups
Make sure you have sufficient space on the drive to host all your backups and versions.
nano /etc/exports
My /etc/exports has a single line configuration
/home/backups 192.168.3.0/27(rw,no_root_squash,async)
This says, share out the /home/backups folder to that subnet, with all those options in brackets, for example read & write access. You could be security conscious and only allow access from one client/ip address if you wish. Make sure you change it to your subnet.
Now restart the NFS server
/etc/init.d/nfs-kernel-server restart
Your server setup is complete. Now we need to sort out the client(s).
On your clients, install the nfs-common and portmap
apt-get install portmap nfs-common
Thats it! Well, nearly, you can either choose to mount the NFS share from the server manually or automatically.
Either way, you’ll need a directory creating,
mkdir /mnt/backups
To manually mount the directory
mount /<backup-server>/backups /mnt/backups
To automatically mount the directory on the client at startup you need to edit /etc/fstab
nano /etc/fstab
Slam this line at the bottom
<backup-server>:/home/backups /mnt/backups nfs rsize=8192,wsize=8192,timeo=14,intr
Of course <backup-server> could be an IP address or a server name, or a dns name.
Then reload it,
mount -a
Note: If you’re backing up over the internet it’s wise to do it over an SSH tunnel, there are other examples on how to do this.
Note 2: If you’re backing up internally, but via a firewall, you’ll need to have ports 32771, 111 and 2049 open.
Now you just need to devise a way of maintaining backups.
Edit: Try my article on Using rsync to maintain backups on Linux
| Bookmark it del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Propeller | Yahoo |
Was this post useful to you? Let me know, buy me a beer!
Alternatively, if you're feeling impecunious, you may like to subscribe to my RSS feed, or see other articles in the Linux category.