【RHEL8】—NFSserver ;【Centos7】—NFSclient

!!!测试环境我们首关闭防火墙和selinux(NFSserver和NFSclient都需要)

  1. [root@localhost ~]# systemctl stop firewalld
  2. [root@localhost ~]# systemctl disable firewalld
  3. [root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  4. [root@localhost ~]# setenforce 0

前言

1、NFS服务介绍

1️⃣:NFS—Network File System—网络文件系统

2️⃣:主要用于linux系统上实现文件共享的一种协议,其客户端主要是Linux

3️⃣:企业应用:为集群中的web server提供后端存储

4️⃣:没有用户认证机制,且数据在网络上传送的时候是明文传送,一般只能在局域网中使用 支持多节点同时挂载及并发写入

5️⃣:一般只在局域网中使用

2、NFS服务的组件

1️⃣:RPC(Remote Procedure Call Protocol):远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,不需要了解底层网络技术的协议。

2️⃣:客户端工具:(1)Linux系统:showmount 、mount.nfs;(2)Windows系统:无

3、NFS服务概述

1️⃣:服务全称:Network File System,网络文件系统

2️⃣:服务功能:在类UNIX主机之间共享目录和文件资源

3️⃣:服务模式:客户机/服务器工作模式

4️⃣:软件包名:rpcbind 和 nfs-utils

        rpcbind:负责NFS的数据传输,远程过程调用

nfs-utils:控制共享哪些文件,权限管理

5️⃣:进程名称:rpcbind 、rpc.nfsd 、rpc.mountd、 exportfs

6️⃣:进程端口:服务器端RPC(111) 、NFS(随机)

一、NFS服务端安装NFS服务

1、首先查看一下服务端IP

  1. [root@NFSserver ~]# ifconfig
  2. ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  3. inet 10.0.0.140 netmask 255.0.0.0 broadcast 10.255.255.255
  4. inet6 fe80::fa13:32e0:3b9f:2196 prefixlen 64 scopeid 0x20<link>
  5. ether 00:0c:29:cd:6a:1b txqueuelen 1000 (Ethernet)
  6. RX packets 5419 bytes 465927 (455.0 KiB)
  7. RX errors 0 dropped 0 overruns 0 frame 0
  8. TX packets 3930 bytes 558300 (545.2 KiB)
  9. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  10.  
  11. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  12. inet 127.0.0.1 netmask 255.0.0.0
  13. inet6 ::1 prefixlen 128 scopeid 0x10<host>
  14. loop txqueuelen 1000 (Local Loopback)
  15. RX packets 594 bytes 50308 (49.1 KiB)
  16. RX errors 0 dropped 0 overruns 0 frame 0
  17. TX packets 594 bytes 50308 (49.1 KiB)
  18. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

2、安装nfs-utils和rpcbind包

  1. [root@NFSserver ~]# yum install -y rpcbind nfs-utils
  2. [root@NFSserver ~]# rpm -qa rpcbind nfs-utils
  3. rpcbind-1.2.5-4.el8.x86_64
  4. nfs-utils-2.3.3-26.el8.x86_64

3、先启动rpcbind和nfs,并开启服务(!!!注意:必须先开启 rpcbind 然后再开启 nfs ,否则会出现问题!!!)

  1. [root@NFSserver ~]# systemctl start rpcbind
  2. [root@NFSserver ~]# systemctl enable rpcbind
  3. [root@NFSserver ~]# systemctl start nfs
  4. Failed to start nfs.service: Unit nfs.service not found.
  5. [root@NFSserver ~]# systemctl start nfs-server
  6. [root@NFSserver ~]# systemctl enable nfs-server
  7. Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service /usr/lib/systemd/system/nfs-server.service.
  8. [root@NFSserver ~]# netstat -tunlp
  9. Active Internet connections (only servers)
  10. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  11. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
  12. tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 30223/rpc.mountd
  13. tcp 0 0 0.0.0.0:52373 0.0.0.0:* LISTEN 28778/rpc.statd
  14. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1101/sshd
  15. tcp 0 0 0.0.0.0:35197 0.0.0.0:* LISTEN -
  16. tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
  17. tcp6 0 0 :::111 :::* LISTEN 1/systemd
  18. tcp6 0 0 :::20048 :::* LISTEN 30223/rpc.mountd
  19. tcp6 0 0 :::36949 :::* LISTEN -
  20. tcp6 0 0 :::22 :::* LISTEN 1101/sshd
  21. tcp6 0 0 :::41119 :::* LISTEN 28778/rpc.statd
  22. tcp6 0 0 :::2049 :::* LISTEN -
  23. udp 0 0 0.0.0.0:42713 0.0.0.0:* -
  24. udp 0 0 127.0.0.1:970 0.0.0.0:* 28778/rpc.statd
  25. udp 0 0 0.0.0.0:68 0.0.0.0:* 1611/dhclient
  26. udp 0 0 0.0.0.0:111 0.0.0.0:* 1/systemd
  27. udp 0 0 0.0.0.0:20048 0.0.0.0:* 30223/rpc.mountd
  28. udp 0 0 0.0.0.0:40540 0.0.0.0:* 28778/rpc.statd
  29. udp6 0 0 :::111 :::* 1/systemd
  30. udp6 0 0 :::35034 :::* 28778/rpc.statd
  31. udp6 0 0 :::33084 :::* -
  32. udp6 0 0 :::20048 :::* 30223/rpc.mountd

  1. 检查守护进程状态
  2. /etc/rc.d/init.d/rpcbind status
  3. 检查服务进程状态
  4. /etc/rc.d/init.d/nfs status

服务进程

4、服务端口查看

  1. [root@NFSserver ~]# rpcinfo -p
  2. program vers proto port service
  3. 100000 4 tcp 111 portmapper
  4. 100000 3 tcp 111 portmapper
  5. 100000 2 tcp 111 portmapper
  6. 100000 4 udp 111 portmapper
  7. 100000 3 udp 111 portmapper
  8. 100000 2 udp 111 portmapper
  9. 100024 1 udp 40540 status
  10. 100024 1 tcp 52373 status
  11. 100003 3 tcp 2049 nfs
  12. 100003 4 tcp 2049 nfs
  13. 100227 3 tcp 2049 nfs_acl
  14. 100021 1 udp 42713 nlockmgr
  15. 100021 3 udp 42713 nlockmgr
  16. 100021 4 udp 42713 nlockmgr
  17. 100021 1 tcp 35197 nlockmgr
  18. 100021 3 tcp 35197 nlockmgr
  19. 100021 4 tcp 35197 nlockmgr
  20. 100005 1 udp 20048 mountd
  21. 100005 1 tcp 20048 mountd
  22. 100005 2 udp 20048 mountd
  23. 100005 2 tcp 20048 mountd
  24. 100005 3 udp 20048 mountd
  25. 100005 3 tcp 20048 mountd

5、创建共享目录

  1. [root@NFSserver ~]# mkdir /nfsdir
  2. [root@NFSserver ~]# ll /nfsdir/
  3. 总用量 0

6、编辑NFS主配置文件

  1. [root@NFSserver ~]# vim /etc/exports
  2. [root@NFSserver ~]# cat /etc/exports
  3. /nfsdir 10.0.0.0/24(ro,rw)
  4. //第一次进入该文件为空白文件,需要使用者自行创建

  1. 1、/etc/exports文件格式
  2. <输出目录> [客户端1 选项(访问权限,用户映射,其他)] [客户端2 选项(访问权限,用户映射,其他)](exprots文件中每一行提供了一个共享目录的设置)
  3. 2、相关说明
  4. 1️⃣:输出目录:输出目录是指NFS系统中需要共享给客户机使用的目录;
  5. 2️⃣:客户端:客户端是指网络中可以访问这个NFS输出目录的计算机;
  6. 客户端常用的指定方式:
  7. 指定ip地址的主机:192.168.10.10
  8. 指定子网中的所有主机:192.168.10.0/24 192.168.10.*
  9. 指定域名的主机:www.test.com.cn
  10. 指定域中的所有主机:*.test.com.cn
  11. 所有主机:*
  12. 3️⃣:选项的种类:
  13. 1)、访问权限选项:
  14. 设置输出目录只读:ro
  15. 设置输出目录读写:rw
  16. 2)、用户映射选项:
  17. all_squash:将远程访问的所有普通用户及所属组都映射为匿名用户或用户组(nfsnobody);
  18. no_all_squash:与all_squash取反(默认设置);
  19. root_squash:将root用户及所属组都映射为匿名用户或用户组(默认设置);
  20. no_root_squash:与rootsquash取反;
  21. anonuid=xxx:将远程访问的所有用户都映射为匿名用户,并指定该用户为本地用户(UID=xxx);
  22. anongid=xxx:将远程访问的所有用户组都映射为匿名用户组账户,并指定该匿名用户组账户为本地用户组账户(GID=xxx);
  23. 3)、其它选项:
  24. secure:限制客户端只能从小于1024tcp/ip端口连接nfs服务器(默认设置);
  25. insecure:允许客户端从大于1024tcp/ip端口连接服务器;
  26. sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性;
  27. async:将数据先保存在内存缓冲区中,必要时才写入磁盘;
  28. wdelay:检查是否有相关的写操作,如果有则将这些写操作一起执行,这样可以提高效率(默认设置);
  29. no_wdelay:若有写操作则立即执行,应与sync配合使用;
  30. subtree:若输出目录是一个子目录,则nfs服务器将检查其父目录的权限(默认设置);
  31. no_subtree:即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率;
  32. no_root_squash:是让root保持权限;
  33. root_squash:是把root映射成nobodyno_all_squash 不让所有用户保持在挂载目录中的权限。

