Linux NFS搭建

简介: 一、NFS简介NFS是Network File System的缩写,即网络文件系统。一种使用于分散式文件协定,有SUN公司开发。功能是通过网络让不同的机器、不同的操作系统能够分享个人数据,让应用程序通过网络可以访问位于服务器磁盘中的数据。

一、NFS简介

NFS是Network File System的缩写,即网络文件系统。一种使用于分散式文件协定,有SUN公司开发。功能是通过网络让不同的机器、不同的操作系统能够分享个人数据,让应用程序通过网络可以访问位于服务器磁盘中的数据。

NFS在文件传送或信息传送的过过程中,依赖于RPC协议。RPC,远程过程调用(Remote Procedure Call),是使客户端能够执行其他系统中程序的一种机制。NFS本身是没有提供信息传输的协议和功能的,但NFS却能让我们通过网络进行资料的分享,就是因为NFS使用了RPC提供的传输协议,可以说NFS就是使用PRC的一个程序。

NFS服务端、RPC协议、客户端三者可以理解为房源、中介、租客之间的关系:

img_909e848cc17f275c2dfa209f39a39711.png

二、系统环境

 CentOS release 6.7 (Final)  2.6.32-573.el6.i686

NFS IP:172.16.1.31

web IP : 172.16.1.8

/etc/init.d/iptables status

iptables:未运行防火墙

SElinux  :getenforce  Permissive

三、开始搭建

1)软件安装,NFS只需要安装两个软件,在通常情况下是作为系统默认软件安装的

【rpcbind】centos 下面RPC主程序

【nfs-utils】NFS服务主程序,包括NFS的基本命令和监控程序

[root@nfs01 ~]# yum install rpcbind nfs-utils

2)开启RCP服务

[root@nfs01 ~]# /etc/init.d/rpcbind start 

查看rpcbind服务端口

[root@nfs01 ~]# netstat -antlp|grep rpcbind

tcp        0      0 0.0.0.0:111                0.0.0.0:*                  LISTEN      1368/rpcbind

查看此时rpc服务上面是否有端口注册

[root@nfs01 ~]# rpcinfo -p localhost

program vers proto  port  service

100000    4  tcp    111  portmapper

100000    3  tcp    111  portmapper

100000    2  tcp    111  portmapper

100000    4  udp    111  portmapper

100000    3  udp    111  portmapper

100000    2  udp    111  portmapper

3)开启NFS服务

[root@nfs01 ~]# /etc/init.d/nfs start 

现在rpc上应该能看到好多新被注册的nfs端口了

[root@nfs01 ~]# rpcinfo -p localhost 

100003    2  tcp  2049  nfs

100003    3  tcp  2049  nfs

100003    4  tcp  2049  nfs

100227    2  tcp  2049  nfs_acl

100227    3  tcp  2049  nfs_acl

设置两个服务开机自启动

[root@nfs01 ~]# chkconfig rpcbind on

[root@nfs01 ~]# chkconfig nfs on

4)服务端配置共享目录(/data)

配置前确认rpcbind、nfs服务进程正常

[root@nfs01 ~]# /etc/init.d/nfs status

[root@nfs01 ~]# /etc/init.d/rpcbind status

[root@nfs01 ~]# ps -ef|egrep "rpc|nfs" 

rpc      1368    1  0 00:14 ?        00:00:00 rpcbind

rpcuser  1391    1  0 00:14 ?        00:00:00 rpc.statd

root      1440    2  0 00:14 ?        00:00:00 [rpciod/0]

root      1449    1  0 00:14 ?        00:00:00 rpc.rquotad

root      1454    1  0 00:14 ?        00:00:00 rpc.mountd

root      1461    2  0 00:14 ?        00:00:00 [nfsd4]

root      1462    2  0 00:14 ?        00:00:00 [nfsd4_callbacks]

root      1463    2  0 00:14 ?        00:00:00 [nfsd]

root      1464    2  0 00:14 ?        00:00:00 [nfsd]

root      1465    2  0 00:14 ?        00:00:00 [nfsd]

root      1466    2  0 00:14 ?        00:00:00 [nfsd]

创建共享目录并授权("nfsnobody")

 #nfsnobody 用户是开启rpc、nfs进程后系统自动创建的

[root@nfs01 ~]# mkdir /data

