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

1、好处

(1)节省本地存储空间,将常用的数据存放在一台NFS服务器上且可以通过网络访问,那么本地终端将可以减少自身存储空间的使用。

(2)用户不需要在网络中的每台计算机上都建有Home目录,Home目录可以放在NFS服务器上且可以在网络上被访问使用。

(3)一些存储设备如软驱、CDROM和ZIP等都可以在网络上被别的机器使用。这可以减少整个网络上移动介质设备的数量。

2、组成

NFS体系至少有两个主要部分:一台NFS服务器和若干台客户机,如图所示

客户机可以通过TCP/IP网络远程访问存放在NFS上的数据。

NFS实现是通过RPC服务来实现的

实现过程:

(1)NFS RPC的主要功能是记录每个NFS功能所对应的端口号,并将信息传递给请求数据的NFS客户端,从而实现数据的传输。

(2)NFS服务启动时会随机取用数个端口,并主动向RPC服务注册取用的相关端口信息,RPC服务就知道每个端口对应的NFS功能了,然后RPC会用固定的端口(111)来监听NFS客户端的请求,将正确的NFS端口传给NFS的客户端

服务启动顺序:RPC--》NFS

3、服务器端安装,配置过程

(1)检查是否安装NFS RPC服务

[root@localhost ~]# rpm -qa nfs-utils rpcbind
[root@localhost ~]# yum install nfs-utils rpcbind -y
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.7 kB :
extras | 3.4 kB :
extras/primary_db | kB :
updates | 3.4 kB :
Resolving Dependencies
--> Running transaction check
---> Package nfs-utils.x86_64 :1.2.-.el6_9 will be installed
--> Processing Dependency: nfs-utils-lib >= 1.1.- for package: :nfs-utils-1.2.-.el6_9.x86_64
--> Processing Dependency: libtirpc >= 0.2.- for package: :nfs-utils-1.2.-.el6_9.x86_64
--> Processing Dependency: keyutils >= 1.4- for package: :nfs-utils-1.2.-.el6_9.x86_64
--> Processing Dependency: python-argparse for package: :nfs-utils-1.2.-.el6_9.x86_64
--> Processing Dependency: libgssglue.so.(libgssapi_CITI_2)(64bit) for package: :nfs-utils-1.2.-.el6_9.x86_64
--> Processing Dependency: libgssglue for package: :nfs-utils-1.2.-.el6_9.x86_64
--> Processing Dependency: libevent for package: :nfs-utils-1.2.-.el6_9.x86_64
--> Processing Dependency: libtirpc.so.()(64bit) for package: :nfs-utils-1.2.-.el6_9.x86_64
--> Processing Dependency: libnfsidmap.so.()(64bit) for package: :nfs-utils-1.2.-.el6_9.x86_64
--> Processing Dependency: libgssglue.so.()(64bit) for package: :nfs-utils-1.2.-.el6_9.x86_64
--> Processing Dependency: libevent-1.4.so.()(64bit) for package: :nfs-utils-1.2.-.el6_9.x86_64
---> Package rpcbind.x86_64 :0.2.-.el6_9. will be installed
--> Running transaction check
---> Package keyutils.x86_64 :1.4-.el6 will be installed
---> Package libevent.x86_64 :1.4.-.el6 will be installed
---> Package libgssglue.x86_64 :0.1-.el6 will be installed
---> Package libtirpc.x86_64 :0.2.-.el6_9 will be installed
---> Package nfs-utils-lib.x86_64 :1.1.-.el6 will be installed
---> Package python-argparse.noarch :1.2.-2.1.el6 will be installed
--> Finished Dependency Resolution Dependencies Resolved ==============================================================================
Package Arch Version Repository Size
==============================================================================
Installing:
nfs-utils x86_64 :1.2.-.el6_9 updates k
rpcbind x86_64 0.2.-.el6_9. updates k
Installing for dependencies:
keyutils x86_64 1.4-.el6 base k
libevent x86_64 1.4.-.el6 base k
libgssglue x86_64 0.1-.el6 base k
libtirpc x86_64 0.2.-.el6_9 updates k
nfs-utils-lib x86_64 1.1.-.el6 base k
python-argparse noarch 1.2.-2.1.el6 base k Transaction Summary
==============================================================================
Install Package(s) Total download size: k
Installed size: 2.0 M
Downloading Packages:
(/): keyutils-1.4-.el6.x86_64.rpm | kB :
(/): libevent-1.4.-.el6.x86_64.rpm | kB :
(/): libgssglue-0.1-.el6.x86_64.rpm | kB :
(/): libtirpc-0.2.-.el6_9.x86_64.rpm | kB :
(/): nfs-utils-1.2.-.el6_9.x86_64.rpm | kB :
(/): nfs-utils-lib-1.1.-.el6.x86_64.rpm | kB :
(/): python-argparse-1.2.-2.1.el6.noarch.rpm | kB :
(/): rpcbind-0.2.-.el6_9..x86_64.rpm | kB :
------------------------------------------------------------------------------
Total 1.1 MB/s | kB :
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : libgssglue-0.1-.el6.x86_64 /
Installing : libtirpc-0.2.-.el6_9.x86_64 /
Installing : rpcbind-0.2.-.el6_9..x86_64 /
Installing : python-argparse-1.2.-2.1.el6.noarch /
Installing : libevent-1.4.-.el6.x86_64 /
Installing : keyutils-1.4-.el6.x86_64 /
Installing : nfs-utils-lib-1.1.-.el6.x86_64 /
Installing : :nfs-utils-1.2.-.el6_9.x86_64 /
Verifying : rpcbind-0.2.-.el6_9..x86_64 /
Verifying : libtirpc-0.2.-.el6_9.x86_64 /
Verifying : keyutils-1.4-.el6.x86_64 /
Verifying : libevent-1.4.-.el6.x86_64 /
Verifying : nfs-utils-lib-1.1.-.el6.x86_64 /
Verifying : libgssglue-0.1-.el6.x86_64 /
Verifying : :nfs-utils-1.2.-.el6_9.x86_64 /
Verifying : python-argparse-1.2.-2.1.el6.noarch / Installed:
nfs-utils.x86_64 :1.2.-.el6_9 rpcbind.x86_64 :0.2.-.el6_9. Dependency Installed:
keyutils.x86_64 :1.4-.el6 libevent.x86_64 :1.4.-.el6
libgssglue.x86_64 :0.1-.el6 libtirpc.x86_64 :0.2.-.el6_9
nfs-utils-lib.x86_64 :1.1.-.el6 python-argparse.noarch :1.2.-2.1.el6 Complete!
[root@localhost ~]# rpm -qa nfs-utils rpcbind
rpcbind-0.2.-.el6_9..x86_64
nfs-utils-1.2.-.el6_9.x86_64