相关说明

7、重启NFS服务

  1. [root@NFSserver ~]# systemctl restart nfs-server
  2. [root@NFSserver ~]# netstat -tunlp
  3. Active Internet connections (only servers)
  4. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  5. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
  6. tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 30394/rpc.mountd
  7. tcp 0 0 0.0.0.0:52373 0.0.0.0:* LISTEN 28778/rpc.statd
  8. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1101/sshd
  9. tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
  10. tcp 0 0 0.0.0.0:44931 0.0.0.0:* LISTEN -
  11. tcp6 0 0 :::111 :::* LISTEN 1/systemd
  12. tcp6 0 0 :::20048 :::* LISTEN 30394/rpc.mountd
  13. tcp6 0 0 :::46481 :::* LISTEN -
  14. tcp6 0 0 :::22 :::* LISTEN 1101/sshd
  15. tcp6 0 0 :::41119 :::* LISTEN 28778/rpc.statd
  16. tcp6 0 0 :::2049 :::* LISTEN -
  17. udp 0 0 127.0.0.1:970 0.0.0.0:* 28778/rpc.statd
  18. udp 0 0 0.0.0.0:68 0.0.0.0:* 1611/dhclient
  19. udp 0 0 0.0.0.0:111 0.0.0.0:* 1/systemd
  20. udp 0 0 0.0.0.0:47351 0.0.0.0:* -
  21. udp 0 0 0.0.0.0:20048 0.0.0.0:* 30394/rpc.mountd
  22. udp 0 0 0.0.0.0:40540 0.0.0.0:* 28778/rpc.statd
  23. udp6 0 0 :::111 :::* 1/systemd
  24. udp6 0 0 :::35034 :::* 28778/rpc.statd
  25. udp6 0 0 :::45389 :::* -
  26. udp6 0 0 :::20048 :::* 30394/rpc.mountd

