NFS服务器搭建 unbuntu14.04

1. 查看是否有NFS服务
hduser@master:/home/nfs-free$ sudo /etc/init.d/nfs-kernel-server status
[sudo] password for hduser: 
nfsd running
2. 如果没有安装
apt-get install nfs-kernel-server nfs-common 
3. 启动NFS服务器
hduser@master:/home/nfs-free$ sudo /etc/init.d/nfs-kernel-server start
 * Exporting directories for NFS kernel daemon...                        [ OK ] 
 * Starting NFS kernel daemon                                            [ OK ] 
hduser@master:/home/nfs-free$ 
4. 创建挂载目录
    a. 在挂载目录中写入共享文件
5. 修改/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)
#
第二列:可访问主机
192.168.152.13 指定IP地址的主机 
nfsclient.test.com 指定域名的主机 
192.168.1.0/24 指定网段中的所有主机 
*.test.com        指定域下的所有主机 
*                       所有主机

来自 <http://www.linuxidc.com/Linux/2012-05/61527.htm> 
最好在/etc/exports中的权限中加入no_subtree_check,可以提高传输率

6. 本地挂载
hduser@master:/home/nfs-free$ sudo mount -t nfs master:/home/nfs-free /mnt
hduser@master:/home/nfs-free$ cd /mnt
hduser@master:/mnt$ ls
free.txt
7. 在客户端查看共享目录
hduser@data1:/mnt$ showmount -e 192.168.56.100
Export list for 192.168.56.100:
/home/nfs-free data1
hduser@data1:/mnt$ showmount -e master
Export list for master:
/home/nfs-free data1
8. 挂载目录
hduser@data1:/mnt$ sudo mount master:/home/nfs-free /mnt
[sudo] password for hduser: 
mount.nfs: /mnt is busy or already mounted
hduser@data1:/mnt$ ls
free.txt  free.txt~
9. 查看NFS状态
hduser@data1:/mnt$ mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/cgroup type tmpfs (rw)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
none on /sys/fs/pstore type pstore (rw)
tracefs on /var/lib/ureadahead/debugfs/tracing type tracefs (rw,relatime)
rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)
systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd)
gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,user=hduser)
/dev/sr0 on /media/hduser/VBOXADDITIONS_5.1.8_111374 type iso9660 (ro,nosuid,nodev,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2)
master:/home/nfs-free on /mnt type nfs (rw,vers=4,addr=192.168.56.100,clientaddr=192.168.56.101)
gvfsd-fuse on /home/hduser/.gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev)
hduser@data1:/mnt$ mount |grep nfs
master:/home/nfs-free on /mnt type nfs (rw,vers=4,addr=192.168.56.100,clientaddr=192.168.56.101)
10. 对共享目录下的文件操作
hduser@data1:~$ cp /mnt/free.txt ~/Desktop/
11. 开机自动挂载
    修改/etc/fstab
    ubuntu /etc/fstab解析
    原文作者:停下浮躁的心
    原文地址: https://www.jianshu.com/p/6fe39e48c87e
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