Ubuntu下搭建nfs服务器

安装方法

安装nfs服务版

# sudo apt-get install nfs-kernel-server

修改nfs配置文件

# sudo vi /etc/exports
/nfs *(rw,sync,insecure)

根目录下建立nfs的目录

# sudo mkdir /nfs
# chmod 777 -R /nfs

常用的命令

挂载命令

# mount -o nolock 192.168.1.100:/nfs /mnt/nfs

或者

# mount -t nfs -o nolock 192.168.1.100:/nfs /mnt/nfs

nfs start/stop/restart

# /etc/init.d/nfs-kernel-server restart
# /etc/init.d/nfs-kernel-server start
# /etc/init.d/nfs-kernel-server stop

常见问题

1、没有访问权限

# ls /mnt/nfs/
ls: can't open '/mnt/nfs/': Permission denied

出现这种情况时,需要给服务端的配置增加no_root_squash选项,参考配置如下:

$ cat /etc/exports 
# /etc/exports: the access control list for filesystems which may be exported
#        to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#

/nfs *(rw,sync,insecure,no_root_squash)

配置更改之后,执行如下的指令:

$ sudo exportfs -a
exportfs: /etc/exports [2]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/nfs".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

你可能感兴趣的:(nfs)