Setting Up An NFS Server And Client On Ubuntu 10.04
Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Follow me on Twitter
Last edited 09/14/2010This guide explains how to set up an NFS server and an NFS client on Ubuntu 10.04. NFS stands for Network File System; through NFS, a client can access (read, write) a remote share on an NFS server as if it was on the local hard disk.
I do not issue any guarantee that this will work for you!
1 Preliminary Note
I'm using two Ubuntu systems here:
- NFS Server: server.example.com, IP address: 192.168.0.100
- NFS Client: client.example.com, IP address: 192.168.0.101
Because we must run all the steps from this tutorial with root privileges, we can either prepend all commands in this tutorial with the string sudo, or we become root right now by typing
sudo su
2 Installing NFS
server:
On the NFS server we run:
aptitude install nfs-kernel-server nfs-common portmap
client:
On the client we can install NFS as follows:
aptitude install nfs-common portmap
3 Exporting Directories On The Server
server:
I'd like to make the directories /home and /var/nfs accessible to the client; therefore we must "export" them on the server.
When a client accesses an NFS share, this normally happens as the user nobody. Usually the /home directory isn't owned by nobody (and I don't recommend to change its ownership to nobody!), and because we want to read and write on /home, we tell NFS that accesses should be made as root (if our /home share was read-only, this wouldn't be necessary). The /var/nfs directory doesn't exist, so we can create it and change its ownership to nobody and nogroup:
mkdir /var/nfs
chown nobody:nogroup /var/nfsNow we must modify /etc/exports where we "export" our NFS shares. We specify /home and /var/nfs as NFS shares and tell NFS to make accesses to /home as root (to learn more about /etc/exports, its format and available options, take a look at
man 5 exports
)
vi /etc/exports
# /etc/exports: the access control list for filesystems which may be exported # to NFS clients. See exports(5). # # Example for NFSv2 and NFSv3: # /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check) # # Example for NFSv4: # /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check) # /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check) # /home 192.168.0.101(rw,sync,no_root_squash,no_subtree_check) /var/nfs 192.168.0.101(rw,sync,no_subtree_check)(The no_root_squash option makes that /home will be accessed as root.)
Whenever we modify /etc/exports, we must run
exportfs -a
afterwards to make the changes effective.
4 Mounting The NFS Shares On The Client
client:
First we create the directories where we want to mount the NFS shares, e.g.:
mkdir -p /mnt/nfs/home
mkdir -p /mnt/nfs/var/nfsAfterwards, we can mount them as follows:
mount 192.168.0.100:/home /mnt/nfs/home
mount 192.168.0.100:/var/nfs /mnt/nfs/var/nfsYou should now see the two NFS shares in the outputs of
df -h
root@client:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/server2-root
29G 847M 26G 4% /
none 243M 172K 242M 1% /dev
none 247M 0 247M 0% /dev/shm
none 247M 48K 247M 1% /var/run
none 247M 0 247M 0% /var/lock
none 247M 0 247M 0% /lib/init/rw
none 29G 847M 26G 4% /var/lib/ureadahead/debugfs
/dev/sda1 228M 17M 199M 8% /boot
192.168.0.100:/home 18G 838M 16G 5% /mnt/nfs/home
192.168.0.100:/var/nfs
18G 838M 16G 5% /mnt/nfs/var/nfs
root@client:~#and
mount
root@client:~# mount
/dev/mapper/server2-root on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
none 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)
none on /dev type devtmpfs (rw,mode=0755)
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
none on /dev/shm type tmpfs (rw,nosuid,nodev)
none on /var/run type tmpfs (rw,nosuid,mode=0755)
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
none on /var/lib/ureadahead/debugfs type debugfs (rw,relatime)
/dev/sda1 on /boot type ext2 (rw)
192.168.0.100:/home on /mnt/nfs/home type nfs (rw,addr=192.168.0.100)
192.168.0.100:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,addr=192.168.0.100)
root@client:~#
5 Testing
On the client, you can now try to create test files on the NFS shares:
client:
touch /mnt/nfs/home/test.txt
touch /mnt/nfs/var/nfs/test.txtNow go to the server and check if you can see both test files:
server:
ls -l /home/
root@server:~# ls -l /home/
total 4
drwxr-xr-x 3 administrator administrator 4096 2010-04-29 14:21 administrator
-rw-r--r-- 1 root root 0 2010-09-14 17:11 test.txt
root@server:~#ls -l /var/nfs
root@server:~# ls -l /var/nfs
total 0
-rw-r--r-- 1 nobody nogroup 0 2010-09-14 17:12 test.txt
root@server:~#(Please note the different ownerships of the test files: the /home NFS share gets accessed as root, therefore /home/test.txt is owned by root; the /var/nfs share gets accessed as nobody, therefore /var/nfs/test.txt is owned by nobody.)
6 Mounting NFS Shares At Boot Time
Instead of mounting the NFS shares manually on the client, you could modify /etc/fstab so that the NFS shares get mounted automatically when the client boots.
client:
Open /etc/fstab and append the following lines:
vi /etc/fstab
[...] 192.168.0.100:/home /mnt/nfs/home nfs rw,sync,hard,intr 0 0 192.168.0.100:/var/nfs /mnt/nfs/var/nfs nfs rw,sync,hard,intr 0 0Instead of rw,sync,hard,intr you can use different mount options. To learn more about available options, take a look at
man nfs
To test if your modified /etc/fstab is working, reboot the client:
reboot
After the reboot, you should find the two NFS shares in the outputs of
df -h
root@client:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/server2-root
29G 847M 26G 4% /
none 243M 172K 242M 1% /dev
none 247M 0 247M 0% /dev/shm
none 247M 48K 247M 1% /var/run
none 247M 0 247M 0% /var/lock
none 247M 0 247M 0% /lib/init/rw
/dev/sda1 228M 17M 199M 8% /boot
192.168.0.100:/var/nfs
18G 838M 16G 5% /mnt/nfs/var/nfs
192.168.0.100:/home 18G 838M 16G 5% /mnt/nfs/home
root@client:~#and
mount
root@client:~# mount
/dev/mapper/server2-root on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
none 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)
none on /dev type devtmpfs (rw,mode=0755)
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
none on /dev/shm type tmpfs (rw,nosuid,nodev)
none on /var/run type tmpfs (rw,nosuid,mode=0755)
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
none on /var/lib/ureadahead/debugfs type debugfs (rw,relatime)
/dev/sda1 on /boot type ext2 (rw)
192.168.0.100:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,sync,hard,intr,addr=192.168.0.100)
192.168.0.100:/home on /mnt/nfs/home type nfs (rw,sync,hard,intr,addr=192.168.0.100)
root@client:~#
7 Links
- Linux NFS: http://nfs.sourceforge.net/
- Ubuntu: http://www.ubuntu.com/
Copyright © 2010 Falko Timme
All Rights Reserved.
Tuesday, October 5, 2010
Setting Up An NFS Server And Client On Ubuntu 10.04
via howtoforge.com
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment