大家好 :
下面是小弟写的一些介绍 NFS 的文章, 由於想参与网路管理的工作学长指派这一个主题给我报告, 由於本身对这方面并不太懂, 只是找一些书籍随便拼拼凑凑, 不知道有没有写到重点,或是一些要点没有提到,因此post出来希望熟悉NFS 的高手们能花一点时间看看我的文章 然後mail给我,指出错误的地方,或者直接reply也可以, 谢谢 !
E-mail : u3430854@sparc20.ncu.edu.tw
===========================================================================
◎ What is NFS ?
Network File System
NFS 是由SUN公司发展, 并於1984年推出, NFS是一个RPC service ,
它使我们能够达到档案的共享, 它的设计是为了在不同的系统间使用, 所
以它的通讯协定设计与主机及作业系统无关.当使用者想用远端档案时只
要用"mount"就可把remote档案系统挂接在自己的档案系统之下,使得远端
的档案使用上和local机器的档案没两样.
machine A machine B
/ /
bin etc usr bin etc usr
man man share local
假如我们在机器A上, 要把机器B上的 /usr/man 挂接到machine A 的
/usr/man只要下
mount machine_name:/usr/man /usr/home
就可mount过来.而我们不只是可以mount目录,就是一个档也是可以的.在
挂接之後我们只能对档案做reading (or writing) 的动作,而不能在
remote machie上把此档或目录move,delete掉 , 但须注意的是如我们
mount /usr 後 , 不能再mount /usr底下的目录, 否则会发生错误
□ Servers & Clients
NFS就是促使Servers上的档案能被其他的机器mount,而达到资源共享,
享用这些档案的机器就可称为Client,一个client可以从server上mount一
个档或是一个层次的目录(file hierarchies) . 然而事实上任何一台机器
都可以做NFS server or NFS client ,甚至同时为NFS server and NFS
client 也可以.
□ Server's Exporting & Client's Mounting
NFS server 所export 出来的档案或目录都记录在 /etc/exports 这
一个档中,当我们启动NFS server 时 在 /etc/rc.local 的这一个script
会自动的启动 exportfs 这一个程式 , 搜寻 /etc/exports 这一个档是否
存在, 并且赋予正确的权限给所有export出去的 file hierarchies .
但须注意的是,只有server所export出去的路径,NFS client才能够mount
, 同样的当启动client时 , 系统会自动去mount所有server export的路径,
而mount到的所有路径都会记录在 /etc/fstab 下 , 类似如下的fstab档
/dev/sd0a / 4.2 rw 1 1
/dev/sd0h /tmp 4.2 rw 1 3
/dev/sd0g /usr 4.2 rw 1 2
/dev/fd0 /pcfs pcfs rw,noauto 0 0
sparc20:/swap /swap nfs rw,intr,bg,soft 0 0
sparc17:/home /home nfs rw,intr,bg,soft 0 0
sparc17:/home3 /home3 nfs rw,intr,bg,soft 0 0
sparc14:/home4 /home4 nfs rw,intr,bg,soft 0 0
sparc20:/home2 /home2 nfs rw,intr,bg,soft 0 0
sparc20:/var/spool/mail /var/spool/mail nfs rw,intr,bg,soft 0 0
rs970:/home1 /home1 nfs rw,intr,bg,soft 0 0
★ Noted :
当client mount 到一个路径,绝对不是说copy server上的这一个路径
到local的机器上,我们可以用 cd 进入这一个mount到的路径,就如同是使用
local directory一样
□ Setting Up a NFS Server
1. 定义机器为 NFS file server
2. 划分server's disk ,定义哪一些partitions 是要提供出来作为
client 所共享的file system
3. 在 Client Form 上定义每一台client 的参数
4. 写出 /etc/exports (一般系统都有一个default exports)
5. 重新boot NFS server or 用指令 exportfs -a 输出所有的
directories 并且用 nfsd 8 & 启动 nfsd守护程式,常驻在背景
※ ps. 一些细节
1. 检查 /etc/exports 输出路径的权限,确定只有root能修改,
all user只能read
2. 用exportfs 去增加或删除directories
exportfs -o access=engineering,ro=dancer /usr
exportfs -u /usr
3. 假如你的机器没有NIS(YP server)的服务,当更改资料时记得修改
/etc/passwd
/etc/group
/etc/hosts
/etc/ethers
4. 为你自己的network 设置security
exportfs的语法
/usr/etc/exportfs [ -avu ] [ -o option ] [ directory ]
-a : 把 /etc/exports 中所有路径export出去
-u : 把 export出去的路径卸下 , 如 exportfs -u /usr
-o option : 如 exportfs -o ro /usr ,所有人对/usr 都为read only
option 还有 root = hostname , access = client
access = netgroup
For example :
exportfs -a 把exports中的路径全部export出去
exportfs -o access=engineering:other /usr
/usr 这路径export後只有engineering and other 这两个
group 能够 read & write
exportfs -o access=oak,ro=dancer /usr
设定dancer 这台client 对 /usr 为read only ,且只有
oak这一个 group 能做read
/etc/exports 档的□例
● syntax : directory -option[,option]
(设定两个group能rw)
/usr -access=engineering:accounting
/home -access=engineering:accounting
/var/spool/mail -access=engineering:accounting
/export/exec/sun3 -access=engineering:accounting
/export/exec/sun3.sunos.4.1 -access=engineering:accounting
/export/exec/kvm/sun3.sunos.4.1 -access=engineering:accounting
/export/root/birch -access=birch,root=birch
