Ubuntu上NFS的安装配置,启用nfs功能

来源:互联网 发布:猎枪火药在淘宝叫什么 编辑:程序博客网 时间:2024/04/26 19:03
NFS用于Linux主机访问网络中其他Linux主机上的共享资源。NFS的原理是在客户端上通过网络将远程主机共享文件系统以挂载(Mount)的方式加入本机的文件系统,之后的操作就如同在本机上一样。

 

NFS服务器(宿主机)

 

1.安装NFS

Ubuntu上默认是没有安装NFS服务器的,首先要安装NFS服务程序:
$ sudo apt-get install nfs-kernel-server


(安装nfs-kernel-server时,apt会自动安装nfs-common和portmap)
这样,宿主机就相当于NFS Server。


1.服务器端:sudo apt-get install portmap

2.服务器端:sudo apt-get install nfs-kernel-server

3.客户端:sudo apt-get install nfs-common

 

2. 配置NFS
1)配置portmap

方法1: 编辑/etc/default/portmap, 将 -i 127.0.0.1 去掉.

方法2:             

$ sudo dpkg-reconfigure portmap

对Should portmap be bound to the loopback address? 选N.

2)配置/etc/hosts.deny

$ sudo gedit /etc/hosts.deny
(禁止任何host(主机)能和你的NFS服务器进行NFS连接),加入:
### NFS DAEMONS
portmap:ALL
lockd:ALL
mountd:ALL
rquotad:ALL
statd:ALL

 

3) /etc/hosts.allow

$ sudo gedit /etc/hosts.allow
允许那些你想要的主机和你的NFS服务器建立连接。下列步骤将允许任何IP地址以192.168.1开头的主机(连接到NFS服务器上),也可以指定特定的IP地址。
### NFS DAEMONS
portmap: 192.168.1.
lockd: 192.168.1.
rquotad: 192.168.1.
mountd: 192.168.1.
statd: 192.168.1.

 

        蓝色文字可略过

 

起用保护机制
    
上面设置了只要在192.168.1.*这个网段的所有IP地址用户都可以访问共享目录,但我只想让一个IP地址访问,比如 192.168.1.101那么就可以这样设置了。
可以通过设定/etc/hosts.deny/etc/hosts.allow文件来限制网络服务的存取权限。

***/etc/hosts.deny***
portmap:ALL
lockd:ALL
mountd:ALL
rquotad:ALL
statd:ALL


***/etc/hosts.allow***
portmap:192.168.1.101
lockd:192.168.1.101
mountd:192.168.1.101
rquotad:192.168.1.101
statd:192.168.1.101

    

      同时使用这两个文件就会使得只有ip192.168.1.101的机器使用NFS服务。你的target boardip地址设定为192.168.1.101,这样就可以了。

    
/etc/hosts.deny  /etc/hosts.allow 设置对portmap的访问采用这两个配置文件有点类似"mask"的意思现在/etc/hosts.deny中禁止所有用户对portmap的访问再在/etc/hosts.allow 中允许某些用户对portmap的访问。

 

4)重启portmap daemon

     每次对/etc/hosts.deny  /etc/hosts.allow两文件的修改后都要重启portmap daemon。不然修改无效。

$ sudo /etc/init.d/portmap restart

 

5)配置/etc/exports
    NFS挂载目录及权限由/etc/exports文件定义。

$sudo gedit /etc/exports
    比如我要将将我的home目录中的/home/lin/NFSshare目录让192.168.1.*的IP共享, 则在该文件末尾添加下列语句:
        /home/lin/NFSshare  192.168.1.*(rw,sync,no_root_squash)

      然后保存退出。

/home/lin/NFSshare就表示共享目录,当然,你可以随便换成自己喜欢的目录。

192.168.1.:前面三位是你主机(NFS客户端)的ip地址(本机终端ifconfig命令就可以获得本机的ip地址)。
rw/写权限,只读权限的参数为ro
sync
:数据同步写入内存和硬盘,也可以使用async,此时数据会先暂存于内存中,而不立即写入硬盘。

no_root_squashNFS 服务器共享目录用户的属性,如果用户是 root,那么对于这个共享目录来说就具有 root 的权限。

 

6)重启nfs服务

$ sudo /etc/init.d/nfs-kernel-server restart

7)showmount查看共享目录

showmout

-a :这个参数是一般在NFS SERVER上使用,是用来显示已经mount上本机nfs目录的clinet机器。

-e :显示指定的NFS SERVER上export出来的目录。

0 0
原创粉丝点击