您的位置:首页 > 理论基础 > 计算机网络

NFS网络文件系统的搭建

2016-12-04 14:08 651 查看

NFS网络文件系统的搭建

什么是NFS网络文件系统?

NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。
在linux中,NFS主要用来做网络数据共享的。NFS网络文件一般被用来存储共享视屏、图片、附件等静态的资源文件。
由于NFS在linux中端口并不是固定的,所以很难确定NFS使用的是哪些端口。所以就需要RPC协议来扮演客户机与服务端中间人的作用。

如何配置NFS服务?

用户访问NFS服务器的文件时,需要通过RPC服务才能找到NFS对应的端口,有了端口之后才能取访问NFS的本地磁盘。

1、 服务器端和客户端开启RPC服务(C5:portmap、C6:rpcbind)

2、 服务器端启动nfs服务。

3、 客户端请求NFS服务。

4、 RPC服务返回给客户端相应的NFS端口。

5、 客户端拥有了NFS端口,找到NFS服务。

开启nfs软件包

至少需要两个软件包,一个是NFS的主程序包nfs-utils,还有个是rpc服务的软件包rcpbind(c6)。

具体的实施过程如下。

将远端的nfs服务器上的/data文件夹共享。
服务端:检查系统版本号、NFS和RPC服务。
[root@ritchie ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@ritchie ~]# rpm -qa nfs-utils protmap rpcbind
rpcbind-0.2.0-12.el6.x86_64
nfs-utils-1.2.3-70.el6_8.2.x86_64
[root@ritchie ~]# service iptables stop
[root@ritchie ~]# chkconfig iptables off
检查NFS包或者RPC服务包没有,则需要安装nfs-util包和rpcbind包或者直接安装NFS file system 包组
[root@ritchie ~]# yum install nfs-util rpcbind -y
[root@ritchie ~]# yum groupinstall "NFS file system" –y
编辑NFS的配置文件。/etc/exprots文件。
[root@ritchie ~]# cat >>/etc/exports <<EOF
> #shared data for bbs by ALin 20161214
> /data 192.168.113.0/24(rw,sync)
> EOF
开启rpc服务和重启或平滑重启nfs服务。
[root@ritchie ~]# /etc/init.d/rpcbind restart
[root@ritchie ~]# /etc/init.d/nfs reload
[root@ritchie ~]# /etc/init.d/nfs restart
检查是否配置成功。
[root@ritchie ~]# showmount -e localhost
Export list for localhost:
/data 192.168.113.0/24
设置RPC协议和NFS服务永久开机启动
[root@ritchie ~]# chkconfig rpcbind on
[root@ritchie ~]# chkconfig nfs on
客户端:检查系统版本、RPC服务包,并启动RPC服务。
[root@moban ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@moban ~]# uname -a
Linux moban 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@moban ~]# rpm -qa rpcbind
rpcbind-0.2.0-12.el6.x86_64
[root@moban ~]# /etc/init.d/rpcbind restart
查看远端是否开启nfs服务。
[root@moban ~]# showmount -e 192.168.113.131
Export list for 192.168.113.131:
/data 192.168.113.0/24
将远端服务器的/data文件夹挂载到本地/mnt。
格式:mount –t [文件类型] [目标ip地址:目标文件夹] [本地文件夹]
[root@moban ~]# mount -t nfs 192.168.113.131:/data /mnt
在服务器端更改/data属主和属组并在客户端读写测试。
[root@ritchie ~]# chown nfsnobody.nfsnobody /data
[root@moban mnt]# touch clientNFStest.txt
[root@moban mnt]# ll nfsTest.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 Dec 3 18:52 nfsTest.txt

测试成功!最后将开机挂载nfs服务器设为开机自启动。
[root@moban mnt]# cat >>/etc/rc.local<<EOF
> #nfs/data dir
> mount -t nfs 192.168.113.131:/data /mnt
> EOF
[root@moban mnt]# tail -2 /etc/rc.local
#nfs/data dir
mount -t nfs 192.168.113.131:/data /mnt
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  服务 NFS 网络文件