[root@nfs01 ~]# chown -R nfsnobody.nfsnobody /data 

修改服务端配置文件(/etc/exports)

[root@nfs01 ~]# vim /etc/exports

#share /data by oldboy for bingbing at 20160524

/data 172.16.1.0/24(rw,sync)

####

/data1 172.16.1.0/24(rw,sync,all_squash,anonuid=65534,anongid=65534)

注意!

#此时可以修改“anonuid”值来修改NFS默认虚拟用户,前提是用户在系统中存在,可以指定“-s /sbin/nologin”

查看系统加载的配置

[root@nfs01 ~]# cat /var/lib/nfs/etab 

/data  172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)

重新平滑加载服务


[root@nfs01 ~]# /etc/init.d/nfs reload

确认服务、目录等配置正确,共享成功

[root@nfs01 ~]# showmount -e 

Export list for nfs01:

/data  172.16.1.0/24

5)客户端配置

客户端只需要安装rpcbind程序,并确认服务正常

[root@web01 ~]# /etc/init.d/rpcbind status

rpcbind (pid  1361) 正在运行...

挂载nfs共享目录

[root@web01 ~]# mount -t nfs 172.16.1.31:/data /mnt

[root@web01 ~]# df -h

Filesystem        Size Used Avail Use% Mounted on

/dev/sda3          6.9G 1.3G  5.2G  20% /

tmpfs              503M    0 503M  0% /dev/shm

/dev/sda1          190M  33M  147M  19% /boot

172.16.1.31:/data  6.9G 1.3G  5.2G  20% /mnt

开机自动挂载

echo "mount -t nfs172.16.1.31:/data /mnt">>/etc/rc.local

另外,实现NFS共享自动挂载也可以在/ets/fstab里实现,不过此时要系统开启netfs服务

因为有可能在系统在重启过程中,先实现挂载,后启动网络,此时出现挂载不成功问题

img_63e4cb07d2cbc5bb4b488aafc6ebfe49.png

开启netfs服务

[root@web01 ~]# chkconfig netfs on

目录
相关文章
|
5月前
|
Linux
Linux安装NFS挂载NFS卸载客户端服务端都有
Linux安装NFS挂载NFS卸载客户端服务端都有
124 0
|
5月前
|
Ubuntu 网络协议 Unix
【Linux】新唐NUC977挂载NFS实现网络文件传输
【Linux】新唐NUC977挂载NFS实现网络文件传输
|
5月前
|
Linux Shell Windows
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
350 0
|
2月前
|
Ubuntu Linux
内核实验(四):Qemu调试Linux内核,实现NFS挂载
本文介绍了在Qemu虚拟机中配置NFS挂载的过程,包括服务端的NFS服务器安装、配置和启动,客户端的DHCP脚本添加和开机脚本修改,以及在Qemu中挂载NFS、测试连通性和解决挂载失败的方法。
50 0
内核实验(四):Qemu调试Linux内核,实现NFS挂载
|
2月前
|
运维 Ubuntu 安全
在Linux中,如何配置NFS共享?
在Linux中,如何配置NFS共享?
|
2月前
|
网络协议 Ubuntu Linux
在Linux中,如何使用NFS和Samba共享文件和目录?
在Linux中,如何使用NFS和Samba共享文件和目录?
|
2月前
|
网络协议 Unix Linux
Linux 多种方式实现文件共享(三)NFS 6
【8月更文挑战第6天】NFS 即网络文件系统,是一种使用于分布式文件系统的协议,NFS 功能是通过网络让不同的机器,不同的操作系统能够彼此分享各自的数据,让应用程序在客户端通过网络访问位于服务器磁盘中的数据
68 13
|
2月前
|
存储 Linux 网络安全
[linux]搭建nfs
[linux]搭建nfs
|
2月前
|
存储 Linux 网络安全
【Azure 存储服务】如何把开启NFS 3.0协议的Azure Blob挂载在Linux VM中呢?(NFS: Network File System 网络文件系统)
【Azure 存储服务】如何把开启NFS 3.0协议的Azure Blob挂载在Linux VM中呢?(NFS: Network File System 网络文件系统)
|
2月前
|
Ubuntu Linux 网络安全
在Linux中,如何配置Samba或NFS文件共享?
在Linux中,如何配置Samba或NFS文件共享?
下一篇
无影云桌面