发新话题
打印

NETAPP技术学习全程记录

本主题由 awu 于 2008-10-12 15:31 设置高亮

export and mount

服务器端:
/etc/exports文件包含了已经被export给客户端的目录和文件
     最多包含10240个条目(entry),对条目的大小没有限制
     一个条目可以分成几行
     条目包含了路径名和选项
     当options nfs.export.auto-update 设置为on的情况下,用命令exportfs或者对volume做了创建,重命名,删除等更新动作时,系统会自动更新/etc/exports文件

客户端:
  mount命令被用来连接服务器端的文件系统
      需要在本机上选择或建立一个挂接点(mountpoint ),一个目录
      卸载的话使用命令umount
      已经mount的资源都包含在系统的mount table中。

TOP

访问限制

可以通过/etc/exports文件中的条目来定义,或者通过exportfs命令来指定访问限制
    哪个主机可以mount资源
   可以对mount后的文件是可以读写,还是只读
   客户端的root用户是否可以访问这些资源
   文件是否可以被带有SETUID位创建
   访问资源的用户ID(UID)
当多个限制条件加于某个资源时,最严格的限制优先起作用

TOP

/etc/exports 中各选项的解释

DR*> rdfile /etc/exports
#Auto-generated by setup Sat Mar 22 09:08:52 EDT 2008
/vol/vol0       -sec=sys,rw,anon=0,nosuid
/vol/vol0/home  -sec=sys,rw,nosuid
/vol/vol1       -sec=sys,rw,nosuid

在/etc/exports文件中,一个被导出的NFS目录占据一行或多行,就是上面说的一个条目。格式上面例子中可以看到。
一个带全路径的目录(绝对目录)。选项是下面说到的一个或多个设置的组合。
ro   如果指定客户端,那该客户端以只读的方式访问被导出的目录。如果没有指定,那导出的目录对所有客户端都只读。
rw  如果指定客户端,那该客户端以读写的方式访问被导出的目录。如果没有指定,那导出的目录对所有客户端都可读写。
root 如果指定主机,就有root的权限。如果没有指定,那表示任何主机都没有root访问权限。
anon 默认情况,该anon选项指定一个UID 65534。如果UID被指定为65535,root用户的访问将被禁止。如果UID被指定为0,客户端的访问都将被视为root用户。如果用一个具体的用户名来替代UID,系统会去根据/etc/nsswitch.conf中定义的查找顺序到相关配置中查询用户信息来确定UID.

[ 本帖最后由 ender 于 2008-7-4 09:52 编辑 ]

TOP

NFS mount 过程

  

Client


  
  

Process


  
  

Server


  
  

Here is my session ID (XID)


  
  

Portmapper


  
  

I see your session ID (XID)


  
  

I want to mount


  
  

Mount


  
  

Who are you?


  
  

I am UID0 and group ID (GID) All


  
  

Mount


  
  

OK, here is my fhandle (FSID)


  
  

Should I use v3 TCP?


  
  

Portmapper


  
  

Yes on port 1024


  
  

Can you hear me on port 1024 (SYN)?


  
  

TCP


  
  

Yes, let us negotiate window size (ACK)


  
  

TCP is established (SYN, ACK)


  
  

TCP


  
  

OK (SYN, FIN,ACK)


  
  

Here is my fhandle (FSID) I want to mount


  
  

NFS


  
  

You are connected


  




一次nfs mount的全过程。

[ 本帖最后由 ender 于 2008-7-4 10:03 编辑 ]

TOP

在Data ONTAP中启用NFS

1.需要输入NFS的license,rpc.mountd和nfsd daemons被启动
DR*> license
               cifs site DZDACHD
            cluster not licensed
     cluster_remote not licensed
  disk_sanitization not licensed
                fcp not licensed
         flex_cache not licensed
         flex_clone not licensed
            gateway not licensed
    gateway_hitachi not licensed
               http site NAZOMKC
              iscsi site BSLRLTG
         multistore not licensed
    nearstore_asis1 not licensed
   nearstore_option not licensed
                nfs site BQOEAZL
2.启动NFS服务
DR*> nfs on
NFS server is running.
3.导出(export)文件系统供客户机使用
4.在客户机上挂接(mount)文件系统

TOP

exportfs 举例

把/vol/vol0 export给所有客户端,并都有读写权限      
       exportfs -p /vol/vol0
       exportfs -io rw /vol/vol0

把/vol/vol0 export给所有客户端,并都有只读权限   
       exportfs -p ro /vol/vol0
       exportfs -io ro /vol/vol0

