setting up an nfs server and client on debian wheezy

Upload: samsul-alam

Post on 05-Nov-2015

227 views

Category:

Documents


0 download

DESCRIPTION

Konfigurasi NFS Debian Server

TRANSCRIPT

Setting up an NFS Server and Client on Debian WheezyVersion 1.0Authors: Till Brehm Last edited 02/02/2014This guide explains how to set up an NFS server and an NFS client on Debian Wheezy. NFS stands forNetwork 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. In this Tutorial I will show you two different NFS exports, the export of a client directory that stores files as user nobody / nogroup without preserving filesystem permissions and a export of the /var/www directory which preserves permissions and ownerships of files, as required on a hosting server setup.1 Preliminary NoteI'm using two Debian Wheezy systems here: NFS Server:server.example.com, IP address:192.168.0.100 NFS Client:client.example.com, IP address:192.168.0.1012 Installing NFSserver:On the NFS server we run:apt-get install nfs-kernel-server nfs-commonThen we create the system startup links for the NFS server and start it:client:On the client we can install NFS as follows (this is actually the same as on the server):apt-get install nfs-common3 Exporting Directories on the Serverserver:I'd like to make the directories/home/client1and/var/wwwaccessible to the client to show the two different access modes of the nfs server. The directory/home/client1is shared in standard mode, so all files written to this directory are stored as user nobody and group nogroup. For the directory/var/wwwI use the no_root_squash option which instructs the nfs server to preserve permissions and ownerships of the files. This is e.g. required when you like to export the/var/wwwdirectory of a webserver managed withISPConfig 3First, I'll create the/home/client1directorymkdir /home/client1chown nobody:nogroup /home/client1chmod 755 /home/client1The /var/www directory exists most likely on your server. If not, then create it:mkdir /var/wwwchown root:root /var/wwwchmod 755 /var/wwwNow we must modify/etc/exportswhere we "export" our NFS shares. We specify/home/client1and/var/wwwas NFS shares and tell NFS to make accesses to/home/client1as user nobody (to learn more about/etc/exports, its format and available options, take a look atman 5 exports)vi /etc/exports/home/client1 192.168.0.101(rw,sync,no_subtree_check)/var/www 192.168.0.101(rw,sync,fsid=0,crossmnt,no_subtree_check,no_root_squash)

(Theno_root_squashoption makes that/var/wwwwill be accessed as root.)To apply the changes in/etc/exports, we restart the kernel nfs server/etc/init.d/nfs-kernel-server restart4 Mounting the NFS shares on the Clientclient:First we create the directories where we want to mount the NFS shares, e.g.:mkdir -p /mnt/nfs/home/client1mkdir -p /var/wwwIf the direcory /var/www exists already on your server, then stop apache, rename the directory and create a new empty directory as mountpoint/etc/init.d/apache2 stopmv /var/www /var/www_bakmkdir -p /var/wwwAfterwards, we can mount them as follows:mount 192.168.0.100:/home/client1 /mnt/nfs/home/client1mount 192.168.0.100:/var/www /var/wwwYou should now see the two NFS shares in the outputs ofdf -h[root@client~]#df-hFilesystemSizeUsedAvailUse%Mountedon/dev/mapper/vg_server2-LogVol009.7G1.7G7.5G18%/tmpfs499M0499M0%/dev/shm/dev/sda1504M39M440M9%/boot192.168.0.100:/home/client19.7G1.7G7.5G19%/mnt/nfs/home/client1192.168.0.100:/var/www9.7G1.7G7.5G19%/var/www[root@client~]#andmount[root@client ~]# mount/dev/mapper/vg_server2-LogVol00 on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)tmpfs on /dev/shm type tmpfs (rw)/dev/sda1 on /boot type ext4 (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)192.168.0.100:/home/client1 on /mnt/nfs/home/client1 type nfs (rw,vers=4,addr=192.168.0.100,clientaddr=192.168.0.101)192.168.0.100:/var/www on /var/www type nfs (rw,vers=4,addr=192.168.0.100,clientaddr=192.168.0.101)[root@client ~]#5 TestingOn the client, you can now try to create test files on the NFS shares:client:touch /mnt/nfs/home/client1/test.txttouch /var/www/test.txtNow go to the server and check if you can see both test files:server:ls -l /home/client1/[root@server~]#ls-l/home/client1total0-rw-r--r--1nobody nogroup0Feb0216:58test.txt[root@server~]#ls -l /var/nfs[root@server~]#ls-l/var/wwwtotal0-rw-r--r--1rootroot0Feb0216:58test.txt[root@server~]#(Please note the different ownerships of the test files: the/home/client1NFS share gets accessed as nobody / nogroup andis owned by nobody / nogroup; the/var/wwwshare gets accessed asroot, therefore/var/www/test.txtis owned byuser and group root.)6 Mounting NFS Shares At Boot TimeInstead of mounting the NFS shares manually on the client, you could modify/etc/fstabso that the NFS shares get mounted automatically when the client boots.client:Open/etc/fstaband append the following lines:vi /etc/fstab[...]192.168.0.100:/home/client1 /mnt/nfs/home/client1 nfs rw,sync,hard,intr 0 0192.168.0.100:/var/www /var/www nfs rw,sync,hard,intr 0 0

Instead ofrw,sync,hard,intryou can use different mount options. To learn more about available options, take a look atman nfsTo test if your modified/etc/fstabis working, unmount the shares and runmount -a:umount /mnt/nfs/home/client1umount /var/wwwmount -aYou should now see the two NFS shares in the outputs ofdf -h[root@client~]#df-hFilesystemSizeUsedAvailUse%Mountedon/dev/mapper/vg_server2-LogVol009.7G1.7G7.5G18%/tmpfs499M0499M0%/dev/shm/dev/sda1504M39M440M9%/boot192.168.0.100:/home/client19.7G1.7G7.5G19%/mnt/nfs/home/client1192.168.0.100:/var/www9.7G1.7G7.5G19%/var/www[root@client~]#andmount[root@client ~]# mount/dev/mapper/vg_server2-LogVol00 on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)tmpfs on /dev/shm type tmpfs (rw)/dev/sda1 on /boot type ext4 (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)192.168.0.100:/home/client1 on /mnt/nfs/home/client1 type nfs (rw,vers=4,addr=192.168.0.100,clientaddr=192.168.0.101)192.168.0.100:/var/www on /var/www type nfs (rw,vers=4,addr=192.168.0.100,clientaddr=192.168.0.101)[root@client ~]#7 CreditsThis Tutorial is based in theCentos NFS ServerTutorial from Falko Timme.