Home » Categories » Multiple Categories |
How To Set Up an NFS Mount on Ubuntu 12.04 |
Article Number: 169 | Rating: Unrated | Last Updated: Sun, Jan 5, 2014 at 9:04 PM
|
About NFS (Network File System) MountsNFS mounts work to share a directory between several virtual servers. This has the advantage of saving disk space, as the home directory is only kept on one virtual private server, and others can connect to it over the network. When setting up mounts, NFS is most effective for permanent fixtures that should always be accessible.SetupAn NFS mount is set up between at least two virtual servers. The machine hosting the shared network is called the server, while the ones that connect to it are called ‘clients’.This tutorial requires 2 servers: one acting as the server and one as the client. We will set up the server machine first, followed by the client. The following IP addresses will refer to each one: Master: 12.34.56.789 Client: 12.33.44.555 The system should be set up as root. You can access the root user by typing sudo su- Setting Up the NFS ServerDownload the Required SoftwareStart off by using apt-get to install the nfs programs. apt-get install nfs-kernel-server portmap Export the Shared DirectoryThe next step is to decide which directory we want to share with the client server. The chosen directory should then be added to the /etc/exports file, which specifies both the directory to be shared and the details of how it is shared.Suppose we wanted to share two directories: /home and /var/nfs. Because the /var/nfs/ does not exist, we need to do two things before we can export it. First, we need to create the directory itself: mkdir /var/nfs/Second, we should change the ownership of the directory to the user, nobody and the group, no group. These represent the default user through which clients can access a directory shared through NFS. Go ahead and chown the directory: chown nobody:nogroup /var/nfsAfter completing those steps, it’s time to export the directories to the other server: nano /etc/exportsAdd the following lines to the bottom of the file, sharing both directories with the client: /home 12.33.44.555(rw,sync,no_root_squash,no_subtree_check) /var/nfs 12.33.44.555(rw,sync,no_subtree_check)These settings accomplish several tasks:
exportfs -a Setting Up the NFS ClientDownload the Required SoftwareStart off by using apt-get to install the nfs programs. apt-get install nfs-common portmap Step Two—Mount the DirectoriesOnce the programs have been downloaded to the the client server, create the directories that will contain the NFS shared filesmkdir -p /mnt/nfs/home mkdir -p /mnt/nfs/var/nfsThen go ahead and mount them mount 12.34.56.789:/home /mnt/nfs/home mount 12.34.56.789:/var/nfs /mnt/nfs/var/nfsYou can use the df -h command to check that the directories have been mounted. You will see them last on the list. df -h Filesystem Size Used Avail Use% Mounted on /dev/sda 20G 948M 19G 5% / udev 119M 4.0K 119M 1% /dev tmpfs 49M 208K 49M 1% /run none 5.0M 0 5.0M 0% /run/lock none 122M 0 122M 0% /run/shm 12.34.56.789:/home 20G 948M 19G 5% /mnt/nfs/home 12.34.56.789:/var/nfs 20G 948M 19G 5% /mnt/nfs/var/nfsAdditionally, use the mount command to see the entire list of mounted file systems. mountYour list should look something like this: /dev/sda on / type ext4 (rw,errors=remount-ro,barrier=0) [DOROOT] proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) none on /sys/fs/fuse/connections type fusectl (rw) none on /sys/kernel/debug type debugfs (rw) none on /sys/kernel/security type securityfs (rw) udev on /dev type devtmpfs (rw,mode=0755) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755) none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880) none on /run/shm type tmpfs (rw,nosuid,nodev) rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw) 12.34.56.789:/home on /mnt/nfs/home type nfs (rw,vers=4,addr= 12.34.56.789,clientaddr=12.33.44.555) 12.34.56.789:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,vers=4,addr=12.34.56.78,clientaddr=12.33.44.555) Testing the NFS MountOnce you have successfully mounted your NFS directories, you can test that they work by creating files on the Client and checking their availability on the Server.Create a file in each directory to try it out: touch /mnt/nfs/home/example /mnt/nfs/var/nfs/exampleYou should then be able to find the files on the Server in the /home and /var/nfs directories. ls /home ls /var/nfs/You can ensure that the mount is always active by adding the directories to the fstab file on the client. This will ensure that the mounts start up after the server reboots. nano /etc/fstab 12.34.56.789:/home /mnt/nfs/home nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0 12.34.56.789:/var/nfs /mnt/nfs/var/nfs nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0You can learn more about the fstab options by typing in: man nfsAny subsequent restarts will include the NFS mount—although the mount may take a minute to load after the reboot You can check the mounted directories with the two earlier commands: df -h mount Removing the NFS MountShould you decide to remove a directory, you can unmount it using the umount command:cd
sudo umount /directory name You can see that the mounts were removed by then looking at the filesystem again.
df -hYou should find your selected mounted directory gone. |
Attachments
There are no attachments for this article.
|
How To Migrate a MySQL Database Between Two Servers
Viewed 2883 times since Thu, Dec 26, 2013
How To Install and Secure phpMyAdmin on Ubuntu 12.04
Viewed 2679 times since Mon, Dec 23, 2013
How To Use ps, kill, and nice to Manage Processes in Linux
Viewed 2718 times since Thu, Dec 26, 2013
Geddy.JS: A No-Brainer MVC Node.js Framework
Viewed 3236 times since Sun, Dec 29, 2013
How To Install and Use Memcache on Ubuntu 12.04
Viewed 3528 times since Tue, Dec 24, 2013
How To Install Node.js with NVM (Node Version Manager) on Server
Viewed 3881 times since Sun, Dec 29, 2013
How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu
Viewed 6628 times since Thu, Jan 2, 2014
How To Configure and Maintain Ghost from the Command Line
Viewed 6579 times since Sun, Dec 29, 2013
How To Create a New User and Grant Permissions in MySQL
Viewed 3284 times since Thu, Dec 26, 2013
How To Install and Configure Django with Postgres, Nginx, and Gunicorn
Viewed 4252 times since Fri, Jan 3, 2014
|