如何配置Ubuntu nfs安装服务版

54次阅读
没有评论

共计 3351 个字符,预计需要花费 9 分钟才能阅读完成。

这篇文章给大家分享的是有关如何配置 Ubuntu nfs 安装服务版的内容。丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,一起跟随丸趣 TV 小编过来看看吧。

1、安装 Ubuntu nfs 服务版
apt-get install Ubuntu nfs-kernel-server
2、修改 nsf 配置文件
vi /etc/exports
在文件中添加 Ubuntu nfs 的目录格式如下
/armUbuntu nfs *(sync,rw,no_root_squash)// 在我的实验中 /armUbuntu nfs 因为 touchscreen 所在目录 /home/wangwei/work/touchscreen
存盘退出
3、在根目录下建立 nsf 的目录
mkdir /arm nfs 修改该目录的权限 chmod 777 -R /arm nfs
4、从新启动 Ubuntu nfs
/etc/init.d/Ubuntu nfs-kernel-server restart
5、测试 nsf
mount 192.168.1.99:/arm nfs/ abc

Ubuntu nfs(Network File System, 网络文件系统)可以通过网络将分享不同主机 (不同的 OS) 的目录——可以通过 Ubuntu nfs 挂载远程主机的目录, 访问该目录就像访问本地目录一样!
一般而言, 使用 Ubuntu nfs 能够方便地使各 unix-like 系统之间实现共享. 但如果需要在 unix-like 和 windows 系统之间共享, 就得使用 samba 了!
Ubuntu nfs 运行在 SUN 的 RPC(Remote Procedure Call, 远程过程调用)基础上, RPC 定义了一种与系统无关的方法来实现进程间通信. 由此, Ubuntu nfs server 也可以看作是 RPC server.

正因为 Ubuntu nfs 是一个 RPC 服务程序, 所以在使用它之前, 先要映射好端口——通过 portmap 设定. 比如: 某个 Ubuntu nfs client 发起 Ubuntu nfs 服务请求时, 它需要先得到一个端口 (port). 所以它先通过 portmap 得到 port number. (不仅 Ubuntu nfs, 所有的 RPC 服务程序启动之前, 都需要设定好 portmap)
与 Ubuntu nfs 相关的几个文件, 命令
1, /etc/exports
对 Ubuntu nfs 卷的访问是由 exports 来批准, 它枚举了若干有权访问 Ubuntu nfs 服务器上文件系统的主机名.

2, /sbin/exportfs
维护 Ubuntu nfs 的资源共享. 可以通过它重新设定 /etc/exports 的共享目录, 卸载 Ubuntu nfs Server 共享的目录或者重新共享等.

3, /usr/sbin/showmount
用在 Ubuntu nfs Server 端,而 showmount 则主要用在 Client 端. showmount 可以用來查看 Ubuntu nfs 共享的目录资源.

4, /var/lib/Ubuntu nfs/xtab
Ubuntu nfs 的记录文档: 通过它可以查看有哪些 Client 连接到 Ubuntu nfs 主机的记录.

下面这几个并不直接负责 Ubuntu nfs, 实际上它们负责所有的 RPC
5, /etc/default/portmap
实际上, portmap 负责映射所有的 RPC 服务端口, 它的内容非常非常之简单(后面详述)

6, /etc/hosts.deny
设定拒绝 portmap 服务的主机

7, /etc/hosts.allow
设定允许 portmap 服务的主机
安装 Ubuntu nfs
Debian/Ubuntu 上默认是没有安装 Ubuntu nfs 服务器的,首先要安装 Ubuntu nfs 服务程序:
$ sudo apt-get install nfs-kernel-server
(安装 nfs-kernel-server 时,apt 会自动安装 nfs-common 和 portmap)
这样,宿主机就相当于 nfs Server。

同样地,目标系统作为 Ubuntu nfs 的客户端,需要安装 Ubuntu nfs 客户端程序。如果是 Debian/Ubuntu 系统,则需要安装 nfs-common。
$ sudo apt-get install nfs-commmon
nfs-common 和 nfs-kernel-server 都依赖于 portmap!

配置 Ubuntu nfs
配置 portmap

方法 1: 编辑 /etc/default/portmap, 将 -i 127.0.0.1 去掉.
方法 2: $ sudo dpkg-reconfigure portmap , 对 Should portmap be bound to the loopback address? 选 N.

配置 /etc/hosts.deny
(禁止任何 host(主机)能和你的 Ubuntu nfs 服务器进行 Ubuntu nfs 连接),加入:
Ubuntu nfs DAEMONS

portmap:ALL
lockd:ALL
mountd:ALL
rquotad:ALL
statd:ALL

配置 /etc/hosts.allow
允许那些你想要的主机和你的 Ubuntu nfs 服务器建立连接。下列步骤将允许任何 IP 地址以 192.168.2 开头的主机(连 接到 Ubuntu nfs 服务器上),也可以指定特定的 IP 地址。参看 man 页 hosts_access(5), hosts_options(5)。加入:
Ubuntu nfs DAEMONS
portmap: 192.168.2.
lockd: 192.168.2.
rquotad: 192.168.2.
mountd: 192.168.2.
statd: 192.168.2.

/etc/hosts.deny 和 /etc/hosts.allow 设置对 portmap 的访问. 采用这两个配置文件有点类似 mask 的意思. 现在 /etc/hosts.deny 中禁止所有用户对 portmap 的访问. 再在 /etc/hosts.allow 中允许某些用户对 portmap 的访问.
运行 $ sudo /etc/init.d/portmap restart 重启 portmap daemon.

配置 /etc/exports
Ubuntu nfs 挂载目录及权限由 /etc/exports 文件定义

比如我要将将我的 home 目录中的 /home/zp/share 目录让 192.168.2.* 的 IP 共享, 则在该文件末尾添加下列语句:
/home/zp/share  192.168.2.*(rw,sync,no_root_squash)
或者:/home/zp/share  192.168.2.0/24(rw,sync,no_root_squash)

192.168.2.* 网段内的 Ubuntu nfs 客户端能够共享 Ubuntu nfs 服务器 /home/zp/share 目录内容. 且有读, 写权限, 并且该用户进入 /home/zp/share 目录后的身份为 root
*** 加上 sync, 否则 $ sudo exportfs -r 时会给出警告, sync 是 Ubuntu nfs 的默认选项.

(运行 $ showmount -e 查看 nfs server 的 export list. 若更改了 /etc/exports, 运行 $ sudo exportfs -r 更新运行 $ sudo /etc/init.d/nfs-kernel-server restart 重启 Ubuntu nfs 服务)
/etc/exports 实际上就是 Ubuntu nfs 服务器的核心配置文件了. 鸟哥的 Linux 私房菜 列举了一些 exports 文件的写法.

测试 Ubuntu nfs
可以尝试一下挂载本地磁盘 (假设本地主机 IP 地址为:192.128.2.1,将 /home/zp/share 挂载到 /mnt)
$ sudo mount 192.168.2.1:/home/zp/share /mnt
运行 $ df 看看结果
$ sudo umount /mnt
注意被拷贝文件的读/写权限!
另外, 可以使用一定的参数:
使用加参数的办法:mount -o nolock,rsize=1024,wsize=1024,timeo=15 192.168.2.130:/tmp/ /tmp/

感谢各位的阅读!关于“如何配置 Ubuntu nfs 安装服务版”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-25发表,共计3351字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)