首页 > 代码库 > NFS

NFS

[root@nfs-server ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[root@nfs-server ~]# uname -ra
Linux nfs-server 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

[root@nfs-server ~]# rpm -aq nfs-utils rpcbind
[root@nfs-server ~]# yum install nfs-utils rpcbind

[root@nfs-server ~]# rpm -aq nfs-utils rpcbind
nfs-utils-1.2.3-75.el6.x86_64
rpcbind-0.2.0-13.el6_9.x86_64


[root@nfs-server ~]# /etc/init.d/rpcbind status
rpcbind is stopped

[root@nfs-server ~]# /etc/init.d/rpcbind start
Starting rpcbind:                                          [  OK  ]
[root@nfs-server ~]# /etc/init.d/rpcbind status
rpcbind (pid  1634) is running...

[root@nfs-server ~]# lsof -i :111
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 1634  rpc    6u  IPv4  12217      0t0  UDP *:sunrpc
rpcbind 1634  rpc    8u  IPv4  12220      0t0  TCP *:sunrpc (LISTEN)
rpcbind 1634  rpc    9u  IPv6  12222      0t0  UDP *:sunrpc
rpcbind 1634  rpc   11u  IPv6  12225      0t0  TCP *:sunrpc (LISTEN)

[root@nfs-server ~]# netstat -lntup|grep rpcbind
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1634/rpcbind       
tcp        0      0 :::111                      :::*                        LISTEN      1634/rpcbind       
udp        0      0 0.0.0.0:961                 0.0.0.0:*                               1634/rpcbind       
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               1634/rpcbind       
udp        0      0 :::961                      :::*                                    1634/rpcbind       
udp        0      0 :::111                      :::*                                    1634/rpcbind       

[root@nfs-server ~]# chkconfig  --list rpcbind
rpcbind         0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@nfs-server ~]# rpcinfo -p localhost
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper

[root@nfs-server ~]# /etc/init.d/nfs status
rpc.svcgssd is stopped
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped

[root@nfs-server ~]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]

[root@nfs-server ~]# /etc/init.d/nfs status
rpc.svcgssd is stopped
rpc.mountd (pid 1747) is running...
nfsd (pid 1763 1762 1761 1760 1759 1758 1757 1756) is running...
rpc.rquotad (pid 1742) is running...

[root@nfs-server ~]# netstat -lntup|grep 2049  
tcp        0      0 0.0.0.0:2049                0.0.0.0:*                   LISTEN      -                  
tcp        0      0 :::2049                     :::*                        LISTEN      -                  
udp        0      0 0.0.0.0:2049                0.0.0.0:*                               -                  
udp        0      0 :::2049                     :::*                                    -                  
[root@nfs-server ~]# rpcinfo -p localhost
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100011    1   udp    875  rquotad
    100011    2   udp    875  rquotad
    100011    1   tcp    875  rquotad
    100011    2   tcp    875  rquotad
    100005    1   udp  35857  mountd
    100005    1   tcp  35831  mountd
    100005    2   udp  47857  mountd
    100005    2   tcp  35728  mountd
    100005    3   udp  55499  mountd
    100005    3   tcp  55169  mountd
    100003    2   tcp   2049  nfs
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    2   tcp   2049  nfs_acl
    100227    3   tcp   2049  nfs_acl
    100003    2   udp   2049  nfs
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    2   udp   2049  nfs_acl
    100227    3   udp   2049  nfs_acl
    100021    1   udp  42835  nlockmgr
    100021    3   udp  42835  nlockmgr
    100021    4   udp  42835  nlockmgr
    100021    1   tcp  56192  nlockmgr
    100021    3   tcp  56192  nlockmgr
    100021    4   tcp  56192  nlockmgr

[root@nfs-server ~]# chkconfig nfs on
[root@nfs-server ~]# chkconfig --list nfs
nfs             0:off 1:off 2:on 3:on 4:on 5:on 6:off

 
[root@nfs-server ~]#  vi /etc/rc.local

 

添加

###
/etc/init.d/rpcbind start
###
/etc/init.d/nfs start

 

编辑共享目录

[root@nfs-server ~]# vi /etc/exports
/data   192.168.31.0/24(rw,sync)

创建目录

mkdir /data

授权目录

chown -R nfsnobody /data
                         

 

客户端 挂载

[root@lnmp02 ~]# mount -t nfs 192.168.31.29:/data /mnt

 

showmount -e 192.168.31.29

[root@lnmp02 ~]# showmount -e 192.168.31.29
Export list for 192.168.31.29:
/data 192.168.31.0/24
[root@lnmp02 ~]# ls -l /mnt/
total 24
drwxr-xr-x 2 nfsnobody nfsnobody 4096 Jun 12 13:27 li
-rw-r--r-- 1 nfsnobody root        22 Jun 12 13:17 li.txt
drwxr-xr-x 2 nfsnobody nfsnobody 4096 Jun 12 13:26 liweiming
drwxr-xr-x 2 nfsnobody nfsnobody 4096 Jun 12 15:13 mnt
drwxr-xr-x 2 nfsnobody nfsnobody 4096 Jun 12 15:18 nfs-server
drwxr-xr-x 3 nfsnobody nfsnobody 4096 Jun 12 13:30 www
[root@lnmp02 ~]#

[root@lnmp02 ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda3             19G  1.5G   17G   9% /
tmpfs                238M     0  238M   0% /dev/shm
/dev/sda1            190M   36M  145M  20% /boot
192.168.31.29:/data   19G  1.5G   17G   9% /mnt

 

NFS