二、客户端访问NFS服务器

1、客户端安装nfs-utils(其实原本需要在客户端安装的工具是showmount和mount.nfs,在安装这两个包时,就是安装的nfs-utils这个包)

  1. [root@nfsclient ~]# yum install -y nfs-utils
  2. [root@nfsclient ~]# rpm -qa nfs-utils
  3. nfs-utils-1.3.0-0.66.el7.x86_64
  4. [root@nfsclient ~]# which showmount mount.nfs
  5. /usr/sbin/showmount
  6. /usr/sbin/mount.nfs
  7. //出现命令的路径,说明已经安装

2、客户端查看服务端提供的共享资源

  1. //命令格式:showmount -e 服务器端ip
  2. [root@nfsclient ~]# showmount -e 10.0.0.140
  3. Export list for 10.0.0.140:
  4. /nfsdir 10.0.0.0/24

3、客户端创建需要挂载的目录

  1. [root@nfsclient ~]# mkdir /sharedir
  2. [root@nfsclient ~]# ll /sharedir/
  3. 总用量 0
  4. [root@nfsclient ~]# df -h
  5. 文件系统 容量 已用 可用 已用% 挂载点
  6. /dev/mapper/centos-root 50G 1.1G 49G 3% /
  7. devtmpfs 901M 0 901M 0% /dev
  8. tmpfs 912M 0 912M 0% /dev/shm
  9. tmpfs 912M 8.6M 904M 1% /run
  10. tmpfs 912M 0 912M 0% /sys/fs/cgroup
  11. /dev/mapper/centos-home 27G 33M 27G 1% /home
  12. /dev/sda1 1014M 143M 872M 15% /boot
  13. tmpfs 183M 0 183M 0% /run/user/0

