Linux_搭建NFS服务(基础)
【RHEL8】—NFSserver ;【Centos7】—NFSclient
!!!测试环境我们首关闭防火墙和selinux(NFSserver和NFSclient都需要)
- [root@localhost ~]# systemctl stop firewalld
- [root@localhost ~]# systemctl disable firewalld
- [root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
- [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
- [root@NFSserver ~]# ifconfig
- ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 10.0.0.140 netmask 255.0.0.0 broadcast 10.255.255.255
- inet6 fe80::fa13:32e0:3b9f:2196 prefixlen 64 scopeid 0x20<link>
- ether 00:0c:29:cd:6a:1b txqueuelen 1000 (Ethernet)
- RX packets 5419 bytes 465927 (455.0 KiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 3930 bytes 558300 (545.2 KiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
- inet 127.0.0.1 netmask 255.0.0.0
- inet6 ::1 prefixlen 128 scopeid 0x10<host>
- loop txqueuelen 1000 (Local Loopback)
- RX packets 594 bytes 50308 (49.1 KiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 594 bytes 50308 (49.1 KiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、安装nfs-utils和rpcbind包
- [root@NFSserver ~]# yum install -y rpcbind nfs-utils
- [root@NFSserver ~]# rpm -qa rpcbind nfs-utils
- rpcbind-1.2.5-4.el8.x86_64
- nfs-utils-2.3.3-26.el8.x86_64
3、先启动rpcbind和nfs,并开启服务(!!!注意:必须先开启 rpcbind 然后再开启 nfs ,否则会出现问题!!!)
- [root@NFSserver ~]# systemctl start rpcbind
- [root@NFSserver ~]# systemctl enable rpcbind
- [root@NFSserver ~]# systemctl start nfs
- Failed to start nfs.service: Unit nfs.service not found.
- [root@NFSserver ~]# systemctl start nfs-server
- [root@NFSserver ~]# systemctl enable nfs-server
- Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.
- [root@NFSserver ~]# netstat -tunlp
- Active Internet connections (only servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
- tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
- tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 30223/rpc.mountd
- tcp 0 0 0.0.0.0:52373 0.0.0.0:* LISTEN 28778/rpc.statd
- tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1101/sshd
- tcp 0 0 0.0.0.0:35197 0.0.0.0:* LISTEN -
- tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
- tcp6 0 0 :::111 :::* LISTEN 1/systemd
- tcp6 0 0 :::20048 :::* LISTEN 30223/rpc.mountd
- tcp6 0 0 :::36949 :::* LISTEN -
- tcp6 0 0 :::22 :::* LISTEN 1101/sshd
- tcp6 0 0 :::41119 :::* LISTEN 28778/rpc.statd
- tcp6 0 0 :::2049 :::* LISTEN -
- udp 0 0 0.0.0.0:42713 0.0.0.0:* -
- udp 0 0 127.0.0.1:970 0.0.0.0:* 28778/rpc.statd
- udp 0 0 0.0.0.0:68 0.0.0.0:* 1611/dhclient
- udp 0 0 0.0.0.0:111 0.0.0.0:* 1/systemd
- udp 0 0 0.0.0.0:20048 0.0.0.0:* 30223/rpc.mountd
- udp 0 0 0.0.0.0:40540 0.0.0.0:* 28778/rpc.statd
- udp6 0 0 :::111 :::* 1/systemd
- udp6 0 0 :::35034 :::* 28778/rpc.statd
- udp6 0 0 :::33084 :::* -
- udp6 0 0 :::20048 :::* 30223/rpc.mountd


- 检查守护进程状态
- /etc/rc.d/init.d/rpcbind status
- 检查服务进程状态
- /etc/rc.d/init.d/nfs status
服务进程
4、服务端口查看
- [root@NFSserver ~]# rpcinfo -p
- 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
- 100024 1 udp 40540 status
- 100024 1 tcp 52373 status
- 100003 3 tcp 2049 nfs
- 100003 4 tcp 2049 nfs
- 100227 3 tcp 2049 nfs_acl
- 100021 1 udp 42713 nlockmgr
- 100021 3 udp 42713 nlockmgr
- 100021 4 udp 42713 nlockmgr
- 100021 1 tcp 35197 nlockmgr
- 100021 3 tcp 35197 nlockmgr
- 100021 4 tcp 35197 nlockmgr
- 100005 1 udp 20048 mountd
- 100005 1 tcp 20048 mountd
- 100005 2 udp 20048 mountd
- 100005 2 tcp 20048 mountd
- 100005 3 udp 20048 mountd
- 100005 3 tcp 20048 mountd
5、创建共享目录
- [root@NFSserver ~]# mkdir /nfsdir
- [root@NFSserver ~]# ll /nfsdir/
- 总用量 0
6、编辑NFS主配置文件
- [root@NFSserver ~]# vim /etc/exports
- [root@NFSserver ~]# cat /etc/exports
- /nfsdir 10.0.0.0/24(ro,rw)
- //第一次进入该文件为空白文件,需要使用者自行创建


- 1、/etc/exports文件格式
- <输出目录> [客户端1 选项(访问权限,用户映射,其他)] [客户端2 选项(访问权限,用户映射,其他)](exprots文件中每一行提供了一个共享目录的设置)
- 2、相关说明
- 1️⃣:输出目录:输出目录是指NFS系统中需要共享给客户机使用的目录;
- 2️⃣:客户端:客户端是指网络中可以访问这个NFS输出目录的计算机;
- 客户端常用的指定方式:
- 指定ip地址的主机:192.168.10.10
- 指定子网中的所有主机:192.168.10.0/24 192.168.10.*
- 指定域名的主机:www.test.com.cn
- 指定域中的所有主机:*.test.com.cn
- 所有主机:*
- 3️⃣:选项的种类:
- 1)、访问权限选项:
- 设置输出目录只读:ro
- 设置输出目录读写:rw
- 2)、用户映射选项:
- all_squash:将远程访问的所有普通用户及所属组都映射为匿名用户或用户组(nfsnobody);
- no_all_squash:与all_squash取反(默认设置);
- root_squash:将root用户及所属组都映射为匿名用户或用户组(默认设置);
- no_root_squash:与rootsquash取反;
- anonuid=xxx:将远程访问的所有用户都映射为匿名用户,并指定该用户为本地用户(UID=xxx);
- anongid=xxx:将远程访问的所有用户组都映射为匿名用户组账户,并指定该匿名用户组账户为本地用户组账户(GID=xxx);
- 3)、其它选项:
- secure:限制客户端只能从小于1024的tcp/ip端口连接nfs服务器(默认设置);
- insecure:允许客户端从大于1024的tcp/ip端口连接服务器;
- sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性;
- async:将数据先保存在内存缓冲区中,必要时才写入磁盘;
- wdelay:检查是否有相关的写操作,如果有则将这些写操作一起执行,这样可以提高效率(默认设置);
- no_wdelay:若有写操作则立即执行,应与sync配合使用;
- subtree:若输出目录是一个子目录,则nfs服务器将检查其父目录的权限(默认设置);
- no_subtree:即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率;
- no_root_squash:是让root保持权限;
- root_squash:是把root映射成nobody,no_all_squash 不让所有用户保持在挂载目录中的权限。
相关说明
7、重启NFS服务
- [root@NFSserver ~]# systemctl restart nfs-server
- [root@NFSserver ~]# netstat -tunlp
- Active Internet connections (only servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
- tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
- tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 30394/rpc.mountd
- tcp 0 0 0.0.0.0:52373 0.0.0.0:* LISTEN 28778/rpc.statd
- tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1101/sshd
- tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
- tcp 0 0 0.0.0.0:44931 0.0.0.0:* LISTEN -
- tcp6 0 0 :::111 :::* LISTEN 1/systemd
- tcp6 0 0 :::20048 :::* LISTEN 30394/rpc.mountd
- tcp6 0 0 :::46481 :::* LISTEN -
- tcp6 0 0 :::22 :::* LISTEN 1101/sshd
- tcp6 0 0 :::41119 :::* LISTEN 28778/rpc.statd
- tcp6 0 0 :::2049 :::* LISTEN -
- udp 0 0 127.0.0.1:970 0.0.0.0:* 28778/rpc.statd
- udp 0 0 0.0.0.0:68 0.0.0.0:* 1611/dhclient
- udp 0 0 0.0.0.0:111 0.0.0.0:* 1/systemd
- udp 0 0 0.0.0.0:47351 0.0.0.0:* -
- udp 0 0 0.0.0.0:20048 0.0.0.0:* 30394/rpc.mountd
- udp 0 0 0.0.0.0:40540 0.0.0.0:* 28778/rpc.statd
- udp6 0 0 :::111 :::* 1/systemd
- udp6 0 0 :::35034 :::* 28778/rpc.statd
- udp6 0 0 :::45389 :::* -
- udp6 0 0 :::20048 :::* 30394/rpc.mountd
二、客户端访问NFS服务器
1、客户端安装nfs-utils(其实原本需要在客户端安装的工具是showmount和mount.nfs,在安装这两个包时,就是安装的nfs-utils这个包)
- [root@nfsclient ~]# yum install -y nfs-utils
- [root@nfsclient ~]# rpm -qa nfs-utils
- nfs-utils-1.3.0-0.66.el7.x86_64
- [root@nfsclient ~]# which showmount mount.nfs
- /usr/sbin/showmount
- /usr/sbin/mount.nfs
- //出现命令的路径,说明已经安装
2、客户端查看服务端提供的共享资源
- //命令格式:showmount -e 服务器端ip
- [root@nfsclient ~]# showmount -e 10.0.0.140
- Export list for 10.0.0.140:
- /nfsdir 10.0.0.0/24
3、客户端创建需要挂载的目录
- [root@nfsclient ~]# mkdir /sharedir
- [root@nfsclient ~]# ll /sharedir/
- 总用量 0
- [root@nfsclient ~]# df -h
- 文件系统 容量 已用 可用 已用% 挂载点
- /dev/mapper/centos-root 50G 1.1G 49G 3% /
- devtmpfs 901M 0 901M 0% /dev
- tmpfs 912M 0 912M 0% /dev/shm
- tmpfs 912M 8.6M 904M 1% /run
- tmpfs 912M 0 912M 0% /sys/fs/cgroup
- /dev/mapper/centos-home 27G 33M 27G 1% /home
- /dev/sda1 1014M 143M 872M 15% /boot
- tmpfs 183M 0 183M 0% /run/user/0
4、客户端访问共享资源
- //命令格式:mount -t nfs nfs服务器端ip:/共享目录 挂载点
- 或者
- //命令格式:mount.nfs nfs服务器端ip:/共享目录 挂载点
- [root@nfsclient ~]# mount.nfs 10.0.0.140:/nfsdir /sharedir
- [root@nfsclient ~]# df -h
- 文件系统 容量 已用 可用 已用% 挂载点
- /dev/mapper/centos-root 50G 1.1G 49G 3% /
- devtmpfs 901M 0 901M 0% /dev
- tmpfs 912M 0 912M 0% /dev/shm
- tmpfs 912M 8.6M 904M 1% /run
- tmpfs 912M 0 912M 0% /sys/fs/cgroup
- /dev/mapper/centos-home 27G 33M 27G 1% /home
- /dev/sda1 1014M 143M 872M 15% /boot
- tmpfs 183M 0 183M 0% /run/user/0
- 10.0.0.140:/nfsdir 50G 2.0G 49G 4% /sharedir
- // 最后一行说明已经挂载成功
三、测试
1、在服务端创建一个文件夹,并写入文件
- [root@NFSserver ~]# cd /nfsdir/
- [root@NFSserver nfsdir]# ls
- [root@NFSserver nfsdir]# ll
- 总用量 0
- [root@NFSserver nfsdir]# touch test.txt
- [root@NFSserver nfsdir]# echo "I am so cool!" > test.txt
2、在客户端查看服务端共享的文件
- [root@nfsclient ~]# cd /sharedir/
- [root@nfsclient sharedir]# ls
- test.txt
- [root@nfsclient sharedir]# ll
- 总用量 4
- -rw-r--r--. 1 root root 14 7月 29 16:23 test.txt
- [root@nfsclient sharedir]# cat test.txt
- I am so cool!
四、拓展
1、客户端开机自动挂载
- [root@nfsclient ~]# vim /etc/fstab
- .........
- 10.0.0.140:/nfsdir /sharedir nfs default,_rnetdev 0 0
- //在文件的最后写入
Linux_搭建NFS服务(基础)的更多相关文章
- 搭建NFS服务
说明:这里是Linux服务综合搭建文章的一部分,本文可以作为单独搭建yum仓库的参考. 注意:这里所有的标题都是根据主要的文章(Linux基础服务搭建综合)的顺序来做的. 如果需要查看相关软件版本和主 ...
- Linux搭建NFS服务
一.NFS服务简单介绍 NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中, ...
- 搭建 NFS 服务 & 实时同步
今日内容 NFS简介 实现 NFS 文件同步功能 NFS 配置详解 统一用户 搭建 web 服务 NFS 实现文件共享 内容详细 1.NFS 简介 1.1 介绍 实现多台 web 服务器可以共享数据资 ...
- linux服务搭建----NFS服务搭建
nfs 服务 //配置脚本 /etc/exports //服务器 发布目录 1> 确定需要发布的目录(想要共享的目录) 例如: 想发 ...
- Centos搭建NFS服务及客户端访问
一.环境介绍 NFS服务端:192.168.200.101 NFS客户端:192.168.200.102 二.服务器端安装配置 1.查看rpcbind和nfs-utils安装包是否安装 [root@b ...
- NFS服务基础
NFS服务部署: (一)NFS环境准备: 操作系统 角色 IP地址 CentOS Linux release 7.3.1611 (Core) NFS服务端 192.168.152.138 CentOS ...
- ubuntu下搭建nfs服务
1. 安装nfs服务端 $ sudo apt install nfs-kernel-server -y 2. 创建目录 $ sudo mkdir -p /mnt/sharefolder 3. 使任何客 ...
- centos7搭建NFS服务
服务器端 139.155.90.78 客户端 192.168.198.146 先查看自己的系统有没有安装rpcbind 和nfs-utils rpm -qa nfs-utils rpcbind 若使 ...
- centos7下搭建nfs服务
现在有3台服务器 s1(主),s2(从), s3(从)需要实现文件实时同步,我们可以安装Nfs服务端和客户端来实现! 一.安装 NFS 服务器所需的软件包: yum install -y nfs-ut ...
随机推荐
- 201871010130-周学铭 实验三 结对项目—《D{0-1}KP 实例数据集算法实验平台》项目报告
项目 内容 课程班级博客链接 18卓越班 这个作业要求链接 实验三结对编程要求 我的课程学习目标 体验软件项目开发中的两人合作,练习结对编程(Pair programming).掌握Github协作开 ...
- Dynamics CRM修改密码界面
我们再实施Dynamics CRM的过程中经常会被客户吐槽没有一个修改密码的页面.市面上也有一些人通过自己操作AD库进行修改密码的解决方案不过多多少少会有一些BUG存在.其实ADFS提供了一个修改密码 ...
- 批处理文件设置IP以及DNS
先附上批处理文件代码(批处理文件怎么创建自己另行百度,这里不再赘述) Echo offecho ==============请输入序号修改办公区===========echo *********1.家 ...
- Kubernetes 学习笔记-- kafka往couchdb里倒东西
首先吐槽下国内这些论坛的技术精神,不是我崇洋媚外,有些复读机烦不烦啊,别人的东西吃进去吐出来好玩么? 还有一些不懂装懂,这种最可恶,明明自己都不明白自己在写什么,还是往精华区发,简直离谱,知道自己多挣 ...
- 12.Quick QML-QML 布局(Row、Column、Grid、Flow和嵌套布局) 、Repeater对象
1.Row布局 Row中的item可以不需要使用anchors布局,就能通过行的形式进行布局. 并且item可以使用Positioner附加属性来访问有关其在Row中的位置及其他信息. 示例如下所示, ...
- 线程stop和Interrupt
一:stop终止线程 举例子: public class ThreadStop { public static int i; public static int j; public static vo ...
- JAVAEE_Servlet_06_ServletContext接口
ServletContext接口 * javax.servlet.ServletContext * Tomcat服务器中ServletContecxt的完整类名: ServletContext:org ...
- 基于Docker安装的MindSpore-1.2 GPU版本
技术背景 在前面一篇博客中,我们介绍过MindSpore-CPU版本的Docker部署以及简单的案例测试,当时官方还不支持GPU版本的Docker容器化部署.经过MindSpore团队的努力,1.2. ...
- hdu3987 最小割边数
题意: 是让你求最小割之后问最小割的最少边数是多少,因为最小割不是唯一的,所以存在最小边数的问法.思路: 两个方法,一个是先一遍最大流,然后把割边全都改成流量1,其他的全都改成流量 ...
- Python中Numpy模块的使用
目录 NumPy ndarray对象 Numpy数据类型 Numpy数组属性 NumPy NumPy(Numerical Python) 是 Python 的一个扩展程序库,支持大量的维度数组与矩阵运 ...