把/vol/vol0 export给10.45.67.0网段上所有的客户端,并都有读写权限   
       exportfs -io rw=10.45.67.0/24 /vol/vol0
       exportfs -io rw="network 10.45.67.0 netmask 255.255.255.0" /vol/vol0
       exportfs -io rw="10.45.67.0 255.255.255.0" /vol/vol0

把 /vol/vol0 export给trusted netgroup并有root访问权限,  在friendly  netgroup 中的客户端有读写权限,其他客户端有只读权限:
       exportfs -io ro,root=@trusted,rw=@friendly /vol/vol0

TOP

exportfs命令几个常用参数

exportfs
显示已经被导出的文件系统路径

exportfs [ -c ] host name [ro | rw | root ]
检查当前访问缓存中的主机权限

exportfs -s pathname
检验哪个卷被导出

exportfs -r
确认只有绑定了的exports被引导

exportfs -a
导出在/etc/exports文件中所有的条目

exportfs -r
导出在/etc/exports文件中所有的条目,将没在其中的unexport掉

TOP

准备NFS测试环境

准备NFS测试环境.前面说了很多理论上的NFS的东西,还是实践一下认识比较深刻一些.

NFS服务器: Data ONTAP simulator,ip为192.168.222.100
LINUX客户端:
  host1 192.168.222.2
  host2 192.168.222.20
  host3 192.168.200.2

R1> vol create  /vol/nfstest myaggr 30M      
Sat Mar 29 00:40:01 EDT [vol.language.changed:info]: Language on volume nfstest changed to en_US
The new language mappings will be available after reboot
Sat Mar 29 00:40:01 EDT [vv_config_worker:notice]: XL - Language of Volume nfstest has been changed to en_US.
Creation of volume 'nfstest' with size 30m on containing aggregate
'myaggr' has completed.
R1> rdfile /etc/exports                     
#Auto-generated by setup Fri Mar 21 20:07:49 EDT 2008
/vol/vol0       -sec=sys,rw,anon=0,nosuid
/vol/vol0/home  -sec=sys,rw,nosuid
/vol/nfstest    -sec=sys,rw,nosuid

可见当一个新的flexvol,nfstest被创建后系统自动把其加入到/etc/exports文件中.
这个时候在客户端可以mount.
[root@host1 root]# mount 192.168.222.100:/vol/nfstest /mnt
[root@host1 root]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             15891788   3839788  11244736  26% /
/dev/sda1               101089      9426     86444  10% /boot
none                    127632         0    127632   0% /dev/shm
192.168.222.100:/vol/nfstest
                         24576        88     24488   1% /mnt

但是这个时候主机是没有写权限的
[root@host2 root]# mount 192.168.222.100:/vol/nfstest /mnt
[root@host2 root]# touch /mnt/testfile
touch: creating `/mnt/testfile': Permission denied
[root@host2 root]#

[ 本帖最后由 ender 于 2008-7-4 15:50 编辑 ]

TOP

NFS测试(续)

在主机上继续mount一个NFS,/vol/vol0,这次可以写.
[root@host2 root]# mount 192.168.222.100:/vol/vol0 /nfs
[root@host2 root]# touch /nfs/lll
[root@host2 root]# ls /nfs
etc  home  lll
[root@host2 root]#
检查对比一下在/etc/exports中,/vol/vol0和/vol/nfstest有何不同

R1> rdfile /etc/exports
#Auto-generated by setup Fri Mar 21 20:07:49 EDT 2008
/vol/vol0       -sec=sys,rw,anon=0,nosuid
/vol/vol0/home  -sec=sys,rw,nosuid
/vol/nfstest    -sec=sys,rw,nosuid
从这里看配置应该是可以读写的.没搞明白.呵呵.

[ 本帖最后由 ender 于 2008-7-4 16:14 编辑 ]

TOP

There are two options in the "exportfs" command.One is "root=", the other is "anon=".

1.If you use "root=<hostname or ip address>" option in the "exportfs" command, then the filer will assign UID 0 to the root user of the client host which is included in the "root=<>" option.

2.If you don't use the "root=" option while exportfs,but you use "anon=501", then the filer will assign the UID 501 to the root user logined from eny clients

3.If you use "root=" and also use "anon=" at the same time, the root user who login from the host included in the "root=" option will be assigned with the UID 0,and the root user who login from clients not included in the "root=" will be assigned with UID <anon>.

4.If you don't use the "root=" and "anon=" options , the root user of all clients will be assigned with UID 65534

5.all none-root user will be assigned with the original UID of the client's UID in the filer.


I hope above will help you. as to your question, if you want to use root user to create a file whoes UID is not 0, you can choose a method listed above to use.

Thanks!
敝人博客
《大话存储》购买:当当,互动,淘宝,卓越,自行搜索。

TOP

发新话题