NFS服务安装

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

2. NFS 的好处

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

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

③一些存储设备 CDROM 和 Zip(一种高储存密度的磁盘驱动器与磁盘)等 都可以在网络上被别的机器使用。这可以减少整个网络上可移动介质设备的数 量。

         NFS 的基本原则是“容许不同的客户端及服务端通过一组 RPC 分享相同的 文件系统”,它是独立于操作系统,容许不同硬件及操作系统的系统共同进行 文件的分享。

        NFS 在文件传送或信息传送过程中依赖于 RPC 协议。RPC,远程过程调用 (Remote Procedure Call) 是能使客户端执行其他系统中程序的一种机制。NFS 本身是没有提供信息传输的协议和功能的,但 NFS 却能让我们通过网络进行资 料的分享,这是因为 NFS 使用了一些其它的传输协议。而这些传输协议用到这 个 RPC 功能的。可以说 NFS 本身就是使用 RPC 的一个程序。或者说 NFS 也是一 个 RPC SERVER。所以只要用到 NFS 的地方都要启动 RPC 服务,不论是 NFS SERVER 或者 NFS CLIENT。这样 SERVER 和 CLIENT 才能通过 RPC 来实现 PROGRAM PORT 的对应。可以这么理解 RPC 和 NFS 的关系:NFS 是一个文件系统,而 RPC 是负责负责信息的传输。

3. nfs 服务端所需的软件列表 nfs-utils: 这个是 NFS 服务主程序(包含 rpc.nfsd、rpc.mountd、 daemons) rpcbind: 这个是 CentOS6.X 的 RPC 主程序(CentOS5.X 的为 portmap)

搭建:

方法一:

4. Nfs 服务器安装搭建 a) Nfs 服务 centos7 已经默认安装,使用命令检测是否安装相应的服务程 序

b) 在 nfs 服务器上建立 nfs 文件共享的目录,设置修改权限

mkdir /nfsfile

chmod -Rf 777 /nfsfile

echo “this is nfs test“ > /nfsfile/readme

c) 修改配置文件/etc/exports,默认内容为空。设置要共享的目录及相应 的权限,格式:“共享目录路径 允许访问的 nfs 客户端(共享权限参 数)

d) 启动 nfs 服务程序。

e) Nfs 客户端配置

         i. 使用 showmount 查询 nfs 服务器的远程共享信息,输出格式:”共 享目录名 允许使用的客户端地址“ -e 显示 nfs 服务器的共享列表

         ii. 在 nfs 客户端创建一个挂载目录。使用 mount -t 指定要挂载的文 件系统类型,并在命令后添加服务器 ip 地址:服务器共享目录、 要挂载的本地目录

方法二: 这个也安装:

eCentos 环境下 NFS 服务安装及配置使用_nfs-kernel-server-CSDN博客

如果更改了 /etc/exports 可以使用  [root@app home]#exportfs -rv  这样就可以不用重启就可以使文件生效

-----(我测试的代码)

服务端

