07 NFS v4.0 File Server

Network File System (NFS) eshte nje protokoll per sistemin e skedareve ne rrjet i ndertuar fillimisht nga Sun Microsystems.

NFS lejon perdoruesit qe te kapin skedaret nepermjet rrjetit.

Paketat qe nevojiten per funksionimin e NFS

Duhet te instalojme paketat e meposhtme:

    • nfs-utils - Paketa nfs-utils permban nje daemon per serverin NFS dhe disa mjete ndihmese.

    • nfs4-acl-tools - Kjo pakete permban utilitete per ACLp er klientin NFSv4 client.

    • autofs - Kjo pakete instalohet ne klient dhe sherben per ngarkimin automatik te FS ne klient

Konfigurimi i Serverit NFS

[root@localhost student]# yum install nfs-utils nfs4-acl-tools

.....................................................................

Publikimi i dosjeve ne rrjet

Skedari /etc/exports eshte skedari kryesor i konfigurimit qe kontrollon cilat direktori publikon serveri NFS

Ai perdor formatin:

/directory1 server.example.com(options)

/directory2 192.168.1.0/24(options)

/directory3 192.168.1.5(options) 192.168.1.15(options) pc202.nixcraft.net.in(options)

Per efekt shembulli kemi kkrijuar nje dosje /sales te cilen do ta ndajme vetem ne rrjetin lokal 192.168.221.0/24

Nese duam qe dosjen /sales ta ndajme vetem me rrjetin local do te shtonim nje rresht tek /etc/exports ne formatin me poshte:

/sales 192.168.221.0/24(rw,sync,fsid=0)

Disa Opsione,

/sales – shared directory

192.168.9.0/24 – IP address range of clients

rw – Writable permission to shared folder

sync – Synchronize shared directory

Ndersa nese duam ta ndajme vetem me dy kompjutera konkrete do te perdornim formatin me poshte:

/sales 192.168.221.15(rw,sync,fsid=0) 192.168.221.16(rw,sync,fsid=0)

shembull:

[root@localhost student]# cat /etc/exports

/sales 192.168.221.0/24(rw,sync,fsid=0)

/autofs_test 192.168.221.0/24(rw,sync,fsid=0)

[root@localhost student]#

Te ngreme sherbimin NFS ne server

# chkconfig nfs on

# service nfs start

IP Tables

Ulim sherbimin iptables ( porta hyrese 2049 perdoret nga NFS)

[root@localhost student]# service iptables stop

TCP Wrapper

Te konfigurojme edhe filtrin e TCP Wrapper duke ndaluar aksesin per te gjithe dhe duke lejuar aksesin vetem per rrjetin lokal:

skedari /etc/hosts.deny

[root@localhost student]# cat /etc/hosts.deny

portmap:ALL

skedari /etc/hosts.allow

[root@localhost student]# cat /etc/hosts.allow

#

portmap:192.168.221.0/24

Konfigurimi i klientit NFS

Ngarkimi i nje dosje te publikuar ne rrjet ne menyre manuale

Ngarkimi i nje dosje te ndare ne rrjet ne menyre manuale mund te realizohet me komanden mount:

[root@localhost student]# mount -t nfs 192.168.221.9:/sales /mysales

[root@localhost student]# ls /mysales

test2.txt test.txt

[root@localhost student]#

Nese do te verifikojme me komanden mount nese eshte ngarkuar dosja /mysales :

[root@localhost student]# mount | grep sales

192.168.221.9:/sales on /mysales type nfs (rw,addr=192.168.221.9)

Tani mund te shikojme permbajtjen e dosjes 192.168.221.9:/sales ne /mysales

[root@localhost student]# ls /sales

hello.world test2.txt test.txt

[root@localhost student]#

Ngarkimi i nje doske ne menyre automatike nepermjet /etc/fstab

Nese dua qe dosja te ngarkohet ne menyre automatike ne momentin e ndezjes se sistemit duhet te shtojme nje rresht ne /etc/fstab si me poshte:

[root@localhost student]# cat /etc/fstab

#

# /etc/fstab

# Created by anaconda on Sun Mar 16 09:38:17 2014

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=99dc7a8a-3c61-412a-aa6c-01af196f8822 / ext4 defaults 1 1

UUID=f8b7f6a2-a8a0-4843-9341-eddf9a2e93b8 /boot ext4 defaults 1 2

UUID=8a5fc919-498a-451f-9544-771f3d8735c1 /home ext4 defaults 1 2

UUID=96ed05f9-7403-4f44-97b3-4e1846b8b5a9 /sd6 ext4 defaults 1 2

UUID=a84d4258-9911-4ea3-b18b-c3993eb992e8 swap swap defaults 0 0

tmpfs /dev/shm tmpfs defaults 0 0

