Home | 簡體中文 | 繁體中文 | 雜文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 作品與服務 | Email

第 15 章 NFS

目錄

15.1. NFS Server Configuration
15.1.1. NFS 防火牆配置
15.2. NFS Client Configuration
15.2.1. Using NFS over UDP
15.3. NFS For Windows
15.4. exportfs - maintain table of exported NFS file systems
yum install -y nfs-utils
	

15.1. NFS Server Configuration

過程 15.1. On the *SERVER* side

  1. stop & disable services

    service nfs stop
    service nfslock stop
    service rpcbind stop
    service rpcidmapd stop
    				
  2. /etc/fstab

    as root edit /etc/fstab and add nfs4 exports
    
    /www  /exports    none    bind    0 0
    				
  3. as root edit /etc/exports

    NFSv3

    /exports 		172.16.1.0/24 (rw,sync)
    				

    NFSv4

    /exports 		172.16.1.0/24(rw,sync,fsid=0,anonuid=99,anongid=99)
    /exports/neo	*(rs,sync)
    				
  4. reload exported filesystems

    # exportfs -rv
    				
  5. start required services

    chkconfig rpcbind on
    chkconfig nfs on
    chkconfig nfslock on
    chkconfig rpcidmapd on
    
    service rpcbind start
    service rpcidmapd start
    service nfs start
    service nfslock start
    				
  6. nfs status

    #  nfsstat
    Server rpc stats:
    calls      badcalls   badauth    badclnt    xdrcall
    171        0          0          0          0
    
    Server nfs v3:
    null         getattr      setattr      lookup       access       readlink
    3         1% 150      88% 0         0% 3         1% 2         1% 0         0%
    read         write        create       mkdir        symlink      mknod
    0         0% 0         0% 0         0% 0         0% 0         0% 0         0%
    remove       rmdir        rename       link         readdir      readdirplus
    0         0% 0         0% 0         0% 0         0% 0         0% 9         5%
    fsstat       fsinfo       pathconf     commit
    0         0% 3         1% 0         0% 0         0%
    				
    # watch nfsstat -c
    
    Every 2.0s: nfsstat -c                                                                                                                          Mon Sep 20 16:53:55 2010
    
    Client rpc stats:
    calls      retrans    authrefrsh
    286818929   1160       0
    
    Client nfs v4:
    null         read         write        commit       open         open_conf
    0         0% 37286763 13% 6         0% 1         0% 38990106 13% 17986485  6%
    open_noat    open_dgrd    close        setattr      fsinfo       renew
    6         0% 0         0% 38774539 13% 2172019   0% 16        0% 147       0%
    setclntid    confirm      lock         lockt        locku        access
    321       0% 321       0% 0         0% 0         0% 0         0% 62157123 21%
    getattr      lookup       lookup_root  remove       rename       link
    80553542 28% 8828991   3% 8         0% 5         0% 5         0% 0         0%
    symlink      create       pathconf     statfs       readlink     readdir
    0         0% 1         0% 0         0% 5         0% 0         0% 13933     0%
    server_caps  delegreturn
    24        0% 54556     0%
    				
  7. security

    # vi /etc/hosts.deny
    rpcbind:ALL
    
    # vi /etc/hosts.allow
    rpcbind:172.16.1.0/255.255.254.0
    				

NFS的隊列大小下面將設置為較合理的值256K

# echo 262144 > /proc/sys/net/core/rmem_default
# echo 262144 > /proc/sys/net/core/rmem_max
# echo 262144 > /proc/sys/net/core/wmmen_default
# echo 262144 > /proc/sys/net/core/wmmen_max
		

過程 15.2. NFSv4

  1. /etc/exports

    # cat /etc/exports
    /www		172.16.1.2/32(ro,sync,fsid=0,anonuid=99,anongid=99)
    /www/logs	*(rw,sync)
    				

    注意,要通過NFS4共享一個目錄,必須使用 fsid=0 的參數,使用fsid=0選項的時候只能共享一個目錄,這個目錄將成為NFS伺服器的根目錄。

  2. 啟動NFS,v4 不需要rpcbind

    service rpcbind stop
    service rpcidmapd stop
    service nfs restart
    service nfslock stop
    				
  3. 查看 export 設置

    # exportfs
    /www          	172.16.1.2/32
    /www/logs     	172.16.1.0/24
    				
  4. mount NFSv4

    mount -t nfs4 172.16.1.15:/logs /mnt
    				

15.1.1. NFS 防火牆配置

查看NFS正在使用的連接埠

rpcinfo -p localhost			
			

vi /etc/sysconfig/nfs

LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
RQUOTAD_PORT=875
STATD_PORT=662
STATD_OUTGOING_PORT=2020
			
service nfs restart
			
iptables -I INPUT -m state --state NEW -p tcp \
    -m multiport --dport 111,892,2049,32803 -s 192.168.0.0/24 -j ACCEPT
 
iptables -I INPUT -m state --state NEW -p udp \
    -m multiport --dport 111,892,2049,32769 -s 192.168.0.0/24 -j ACCEPT		
			
comments powered by Disqus