Last login: Sun Oct  8 21:36:55 2023
/usr/bin/xauth:  file /root/.Xauthority does not exist
[root@localhost ~]# ls -la
总用量 60
dr-xr-x---. 14 root root 4096 10月  9 17:45 .
dr-xr-xr-x. 18 root root  250 10月  9 11:45 ..
-rw-------.  1 root root 1808 10月  9 02:45 anaconda-ks.cfg
-rw-------.  1 root root 3161 10月  9 17:25 .bash_history
-rw-r--r--.  1 root root   18 12月 29 2013 .bash_logout
-rw-r--r--.  1 root root  176 12月 29 2013 .bash_profile
-rw-r--r--.  1 root root  176 12月 29 2013 .bashrc
drwx------. 13 root root 4096 10月  8 21:36 .cache
drwxr-xr-x. 16 root root 4096 10月  9 02:48 .config
-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc
drwx------.  3 root root   25 10月  9 02:45 .dbus
-rw-------.  1 root root   16 10月  9 02:46 .esd_auth
-rw-------.  1 root root  620 10月  8 21:36 .ICEauthority
-rw-r--r--.  1 root root 1856 10月  9 02:45 initial-setup-ks.cfg
drwx------.  3 root root   19 10月  9 02:46 .local
-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc
-rw-------.  1 root root 3772 10月  9 14:56 .viminfo
-rw-------.  1 root root   67 10月  9 17:45 .Xauthority
drwxr-xr-x.  2 root root    6 10月  9 02:46 公共
drwxr-xr-x.  2 root root    6 10月  9 02:46 模板
drwxr-xr-x.  2 root root    6 10月  9 02:46 视频
drwxr-xr-x.  2 root root    6 10月  9 02:46 图片
drwxr-xr-x.  2 root root    6 10月  9 02:46 文档
drwxr-xr-x.  2 root root    6 10月  9 02:46 下载
drwxr-xr-x.  2 root root    6 10月  9 02:46 音乐
drwxr-xr-x.  2 root root    6 10月  9 02:46 桌面
[root@localhost ~]# cd data
-bash: cd: data: 没有那个文件或目录
[root@localhost ~]# cd /data
[root@localhost data]# ls -la
总用量 0
drwxr-xr-x.  4 root root  33 10月  9 17:41 .
dr-xr-xr-x. 18 root root 250 10月  9 11:45 ..
drw-rw-rw-.  2 root root   6 10月  9 11:45 share
drw-rw-rw-.  2 root root   6 10月  9 17:41 share1
[root@localhost data]# chmod an /data/share1
chmod: 无效模式:"an"
Try 'chmod --help' for more information.
[root@localhost data]# chmod -Rf 777 /data/share1
[root@localhost data]# echo "this is nfs test" > /data/share1/readme
[root@localhost data]# ls
share  share1
[root@localhost data]# cd share1
[root@localhost share1]# ls 
readme
[root@localhost share1]# vim /etc/exports
[root@localhost share1]# systemctl restart rcpbind
Failed to restart rcpbind.service: Unit not found.
[root@localhost share1]# systemctl restart rpcbind
[root@localhost share1]# systemctl enable rpcbind
Created symlink from /etc/systemd/system/multi-user.target.wants/rpcbind.service to /usr/lib/systemd/system/rpcbind.service.
[root@localhost share1]# ststemctl start nfs-server
bash: ststemctl: 未找到命令...
[root@localhost share1]# systemctl start nfs-server
[root@localhost share1]# systemctl enable nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@localhost share1]# showmount -e 192.168.20.250
[root@localhost share1]# vim /etc/exports
[root@localhost share1]# systemctl restart rcpbind
Failed to restart rcpbind.service: Unit not found.
[root@localhost share1]# systemctl restart rpcbind
[root@localhost share1]# systemctl enable rcpbind
Failed to execute operation: No such file or directory
[root@localhost share1]# systemctl enable rpcbind
[root@localhost share1]# systemctl start nfs-server
[root@localhost share1]# systemctl enable nfs-server
[root@localhost share1]# showmount -e 192.168.20.250
[root@localhost share1]# 
[root@localhost share1]# vim /etc/exports
[root@localhost share1]# showmount -e 192.168.50.128
Export list for 192.168.50.128:
[root@localhost share1]# vim /etc/exports
[root@localhost share1]# exportfs -rv
exporting 192.168.50.*:/data/share1
[root@localhost share1]# showmount -e 192.168.50.128
Export list for 192.168.50.128:
/data/share1 192.168.50.*
[root@localhost share1]# ls
readme
[root@localhost share1]# ^C
[root@localhost share1]# 

客户端:

[root@localhost /]# ls
bin   data  etc   lib    master  mnt       opt   root  sbin  sys  usr
boot  dev   home  lib64  media   nfsfile2  proc  run   srv   tmp  var
[root@localhost /]# cd data
[root@localhost data]# ls
share  share1
[root@localhost data]# mkdir nfsfile

[root@localhost data]# mount -t nfs 192.168.50.128:/date/share1 /data/share
mount.nfs: mounting 192.168.50.128:/date/share1 failed, reason given by server: No such file or directory
[root@localhost data]# cd share
[root@localhost share]# ls
[root@localhost share]# ls
[root@localhost share]# ls -la
总用量 0
drw-rw-rw-. 2 root root  6 10月  9 11:45 .
drwxr-xr-x. 5 root root 48 10月  9 18:27 ..
[root@localhost share]# cd /data/share1
[root@localhost share1]# ls
readme
[root@localhost share1]# ls
readme
[root@localhost share1]# cat readme
this is nfs test
[root@localhost share1]# 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值