4、客户端访问共享资源

  1. //命令格式:mount -t nfs nfs服务器端ip:/共享目录 挂载点
  2. 或者
  3. //命令格式:mount.nfs nfs服务器端ip:/共享目录 挂载点
  4. [root@nfsclient ~]# mount.nfs 10.0.0.140:/nfsdir /sharedir
  5. [root@nfsclient ~]# df -h
  6. 文件系统 容量 已用 可用 已用% 挂载点
  7. /dev/mapper/centos-root 50G 1.1G 49G 3% /
  8. devtmpfs 901M 0 901M 0% /dev
  9. tmpfs 912M 0 912M 0% /dev/shm
  10. tmpfs 912M 8.6M 904M 1% /run
  11. tmpfs 912M 0 912M 0% /sys/fs/cgroup
  12. /dev/mapper/centos-home 27G 33M 27G 1% /home
  13. /dev/sda1 1014M 143M 872M 15% /boot
  14. tmpfs 183M 0 183M 0% /run/user/0
  15. 10.0.0.140:/nfsdir 50G 2.0G 49G 4% /sharedir
  16. // 最后一行说明已经挂载成功

三、测试

1、在服务端创建一个文件夹,并写入文件

  1. [root@NFSserver ~]# cd /nfsdir/
  2. [root@NFSserver nfsdir]# ls
  3. [root@NFSserver nfsdir]# ll
  4. 总用量 0
  5. [root@NFSserver nfsdir]# touch test.txt
  6. [root@NFSserver nfsdir]# echo "I am so cool!" > test.txt

2、在客户端查看服务端共享的文件

  1. [root@nfsclient ~]# cd /sharedir/
  2. [root@nfsclient sharedir]# ls
  3. test.txt
  4. [root@nfsclient sharedir]# ll
  5. 总用量 4
  6. -rw-r--r--. 1 root root 14 7 29 16:23 test.txt
  7. [root@nfsclient sharedir]# cat test.txt
  8. I am so cool!

四、拓展

1、客户端开机自动挂载

  1. [root@nfsclient ~]# vim /etc/fstab
  2. .........
  3. 10.0.0.140:/nfsdir /sharedir nfs default,_rnetdev 0 0
  4. //在文件的最后写入