(2)安装完成后,启动相关服务

[root@localhost ~]# rpm -qa nfs-utils rpcbind
rpcbind-0.2.-.el6_9..x86_64
nfs-utils-1.2.-.el6_9.x86_64
[root@localhost ~]# /etc/init.d/rpcbind status
rpcbind is stopped
[root@localhost ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
[root@localhost ~]# /etc/init.d/rpcbind status
rpcbind (pid ) is running...
[root@localhost ~]# /etc/init.d/nfs
anaconda-ks.cfg .bashrc install.log.syslog
.bash_logout .cshrc .tcshrc
.bash_profile install.log
[root@localhost ~]# /etc/init.d/nfs status
rpc.svcgssd is stopped
rpc.mountd is stopped
nfsd is stopped
[root@localhost ~]# rpcinfo -p localhost
program vers proto port service
tcp portmapper
tcp portmapper
tcp portmapper
udp portmapper
udp portmapper
udp portmapper
[root@localhost ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
[root@localhost ~]# rpcinfo -p localhost
program vers proto port service
tcp portmapper
tcp portmapper
tcp portmapper
udp portmapper
udp portmapper
udp portmapper
udp mountd
tcp mountd
udp mountd
tcp mountd
udp mountd
tcp mountd
tcp nfs
tcp nfs
tcp nfs
tcp nfs_acl
tcp nfs_acl
udp nfs
udp nfs
udp nfs
udp nfs_acl
udp nfs_acl
udp nlockmgr
udp nlockmgr
udp nlockmgr
tcp nlockmgr
tcp nlockmgr
tcp nlockmgr

让RPC、NFS服务开机自启,在实际生产环境中都会将配置放在/etc/rc.local下面

[root@localhost ~]# vim /etc/rc.local
[root@localhost ~]# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff. touch /var/lock/subsys/local
/etc/init.d/rpcbind start
/etc/init.d/nfs start

(3)配置服务端NFS配置文件/etc/exports

[root@localhost ~]# cat /etc/exports
##nfs server created by cairui at --
/home/cairui 192.168.181.128(rw)
[root@localhost ~]# /etc/init.d/nfs
anaconda-ks.cfg .bashrc install.log.syslog
.bash_logout .cshrc .tcshrc
.bash_profile install.log .viminfo
[root@localhost ~]# /etc/init.d/nfs reload
[root@localhost ~]# /etc/init.d/nfs restart
Shutting down NFS daemon: [ OK ]
Shutting down NFS mountd: [ OK ]
Shutting down NFS services: [ OK ]
Shutting down RPC idmapd: [ OK ]
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]

4、客户端配置

[root@localhost ~]# rpm -qa | grep nfs
nfs-utils-lib-1.1.-.el6.x86_64
nfs-utils-1.2.-.el6_9.x86_64
[root@localhost ~]# rpm -qa | grep rpc
rpcbind-0.2.-.el6_9..x86_64
libtirpc-0.2.-.el6_9.x86_64
[root@localhost ~]# /etc/init.d/rpcbind status
rpcbind is stopped
[root@localhost ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
[root@localhost ~]# /etc/init.d/rpcbind status
rpcbind (pid ) is running...
[root@localhost ~]# /etc/init.d/nfs status
rpc.svcgssd is stopped
rpc.mountd is stopped
nfsd is stopped
[root@localhost ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
[root@localhost ~]# showmount -e 192.168.181.129
Export list for 192.168.181.129:
/home/cairui 192.168.181.128
[root@localhost ~]# ping 192.168.181.129
PING 192.168.181.129 (192.168.181.129) () bytes of data.
bytes from 192.168.181.129: icmp_seq= ttl= time=0.348 ms
bytes from 192.168.181.129: icmp_seq= ttl= time=0.706 ms
bytes from 192.168.181.129: icmp_seq= ttl= time=0.512 ms
^C
--- 192.168.181.129 ping statistics ---
packets transmitted, received, % packet loss, time 2760ms
rtt min/avg/max/mdev = 0.348/0.522/0.706/0.146 ms
[root@localhost ~]# iptables -F
[root@localhost ~]# showmount -e 192.168.181.129
Export list for 192.168.181.129:
/home/cairui 192.168.181.128

客户端进行NFS挂载

[root@localhost ~]# mount -t nfs 192.168.181.129:/home/cairui /mnt
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G .4G 16G % /
tmpfs 491M 491M % /dev/shm
/dev/sda1 190M 30M 150M % /boot
192.168.181.129:/home/cairui
18G 809M 16G % /mnt

5、测试

服务端

[root@localhost ~]# cd /home/cairui/
[root@localhost cairui]# touch .txt
[root@localhost cairui]# ls -ll /home/cairui/
total
-rw-r--r--. root root Feb : .txt
[root@localhost cairui]# ls -ld /home/cairui/
drwx------. cairui cairui Feb : /home/cairui/
[root@localhost cairui]# chmod /home/cairui/
[root@localhost cairui]# ls -ld /home/cairui/
drwxrwxrwx. cairui cairui Feb : /home/cairui/

 [root@localhost cairui]# mkdir nfs

客户端

[root@localhost ~]# cd /mnt/
-bash: cd: /mnt/: Permission denied
[root@localhost ~]# ls -ll /mnt/
ls: cannot open directory /mnt/: Permission denied
[root@localhost ~]# cd /m
media/ mnt/
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
.txt
[root@localhost mnt]# ls
.txt nfs
[root@localhost mnt]#

八.启动自动挂载nfs文件系统

格式:<server>:<remote/export>

</local/directory> nfs <option> 0 0

#vim /etc/fstab

最后一行为后加的

保存退出,重启系统

或者修改

Linux之NFS网络文件系统的更多相关文章

  1. Linux系统NFS网络文件系统

    Linux系统NFS网络文件系统 NFS(network file system)网络文件系统,就是通过网络让不同的主机系统之间可以共享文件或目录,此种方法NFS客户端使用挂载的方式让共享文件或目录到 ...

  2. linux初学者-NFS网络文件系统篇

    linux初学者-NFS网络文件系统篇 在上一篇的SAMBA篇中介绍了linux系统和windows系统之间共用的网络文件系统CIFS,主要用于客户端是windows的情况.在linux系统之间,所用 ...

  3. Linux系统——NFS网络文件系统

    在企业集群架构的工作场景中,NFS网络文件系统一般被用来存储共享视频,图片,附件等静态资源文件,通常网站用户上传的文件都会放到NFS共享里,然后前端所有的节点访问这些静态资源时都会读取NFS存储上的资 ...

  4. tiny4412 linux+qtopia nfs网络文件系统的挂载

    1,首先确定uboot启动内核的bootargs参数 Linux-CommandLine = root=/dev/nfs nfsroot=192.168.1.131:/home/tiny4412/ro ...

  5. Linux基础学习-NFS网络文件系统实时文件共享

    NFS网络文件系统 如果大家觉得Samba服务程序的配置太麻烦了,那么你共享文件的主机都是Linux系统,那么推荐大家在客户端部署nfs服务来共享文件.nfs(网络文件系统)服务可以将远程Linux系 ...

  6. NFS 网络文件系统挂载在A8板子上

    我承认自己是菜鸟,没什么网络知识就来搞挂载nfs网络文件系统,花费了5天的时间才把nfs网络文件系统成功挂载在A8板子上,实现了A8板子和虚拟机的文件共享.分享一下个人经验: 以下是基于nfs已经完成 ...

  7. [学习嵌入式开发板]iTOP-4412实现NFS网络文件系统

    本文转自迅为:http://www.topeetboard.com 学习平台:iTOP-4412开发板 本文讲解如何在 iTOP-4412 开发板上实现 NFS 网络文件系统. 我们使用的软硬件环境是 ...

  8. linux初学者-CIFS网络文件系统篇

    linux初学者-CIFS网络文件系统篇 CIFS是一种通用网络文件系统,主要用于网络设备之间的文件共享.CIFS可以在linux系统和windows系统之间共享文件,因此这种文件系统主要用于客户端是 ...

  9. NFS(网络文件系统)

    NFS(网络文件系统) 1.关于NFS介绍 1.1NFS在企业中的应用场景 在企业集群架构的工作场景中,NFS网络文件系统一般被用来存储共享视频,图片,附件等静态资源文件,通常网站用户上传的文件都会放 ...

随机推荐

  1. 微服务监控之一:Metrics让微服务运行更透明

    摘要 让微服务运行状态清晰可见. 嘉宾演讲视频回顾及PPT:http://t.cn/R8b6i85 Metrics是什么 直译是“度量”,不同的领域定义有所区别,在微服务领域中的定义: “对微服务的某 ...

  2. Java-API-Package:java.util

    ylbtech-Java-API-Package:java.util 1.返回顶部 1. java.util Interfaces Collection Comparator Deque Enumer ...

  3. MySQL执行计划的讲解

    最近同事在执行线上执行一条MySQL的查询语句,数据的话在9000条左右,但使用左连接的时候查询速度大概在15秒左右~这速度确实是无法接受的~ 经过简单的修改,变为内连接的话,执行速度不到1秒. 下面 ...

  4. 关于WinPE安装操作系统

    在WinPE安装操作系统,最好用虚拟光驱打开安装镜像文件,或者把镜像文件解压后直接安装. 最好不要用工具盘里所带的一键安装,复制等等功能,因为这些功能往往会安装一些其他的附带功能,不是清洁版的.

  5. log4j配置文件加载方式

    使用背景: apache的log4j是一个功能强大的日志文件,当我们使用eclipse等IDE在项目中配置log4j的时候,需要知道我们的配置文件的加载方式以及如何被加载的. 加载方式: (1).自动 ...

  6. 10-17C#语句(3)--跳转语句、异常处理语句

    回顾: 穷举法(重点掌握):虽然运用for...嵌循环语句,但是也要找到执行for...循环的规律, 即一个题目中,需要得到哪个值,首先定义它初始变量:哪个条件需要改变,它对应的就是for...循环的 ...

  7. Microsoft Office Visio 2010如何创建UML 用例图

    转自:https://blog.csdn.net/mmoooodd/article/details/10513059 1..在Microsoft Office2010中打开Microsoft Visi ...

  8. 使用Eclipse的常见问题整理

    我在Eclipse里新建一个android工程的时候附带着产生了一个名字为appcompat_v7的工程,这个工程是干什么用的啊?为何我新建的工程都出错了,错误信息提示为: error: Error ...

  9. day70-oracle 12-Java调用存储过程和存储函数

    我们现在调用的是存储过程和存储函数.用CallableSatement调用存储函数和存储过程. RDBMS:关系数据库.使用标准方式调用存储过程.也就是说:在mysql中调用和在oracle中调用的写 ...

  10. Codeforces 914C Travelling Salesman and Special Numbers (数位DP)

    题意:题目中定义了一种运算,把数字x变成数字x的二进制位数.问小于n的恰好k次运算可以变成1的数的个数(题目中的n是二进制数,n最大到2^1000) 思路:容易发现,无论多么大的数,只要进行了一次运算 ...