Upload
maxus-lord
View
62
Download
1
Embed Size (px)
Citation preview
PricingFeaturesCustomersHelp & Community
Sign Up LoginHelp & Community
Articles & Tutorials
Questions
Chat
Blog
Try this tutorialon an SSD cloud server.
Includes 512MB RAM, 20GB SSD Disk, and 1TB Transfer for <br /> $5/mo! Learn more.Related Articles
Linux Basics
How to Set Up vsftpd on CentOS 6How to Set Up vsftpd on Ubuntu 12.04How to Add and Delete Users on Ubuntu 12.04 and CentOS 6Initial Server Setup with Ubuntu 12.04How to Install Linux, Apache, MySQL, PHP (LAMP) stack on CentOS 6
Ubuntu
How to Create a SSL Certificate on Apache for Ubuntu 12.04How to Install Linux, Apache, MySQL, PHP (LAMP) stack on UbuntuHow to Install Git on Ubuntu 12.04How to Set Up Apache Virtual Hosts on Ubuntu 12.04 LTSHow to Install Ruby on Rails on Ubuntu 12.04 LTS (Precise Pangolin) with RVM
How to Set Up an NFS Mount on Ubuntu 12.04
Tweet 3 5
submit
About NFS (Network File System) Mounts
NFS mounts work to share a directory between several virtual servers. This has the advantage of saving disk space, as the homedirectory is only kept on one virtual private server, and others can connect to it over the network. When setting up mounts, NFS ismost effective for permanent fixtures that should always be accessible.
Setup
Like 4
ShareShare
How to Set Up an NFS Mount on Ubuntu 12.04 | DigitalOcean https://www.digitalocean.com/community/articles/how-to-set-up-an-n...
1 de 8 05/08/2013 20:41
An NFS mount is set up between at least two virtual servers. The machine hosting the shared network is called the server, whilethe 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 bythe client. The following IP addresses will refer to each one:
Master: 12.34.56.789Client: 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 Server
Step One—Download the Required Software
Start off by using apt-get to install the nfs programs.
apt-get install nfs-kernel-server portmap
Step Two—Export the Shared Directory
The next step is to decide which directory we want to share with the client server. The chosen directory should then be added tothe /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 defaultuser through which clients can access a directory shared through NFS.
Go ahead and chown the directory:
chown nobody:nogroup /var/nfs
After completing those steps, it’s time to export the directories to the other VPS:
nano /etc/exports
Add 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:
rw: This option allows the client server to both read and write within the shared directory
sync: Sync confirms requests to the shared directory only once the changes have been committed.
no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a largerfilesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling thesubtree check may increase the reliability of NFS, but reduce security.
How to Set Up an NFS Mount on Ubuntu 12.04 | DigitalOcean https://www.digitalocean.com/community/articles/how-to-set-up-an-n...
2 de 8 05/08/2013 20:41
no_root_squash: This phrase allows root to connect to the designated directory
Once you have entered in the settings for each directory, run the following command to export them:
exportfs -a
Setting Up the NFS Client
Step One—Download the Required Software
Start off by using apt-get to install the nfs programs.
apt-get install nfs-common portmap
Step Two—Mount the Directories
Once the programs have been downloaded to the the client server, create the directories that will contain the NFS shared files
mkdir -p /mnt/nfs/homemkdir -p /mnt/nfs/var/nfs
Then go ahead and mount them
mount 12.34.56.789:/home /mnt/nfs/homemount 12.34.56.789:/var/nfs /mnt/nfs/var/nfs
You 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% /devtmpfs 49M 208K 49M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 122M 0 122M 0% /run/shm12.34.56.789:/home 20G 948M 19G 5% /mnt/nfs/home12.34.56.789:/var/nfs 20G 948M 19G 5% /mnt/nfs/var/nfs
Additionally, use the mount command to see the entire list of mounted file systems.
mount
Your 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)
How to Set Up an NFS Mount on Ubuntu 12.04 | DigitalOcean https://www.digitalocean.com/community/articles/how-to-set-up-an-n...
3 de 8 05/08/2013 20:41
Testing the NFS Mount
Once you have successfully mounted your NFS directories, you can test that they work by creating files on the Client andchecking their availability on the Server.
Create a file in each directory to try it out:
touch /mnt/nfs/home/example /mnt/nfs/var/nfs/example
You 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 themounts 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 012.34.56.789:/var/nfs /mnt/nfs/var/nfs nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
You can learn more about the fstab options by typing in:
man nfs
Any subsequent restarts will include the NFS mount—although the mount may take a minute to load after the reboot You cancheck the mounted directories with the two earlier commands:
df -h
mount
Removing the NFS Mount
Should you decide to remove a directory, you can unmount it using the umount command:
cdsudo umount /directory name
You can see that the mounts were removed by then looking at the filesystem again.
df -h
You should find your selected mounted directory gone.
Try this tutorial on an SSD cloud server.
Includes 512MB RAM, 20GB SSD Disk, and 1TB Transfer for $5/mo! Learn more.
Comments
pc-raed818
How to Set Up an NFS Mount on Ubuntu 12.04 | DigitalOcean https://www.digitalocean.com/community/articles/how-to-set-up-an-n...
4 de 8 05/08/2013 20:41
great tutorial , thank you so much
Posted March 2nd, 2013 20:45
robert.simpson.lists
mount hangs when I try to mount the fs on the client.
Posted March 16th, 2013 14:42
robert.simpson.lists
Also portmap has been renamed to rpcbind (and I think it's installed when you install nfs-common).
Posted March 16th, 2013 14:44
jakub
yep, mount hangs… :/
Posted April 29th, 2013 13:24
jakub
This is missing in tutorial:server$ sudo service nfs-kernel-server startclient$ sudo chmod og+w /mnt/nfs/home
now it mounts… :P
Posted April 29th, 2013 13:35
scriptfang
once in a blue moon I find a really good tutorial.
Yours is one of them. Thank you. Really thankyou.
I am and old user of nfs. but sometimes I need to refresh my memory with some parameters. That is why I found you.
Keep the good work.
Posted May 16th, 2013 15:22
How to Set Up an NFS Mount on Ubuntu 12.04 | DigitalOcean https://www.digitalocean.com/community/articles/how-to-set-up-an-n...
5 de 8 05/08/2013 20:41
Kamal Nasser
@scriptfang: Thanks for the feedback! :]
Posted May 16th, 2013 18:00
kourtzis
:-(On the server:$ service nfs-kernel-server startFATAL: Could not load /lib/modules/3.8.0-19-generic/modules.dep: No such file or directory* Not starting NFS kernel daemon: no support in current kernel.
Posted May 26th, 2013 19:12
Kamal Nasser
@kourtzis What's the output of 'uname -rsi'?
Posted May 27th, 2013 08:16
djedge2008
Tutorial worked like a charm, but when using rsync to move files from one server to another, the files aren't removed from thesource server... for example: rsync -avh --remove-source-files --progress /mnt/nfs/xfer/series /srv/fs1/work/iso
I'd been using cifs for this but it was painfully slow on linux to linux ... NFS is much faster.
I've got the nfs mount as follows in fstab:
192.168.0.50:/srv/xfer /mnt/nfs/xfer nfs auto,noatime,nolock,bg,nfsvers=3,rsize=32768,wsize=32768,intr,tcp,actimeo=1800 0 0
the export from the nfs server is:
/srv/xfer 192.168.0.42(rw,sync,no_root_squash,no_subtree_check)
all folders and files within /srv/xfer are owned by nobody with nogroup
Any ideas?
Thanks!
Posted July 5th, 2013 12:14
djedge2008
How to Set Up an NFS Mount on Ubuntu 12.04 | DigitalOcean https://www.digitalocean.com/community/articles/how-to-set-up-an-n...
6 de 8 05/08/2013 20:41
Further expansion of previous post....
The source box shows the files as gone and removed using ls in shell...
Windows 7 samba shows the files still there and i can copy them even though linux shows they are gone...
What gives lol
Posted July 5th, 2013 12:20
djedge2008
Solving my own post....... There must be some kind of delay with the directory listings ... After refreshing the folder a couple oftimes from the windows box the files that were moved via rsync were removed out of the list.
Posted July 5th, 2013 12:23
Create your account or sign-in
Company
PricingComparison ChartFeaturesCustomersAboutFAQJobsAPIIntegrationsNetwork StatusPress KitContact
Community
Articles & TutorialsChatQuestionsBlogReferral Program
How to Set Up an NFS Mount on Ubuntu 12.04 | DigitalOcean https://www.digitalocean.com/community/articles/how-to-set-up-an-n...
7 de 8 05/08/2013 20:41
FeedbackGet Paid to WriteBadges & LogosThe Shop
Getting Started
What is Cloud Hosting?Control Panel OverviewDeploy a Virtual ServerSet-Up SSH KeysInstall Git on UbuntuHow to Install Ruby on RailsHow to Install LAMP StackSet-Up a Host Name
Create an AccountGet Started
©2011-2013 DigitalOcean™, Inc. All Rights Reserved. Terms & Privacy. Security.Proudly Made in NYC
How to Set Up an NFS Mount on Ubuntu 12.04 | DigitalOcean https://www.digitalocean.com/community/articles/how-to-set-up-an-n...
8 de 8 05/08/2013 20:41