Linux_搭建NFS服务(基础)的更多相关文章

  1. 搭建NFS服务

    说明:这里是Linux服务综合搭建文章的一部分,本文可以作为单独搭建yum仓库的参考. 注意:这里所有的标题都是根据主要的文章(Linux基础服务搭建综合)的顺序来做的. 如果需要查看相关软件版本和主 ...

  2. Linux搭建NFS服务

    一.NFS服务简单介绍 NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中, ...

  3. 搭建 NFS 服务 & 实时同步

    今日内容 NFS简介 实现 NFS 文件同步功能 NFS 配置详解 统一用户 搭建 web 服务 NFS 实现文件共享 内容详细 1.NFS 简介 1.1 介绍 实现多台 web 服务器可以共享数据资 ...

  4. linux服务搭建----NFS服务搭建

    nfs  服务     //配置脚本         /etc/exports     //服务器  发布目录     1> 确定需要发布的目录(想要共享的目录)     例如:      想发 ...

  5. Centos搭建NFS服务及客户端访问

    一.环境介绍 NFS服务端:192.168.200.101 NFS客户端:192.168.200.102 二.服务器端安装配置 1.查看rpcbind和nfs-utils安装包是否安装 [root@b ...

  6. NFS服务基础

    NFS服务部署: (一)NFS环境准备: 操作系统 角色 IP地址 CentOS Linux release 7.3.1611 (Core) NFS服务端 192.168.152.138 CentOS ...

  7. ubuntu下搭建nfs服务

    1. 安装nfs服务端 $ sudo apt install nfs-kernel-server -y 2. 创建目录 $ sudo mkdir -p /mnt/sharefolder 3. 使任何客 ...

  8. centos7搭建NFS服务

    服务器端 139.155.90.78 客户端  192.168.198.146 先查看自己的系统有没有安装rpcbind 和nfs-utils rpm -qa nfs-utils rpcbind 若使 ...

  9. centos7下搭建nfs服务

    现在有3台服务器 s1(主),s2(从), s3(从)需要实现文件实时同步,我们可以安装Nfs服务端和客户端来实现! 一.安装 NFS 服务器所需的软件包: yum install -y nfs-ut ...

随机推荐

  1. 201871010130-周学铭 实验三 结对项目—《D{0-1}KP 实例数据集算法实验平台》项目报告

    项目 内容 课程班级博客链接 18卓越班 这个作业要求链接 实验三结对编程要求 我的课程学习目标 体验软件项目开发中的两人合作,练习结对编程(Pair programming).掌握Github协作开 ...

  2. Dynamics CRM修改密码界面

    我们再实施Dynamics CRM的过程中经常会被客户吐槽没有一个修改密码的页面.市面上也有一些人通过自己操作AD库进行修改密码的解决方案不过多多少少会有一些BUG存在.其实ADFS提供了一个修改密码 ...

  3. 批处理文件设置IP以及DNS

    先附上批处理文件代码(批处理文件怎么创建自己另行百度,这里不再赘述) Echo offecho ==============请输入序号修改办公区===========echo *********1.家 ...

  4. Kubernetes 学习笔记-- kafka往couchdb里倒东西

    首先吐槽下国内这些论坛的技术精神,不是我崇洋媚外,有些复读机烦不烦啊,别人的东西吃进去吐出来好玩么? 还有一些不懂装懂,这种最可恶,明明自己都不明白自己在写什么,还是往精华区发,简直离谱,知道自己多挣 ...

  5. 12.Quick QML-QML 布局(Row、Column、Grid、Flow和嵌套布局) 、Repeater对象

    1.Row布局 Row中的item可以不需要使用anchors布局,就能通过行的形式进行布局. 并且item可以使用Positioner附加属性来访问有关其在Row中的位置及其他信息. 示例如下所示, ...

  6. 线程stop和Interrupt

    一:stop终止线程 举例子: public class ThreadStop { public static int i; public static int j; public static vo ...

  7. JAVAEE_Servlet_06_ServletContext接口

    ServletContext接口 * javax.servlet.ServletContext * Tomcat服务器中ServletContecxt的完整类名: ServletContext:org ...

  8. 基于Docker安装的MindSpore-1.2 GPU版本

    技术背景 在前面一篇博客中,我们介绍过MindSpore-CPU版本的Docker部署以及简单的案例测试,当时官方还不支持GPU版本的Docker容器化部署.经过MindSpore团队的努力,1.2. ...

  9. hdu3987 最小割边数

    题意:      是让你求最小割之后问最小割的最少边数是多少,因为最小割不是唯一的,所以存在最小边数的问法.思路:      两个方法,一个是先一遍最大流,然后把割边全都改成流量1,其他的全都改成流量 ...

  10. Python中Numpy模块的使用

    目录 NumPy ndarray对象 Numpy数据类型 Numpy数组属性 NumPy NumPy(Numerical Python) 是 Python 的一个扩展程序库,支持大量的维度数组与矩阵运 ...