当前位置:首页 > CN2资讯 > 正文内容

nfs linux 开发 linux的nfs

1天前CN2资讯


  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 00:00 extras | 3.4 kB 00:00 extras/primary_db | 30 kB 00:00 updates | 3.4 kB 00:00 Resolving Dependencies --> Running transaction check ---> Package nfs-utils.x86_64 1:1.2.3-75.el6_9 will be installed --> Processing Dependency: nfs-utils-lib >= 1.1.0-3 for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64 --> Processing Dependency: libtirpc >= 0.2.1-11 for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64 --> Processing Dependency: keyutils >= 1.4-4 for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64 --> Processing Dependency: python-argparse for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64 --> Processing Dependency: .1(libgssapi_CITI_2)(64bit) for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64 --> Processing Dependency: libgssglue for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64 --> Processing Dependency: libevent for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64 --> Processing Dependency: .1()(64bit) for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64 --> Processing Dependency: .0()(64bit) for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64 --> Processing Dependency: .1()(64bit) for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64 --> Processing Dependency: .2()(64bit) for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64 ---> Package rpcbind.x86_64 0:0.2.0-13.el6_9.1 will be installed --> Running transaction check ---> Package keyutils.x86_64 0:1.4-5.el6 will be installed ---> Package libevent.x86_64 0:1.4.13-4.el6 will be installed ---> Package libgssglue.x86_64 0:0.1-11.el6 will be installed ---> Package libtirpc.x86_64 0:0.2.1-13.el6_9 will be installed ---> Package nfs-utils-lib.x86_64 0:1.1.5-13.el6 will be installed ---> Package python-argparse.noarch 0:1.2.1-2.1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================== Package Arch Version Repository Size ============================================================================== Installing: nfs-utils x86_64 1:1.2.3-75.el6_9 updates 336 k rpcbind x86_64 0.2.0-13.el6_9.1 updates 51 k Installing for dependencies: keyutils x86_64 1.4-5.el6 base 39 k libevent x86_64 1.4.13-4.el6 base 66 k libgssglue x86_64 0.1-11.el6 base 23 k libtirpc x86_64 0.2.1-13.el6_9 updates 82 k nfs-utils-lib x86_64 1.1.5-13.el6 base 71 k python-argparse noarch 1.2.1-2.1.el6 base 48 k Transaction Summary ============================================================================== Install 8 Package(s) Total download size: 716 k Installed size: 2.0 M Downloading Packages: (1/8): keyutils-1.4-5.el6.x86_64.rpm | 39 kB 00:00 (2/8): libevent-1.4.13-4.el6.x86_64.rpm | 66 kB 00:00 (3/8): libgssglue-0.1-11.el6.x86_64.rpm | 23 kB 00:00 (4/8): libtirpc-0.2.1-13.el6_9.x86_64.rpm | 82 kB 00:00 (5/8): nfs-utils-1.2.3-75.el6_9.x86_64.rpm | 336 kB 00:00 (6/8): nfs-utils-lib-1.1.5-13.el6.x86_64.rpm | 71 kB 00:00 (7/8): python-argparse-1.2.1-2.1.el6.noarch.rpm | 48 kB 00:00 (8/8): rpcbind-0.2.0-13.el6_9.1.x86_64.rpm | 51 kB 00:00 ------------------------------------------------------------------------------ Total 1.1 MB/s | 716 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : libgssglue-0.1-11.el6.x86_64 1/8 Installing : libtirpc-0.2.1-13.el6_9.x86_64 2/8 Installing : rpcbind-0.2.0-13.el6_9.1.x86_64 3/8 Installing : python-argparse-1.2.1-2.1.el6.noarch 4/8 Installing : libevent-1.4.13-4.el6.x86_64 5/8 Installing : keyutils-1.4-5.el6.x86_64 6/8 Installing : nfs-utils-lib-1.1.5-13.el6.x86_64 7/8 Installing : 1:nfs-utils-1.2.3-75.el6_9.x86_64 8/8 Verifying : rpcbind-0.2.0-13.el6_9.1.x86_64 1/8 Verifying : libtirpc-0.2.1-13.el6_9.x86_64 2/8 Verifying : keyutils-1.4-5.el6.x86_64 3/8 Verifying : libevent-1.4.13-4.el6.x86_64 4/8 Verifying : nfs-utils-lib-1.1.5-13.el6.x86_64 5/8 Verifying : libgssglue-0.1-11.el6.x86_64 6/8 Verifying : 1:nfs-utils-1.2.3-75.el6_9.x86_64 7/8 Verifying : python-argparse-1.2.1-2.1.el6.noarch 8/8 Installed: nfs-utils.x86_64 1:1.2.3-75.el6_9 rpcbind.x86_64 0:0.2.0-13.el6_9.1 Dependency Installed: keyutils.x86_64 0:1.4-5.el6 libevent.x86_64 0:1.4.13-4.el6 libgssglue.x86_64 0:0.1-11.el6 libtirpc.x86_64 0:0.2.1-13.el6_9 nfs-utils-lib.x86_64 0:1.1.5-13.el6 python-argparse.noarch 0:1.2.1-2.1.el6 Complete! [root@localhost ~]# rpm -qa nfs-utils rpcbind rpcbind-0.2.0-13.el6_9.1.x86_64 nfs-utils-1.2.3-75.el6_9.x86_64



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



