NFS(Network File System)

NFS(Network File System)

即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。

一、准备阶段:(客户端和服务端)

[root@NFS-server ~]# cat /etc/redhat-release #查看系统版本
[root@NFS-server ~]# uname -r #查看系统内核版本
[root@NFS-server ~]# uname -m #查看系统是否64位

二、NFS服务端所需的软件列表

nfs-utils: 这个是NFS服务主程序(包含rpc.nfsd、rpc.mountd、daemons)
rpcbind: 这个是CentOS6.X的RPC主程序(CentOS5.X的为portmap)

三、检查软件是否安装

[root@NFS-server ~]# rpm -qa nfs-utils rpcbind #检查安装的软件包
<如果没有安装在系统中通过yum 命令进行安装以上两个包>
[root@NFS-server ~]# yum install -y nfs-utils rpcbind #安装上述所需的两个软件包

四、启动NFS服务端相关服务

---启动rpcbind服务

[root@NFS-server ~]# /etc/init.d/rpcbind status  #查询rpcbind服务状态并启动
[root@NFS-server ~]# LANG=en
[root@NFS-server ~]# lsof -i :111 #查询rpcbind监听状态 (111是rpcbind的主端口)
[root@NFS-server ~]# netstat -lntup |grep rpcbind #查询rpcbind服务启动状态 (同lsof查询端口效果一样)
[root@NFS-server ~]# chkconfig --list rpcbind #检查rpcbind自启动情况
[root@NFS-server ~]# rpcinfo -p localhost #查看NFS服务项rpc服务器注册的端口信

---启动NFS服务

[root@NFS-server ~]# /etc/init.d/nfs status #查看NFS服务并启动
[root@NFS-server ~]# netstat -lntup|grep nfs #查看NFS端口启动(FNS默认端口为2049)
[root@NFS-server ~]# lsof -i :2049 #查看NFS端口启动(FNS默认端口为2049)
[root@NFS-server ~]# netstat -lntup|grep 2049 #查看NFS端口启动(FNS默认端口为2049)
[root@NFS-server ~]# rpcinfo -p localhost #启动NFS过后rpcbind服务已经启用了对FNS的端口映射
[root@NFS-server ~]# chkconfig --list nfs #查看nfs的开机自启动情况
[root@NFS-server ~]# chkconfig nfs on #让FNS开机自启动

由于在FNS服务过程中,必须先启动rpcbind,再启动nfs,这样才能让NFS在rpcbind上注册成功

[root@NFS-server ~]# less /etc/init.d/rpcbind #查看rpcbind服务启动详情
[root@NFS-server ~]# less /etc/init.d/nfs  #同理我们查看nfs服务的自启动详情
[root@NFS-server ~]# ps -ef |egrep "rpc|nfs" #查看nfs相进程

五、配置NFS服务端

前面介绍了NFS的启动,接下来我们配置NFS服务端的配置
/etc/exports 是NFS程序的配置文件。并且默认为空
/etc/exports文件的配置格式为:
NFS共享目录 NFS客户端地址1(参数1,参数2,参数3......) 客户端地址2(参数1,参数2,参数3......)
NFS共享目录 NFS客户端地址(参数1,参数2,参数3......)
配置完成exports后平滑重启NFS服务 ,下面两条命令等同
[root@NFS-server ~]# /etc/init.d/nfs reload
[root@NFS-server ~]# exportfs -r
[root@NFS-server ~]# cat /var/lib/nfs/etab #查看一条配置的详细信息
[root@NFS-server ~]# showmount -e 127.0.0.1 #查看本机挂载情况
[root@NFS-server ~]# mount -t nfs 192.168.1.5:/data /mnt #在本机测试挂载

六、配置NFS客户端

客户端也需要安装rpcbind和nfs-utils软件,并且设置开机自启动。(只需要启动rpcbind即可)
然后再进行如下操作
 

总结NFS服务的配置过程:

--服务端--

1.安装软件
yum install -y nfs-utils rpcbind
2.启动服务(先启动rpcbind)
/etc/init.d/rpcbind start
/etc/init.d/nfs start
3.设置开机自启动
chkconfig nfs on
chkconfig rpcbind on
或者修改rc.local
4.配置NFS服务
echo "/data 192.168.1.0/24(rw,sync)"
mkdir -p /data
chown -R nfsnobody.nfsnobody /data
5.重新加载服务
/etc/init.d/nfs reload 或者 exportfs -r
6.检查或测试挂载
showmount -e localhost
mount -t nfs 192.168.1.0:/data /mnt
 

--客户端-

1.安装软件
yum install -y nfs-utils rpcbind
2.启动rpcbind
/etc/init.d/rpcbind start
3.配置开机自启动
chkconfig rpcbind on
或者修改rc.local
4.测试服务端共享情况
showmount -e 192.168.1.5
5.挂载
mkdir -p /data
mount -t nfs 192.168.1.5:/data /data
6.测试是否有读写权限
-------------------------------------------------------------------------------------------

常见错误

1.df -h 检查服务端的NFS服务是不是启动成功,
2.确认NFS客户端showmount是否OK。
3.确认rpcbind上是否有NFS注册,(rpcbind必须先启动)
3.确认网络是否通畅
4.确认是否因为防火墙挡住(一般内网不需要开启防火墙,在出口加防火墙就够了)
5不要把挂载命令放在fstab,因为fstab比网络先启动,会出现挂载不上网络NFS
-----------------------------------------------------------------------------------------
源:http://www.cnblogs.com/alonones/p/6105586.html
 


posted @ 2017-06-30 09:12  zk-ing  阅读(273)  评论(0编辑  收藏  举报