devpts /dev/pts devpts gid=5,mode=620 0 0

sysfs /sys sysfs defaults 0 0

proc /proc proc defaults 0 0

/dev/vlm1/backup /bck ext4 defaults 1 2

192.168.221.9:/sales /mysales nfs defaults 0 0

[root@localhost student]#

Shtimi i rreshtit ne skedarin /etc/fstab do te beje qe pas reboot dosja /mysales te ngarkohet automatikisht.

Ekzistenca e nje rreshti ne /etc/fstab na mundeson gjithashtu ta ngarkojme dosjen manualisht me nje format te shkurtuar:

[root@localhost student]# mount /mysales/

[root@localhost student]# mount | grep sale

192.168.221.9:/sales on /mysales type nfs (rw,addr=192.168.221.9)

[root@localhost student]#

Ngarkimi i nje dosje ne menyre automatike nepermjet autofs

Utiliteti autofs mundeson ngarkimin e dosjeve ne menyre ne momentin qe ato tentojne te perdoren nga perdoruesi.

autofs ka nje skedar kryesot konfigurimi /etc/auto.master , i cili ruan lidhjet midis nje direktorie baze te ngarkimit ( map point) dhe nje skedari tjeter qe ruan direktorite qe do te ngarkohen.

Utiliteti autofs duhet instaluar ne klient nese nuk eshte instaluar tashme:

[root@localhost student]# yum install autofs

Loaded plugins: fastestmirror, refresh-packagekit, security

Loading mirror speeds from cached hostfile

* base: ftp.ntua.gr

* extras: ftp.ntua.gr

* updates: ftp.ntua.gr

Setting up Install Process

Package 1:autofs-5.0.5-89.el6_5.1.i686 already installed and latest version

Nothing to do

[root@localhost student]#

skedaret e konfigurimit

[root@localhost student]# cat /etc/auto.master

#

# Sample auto.master file

# This is an automounter map and it has the following format

# key [ -mount-options-separated-by-comma ] location

# For details of the format look at autofs(5).

#

/misc /etc/auto.misc

+auto.master

[root@localhost student]#

rreshti me lart percakton nje mount point dhe nje skedar teskt qe perckton dosjet qe do te ngarkohen ne kete mount point

skedari shembull /etc/auto.misc ka ne perberje nej rreshte per cdo dosje qe duhet ngarkuar ne formatin si me poshte:

payroll -fstype=nfs 192.168.221.9:/sales

ict -fstype=nfs 192.168.221.9:/autofs_test

    • emrin e dosjes lokakisht (payroll ose ict)

    • tipin e fstype

    • path ku ndodhet dosja ne rrjet.

Per te ngarkuar dosjen mjafton te tentojme ta perdorim ate. Vini re me poshte:

dosja payroll nuk eshte ngarkuar

[root@localhost student]# mount

/dev/sdb2 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,rootcontext="system_u:object_r:tmpfs_t:s0")

/dev/sdb1 on /boot type ext4 (rw)

/dev/sdb5 on /home type ext4 (rw)

/dev/sdc6 on /sd6 type ext4 (rw)

/dev/mapper/vlm1-backup on /bck type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

none on /proc/fs/vmblock/mountPoint type vmblock (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

nfsd on /proc/fs/nfsd type nfsd (rw)

[root@localhost student]#

dosja payroll nuk ekziston ne /misc/payroll

[root@localhost student]# ls /misc -l

total 0

[root@localhost student]#

nese do te tentojme te listojme permbajtjen e dosjes /misc/payroll do te veme re qe ajo do te ndarkohet automatikisht.

Shikoni me poshte:

[root@localhost student]# ls /misc/payroll -l

total 12

-rw-r--r--. 1 root root 6 Mar 28 04:03 hello.world

-rw-r--r--. 1 nfsnobody nfsnobody 8 Mar 21 04:52 test2.txt

-rw-r--r--. 1 root root 12 Mar 21 04:46 test.txt

[root@localhost student]#

Nese do te verifikojme tani permbajten e dosjes /misc do te veme re qe dosja /misc/payroll ekziston dhe ka permbajtjen e saj.

[root@localhost student]# ls /misc

payroll

[root@localhost student]# ls /misc/payroll/

hello.world test2.txt test.txt

[root@localhost student]#

Gjithashtu mund te verifikojme qe dosja eshte ngarkuar :

[root@localhost student]# mount | grep pay

/sales on /misc/payroll type none (rw,bind)

[root@localhost student]#

Shenim

Dosja do te shkeputet nese nuk perdoret per nje fare periudhe ( timeout perdiod ) qe percaktohet ne /etc/sysconfig/autofs dhe si default eshte 300 sek = 5 min.

rreshti brenda /etc/sysconfig/autofs qe percakton kohen e timeout:

TIMEOUT=300