[root@localhost ~]# rpm -qa nfs-utils rpcbind rpcbind-0.2.0-13.el6_9.1.x86_64 nfs-utils-1.2.3-75.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 1958) 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 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 [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 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 100005 1 udp 53776 mountd 100005 1 tcp 45705 mountd 100005 2 udp 59195 mountd 100005 2 tcp 37339 mountd 100005 3 udp 51079 mountd 100005 3 tcp 42701 mountd 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 100003 2 udp 2049 nfs 100003 3 udp 2049 nfs 100003 4 udp 2049 nfs 100227 2 udp 2049 nfs_acl 100227 3 udp 2049 nfs_acl 100021 1 udp 55657 nlockmgr 100021 3 udp 55657 nlockmgr 100021 4 udp 55657 nlockmgr 100021 1 tcp 56873 nlockmgr 100021 3 tcp 56873 nlockmgr 100021 4 tcp 56873 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 2018-2-17 /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.5-13.el6.x86_64 nfs-utils-1.2.3-75.el6_9.x86_64 [root@localhost ~]# rpm -qa | grep rpc rpcbind-0.2.0-13.el6_9.1.x86_64 libtirpc-0.2.1-13.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 1463) 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) 56(84) bytes of data. 64 bytes from 192.168.181.129: icmp_seq=1 ttl=64 time=0.348 ms 64 bytes from 192.168.181.129: icmp_seq=2 ttl=64 time=0.706 ms 64 bytes from 192.168.181.129: icmp_seq=3 ttl=64 time=0.512 ms ^C --- 192.168.181.129 ping statistics --- 3 packets transmitted, 3 received, 0% 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 1.4G 16G 9% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 190M 30M 150M 17% /boot 192.168.181.129:/home/cairui 18G 809M 16G 5% /mnt



5、测试

服务端



[root@localhost ~]# cd /home/cairui/ [root@localhost cairui]# touch 1.txt [root@localhost cairui]# ls -ll /home/cairui/ total 0 -rw-r--r--. 1 root root 0 Feb 17 17:15 1.txt [root@localhost cairui]# ls -ld /home/cairui/ drwx------. 2 cairui cairui 4096 Feb 17 17:15 /home/cairui/ [root@localhost cairui]# chmod 777 /home/cairui/ [root@localhost cairui]# ls -ld /home/cairui/ drwxrwxrwx. 2 cairui cairui 4096 Feb 17 17:15 /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 1.txt [root@localhost mnt]# ls 1.txt nfs [root@localhost mnt]#



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

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

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

#vim /etc/fstab

最后一行为后加的

保存退出,重启系统

或者修改

    你可能想看:

    扫描二维码推送至手机访问。

    版权声明:本文由皇冠云发布,如需转载请注明出处。

    本文链接:https://www.idchg.com/info/25869.html

    分享给朋友:

    “nfs linux 开发 linux的nfs” 的相关文章

    中国电信CN2价格表最新版下载指南:助力企业轻松选择优质网络服务

    在互联网高速发展的今天,网络服务质量已经成为企业发展的重要保障。而对于企业来说,选择一家优质、可靠、性价比高的网络服务提供商尤为重要。中国电信作为国内领先的通信运营商,始终致力于为企业提供优质的网络服务,其CN2网络更是以其稳定的性能和全面的覆盖而备受好评。为了帮助企业更好地选择适合自己的网络服务方...

    mac ssh工具推荐:提升远程工作效率的最佳选择

    在现代计算机网络中,SSH(Secure Shell)是一个重要的工具。它为用户提供了一种安全的远程登录协议,广泛应用于网络管理、服务器配置等场景。我自己在处理多台服务器时,总是通过SSH来保证安全性和网络的高效性。通过SSH,我可以在远程计算机上执行命令和操作,感觉就像在本地电脑上一样。 在Mac...

    DirectAdmin安装全攻略:快速安装与配置指南

    DirectAdmin是一款由国外开发的虚拟主机管理系统。我第一次接触它时,就被其强大的功能和用户友好的界面所吸引。它不仅可以管理服务器,还能帮助我轻松设置EMAIL、DNS、FTP等。这种集中管理的方式大大提高了我的工作效率,尤其是对那些需要频繁处理服务器配置的用户来说,DirectAdmin无疑...

    全面解析UDP攻击:类型、影响及有效防御策略

    在当今网络环境中,UDP攻击是一个话题无法忽视的安全隐患。它是一种常见的网络攻击形式,通常会给目标服务器带来严重的资源消耗。为了更好地理解这一现象,我们不妨简单回顾一下UDP协议的特性,以及攻击者是如何利用这一协议实施攻击的。 UDP,即用户数据报协议(User Datagram Protocol)...

    强制结束占用短裤:高效解决文件锁定问题的方法与工具

    强制结束占用短裤这一概念听起来可能有些陌生,但在计算机操作系统中,它扮演着一个非常重要的角色。当一个文件或进程被占用时,我们常常会发现自己无法删除、移动或修改这些文件。这时,强制结束的必要性就显而易见了。通过强制结束占用,我们可以有效地解除阻碍,重新获得对文件的掌控。 对于普通用户来说,主动解除文件...

    选择最佳VPS主机服务:Digital-VM全面解析与性能优化策略

    谈到 Digital-VM,我总会被它的成长故事所吸引。这家主机商成立于2018年,致力于为用户提供高效、灵活的VPS主机解决方案。作为一家美国公司,它在短时间内就扩大了服务范围,减少了用户在选择主机服务时的焦虑。Digital-VM 看似是一颗新星,却在竞争激烈的市场中脱颖而出,令人刮目相看。 在...