什么是NFS文件系统

  • 什么是NFS文件系统
  • ◎ 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 也可以.



    □ Servers Exporting & Clients 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. 划分servers 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. 一些细节
    检查 /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
    /export/swap/birch -access=birch,root=birch
    /export/root/oak -access=oak,root=oak
    /export/swap/oak -access=oak,root=oak
    /export/root/willow -access=willow,root=willow
    /export/swap/willow -access=willow,root=willow
    /export/root/pine -accsee=pine,root=pine
    /export/swap/pine -accsee=pine,root=pine
    (access=client , root=hostname 如此只有这一台client的superuser有权力rw)

    □ Setting Up a NFS Client

    1. 宣告机器为没有磁碟机或没有资料的Client,在使用SunInstall之前
    2. 编辑好 /etc/fstab 这一个档,确定要mount的路径都在fstab中
    3. 依照fstab所设的内容,在Client上设定好Mount points
    (mount_points 就是用mkdir 设exports所输出的路径)
    4. 确定我们所要mount的路径,都有出现在 /etc/exports 中
    5. 可以启动mount去连结server上的directories ( mount -a )

    /etc/fstab 档的□例
    ● syntax filesystem directory type options freq pass
    oak:/export/root/boomer / nfs rw 0 0
    ^^^
    因为档案在server上,not on client
    所以client的设定为0
    oak:/export/exec/sun3 /usr nfs ro 0 0
    oak:/export/exec/kvm/sun3 /usr/kvm nfs ro 0 0
    oak:/usr/share /usr/share nfs ro 0 0
    oak:/home/oak /home/oak nfs rw,bg 0 0



    § mount 的语法

    ● syntax : mount -t type [-rv] -o [option] server:pathname /mount_point
    MOUNT :
    mount -a 把/etc/fstab 中所列的路径全部挂上
    mount -o ro,soft,bg dancer:/usr/local /usr/local/dancer
    把dancer server 的/usr/local mount 到 client的
    /usr/local/dancer 并且是read only

    -t type : 你所要mount的型别, 如 nfs or 4.2
    -r : 所mount的路径定为read only
    -v : mount过程的每一个动作,都有messages 传回到萤幕上
    hard : 重复要求,直到server回应为止,但如server一直不回应
    the server may be down !
    soft : 当client的请求得不到回应,retry one time 後 传回
    error message
    bg : 当第一次请求不成功,第二次的mount将放到背景执行
    fg : retries mount 都一直在提示符号下进行
    intr : 当正在进行 NFS 请求时,允许用键盘中断

    mount 成功时的message
    NFS server hostname ok
    hard mount fail
    NFS server hostname not responding, still trying
    soft . . .hostname server not reponding: RPC: Timed out

    § UNMOUNT :

    umount mount_point
    umount -a 卸下所有已经mount上的路径

    ◎ How NFS Work ?

    当我们启动 NFS file server 时,/etc/rc.local 会自动启动exportfs这一个程式,指定可以export的档案或目录,而我们所能mount的也只能是其所指定的目录.



    □ NFS 架设在 XDR/RPC的协定之上

    XDR : (eXternal Data Representation) 外部资料表示法
    XDR(eXternal Data Representation) 提供一种方法把资料从一种格式转换成另一种标准资料格式表示法,确保在不同的电脑,作业系统及电脑语言中,所有资料代表的意义都是相同的

    RPC : (Remote Procedure Calls) 远端程序呼叫
    RPC(Remote Procedure Calls) 远端程序呼叫, 请求远端电脑给予服务. 委托器(client)就会透过网路传送RPC到远端电脑,请求服务.
    (一般 local machine : client remote machine : server )

    □ NFS 如何运用 RPC 传送资料

    客户端process 主服务端process
    ┌————┐ ┌—————┐
    │ 客户端 │ │ 主服务站 │
    │routines│ │ routines │
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值