centos8安装及配置nfs4
一,用rpm检查是否有nfs-utils的包已安装
[root@localhost liuhongdi]# rpm -qa | grep nfs-utils
nfs-utils-2.3.3-26.el8.x86_64
说明:架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,如果没有安装,在centos平台如何安装nfs?
[root@localhost liuhongdi]# dnf install nfs-utils
三,如何启动nfs?
[root@localhost liuhongdi]# systemctl start nfs-server
四,如何查看当前nfs服务所支持的nfs的版本?
[root@localhost liuhongdi]# cat /proc/fs/nfsd/versions
-2 +3 +4 +4.1 +4.2
说明:可以看到在nfs4的大版本下nfs2已经不被支持了
五,配置要导出的文件系统:
1,创建两个要共享的目录:
[root@localhost data]# mkdir /data/nfs
[root@localhost data]# cd /data/nfs
[root@localhost nfs]# mkdir rw
[root@localhost nfs]# mkdir ro
2,切换两个目录的owner:
[root@localhost nfs]# chown nginx.nginx *
[root@localhost nfs]# ll
总用量 0
drwxr-xr-x 2 nginx nginx 6 2月 24 11:11 ro
drwxr-xr-x 2 nginx nginx 6 2月 24 11:11 rw
说明:切换owner为我们要用来访问此目录的用户,
因为使用nginx访问,所以用户是nginx
说明2:查看nginx用户的id信息:
[root@localhost nfs]# cat /etc/passwd | grep nginx
nginx:x:973:973:Nginx web server:/var/lib/nginx:/sbin/nologin
说明:973:973 分别是用户的id和所属组的id
3,补充说明:如何手动创建一个nfs用户?
[root@localhost nfs]# useradd -u 1100 -s /sbin/nologin -M nfsuser
[root@localhost nfs]# id nfsuser
uid=1100(nfsuser) gid=1100(nfsuser) 组=1100(nfsuser)
说明:
-u : 指定用户uid
-M: --no-create-home 不创建用户home目录
-s : --shell 指定用户的shell
以上用法通过man命令可以了解到:
[root@localhost nfs]# man useradd
4,编辑配置文件:
[root@localhost srv]# vi /etc/exports
编辑的内容为:
/data/nfs/rw 192.168.3.162(rw,sync,all_squash,anonuid=973,anongid=973)
说明: /etc/exports是nfs默认的配置文件
说明:各项权限的说明:
rw:可读写
ro: 只读
no_root_squash:对root用户不压制,如果客户端以root用户写入,在服务端都映射为服务端的root用户
root_squash: nfs服务:默认情况使用的是相反参数root_squash,
如果客户端是用户root操作,会被压制成nobody用户
all_squash: 不管客户端的使用nfs的用户是谁,都会压制成nobody用户
insecure: 允许从客户端过来的非授权访问
sync: 数据同步写入到内存和硬盘
async: 数据先写入内存,不直接写入到硬盘
anonuid: 指定uid的值,此uid必须存在于/etc/passwd中
anongid:指定gid的值
5,配置完成后,如何使nfs配置生效?
说明:完成设置后,使用exportfs实用程序有选择地导出目录,而无需重新启动NFS服务
[root@localhost srv]# exportfs -rv
exporting 192.168.3.162:/data/nfs/rw
说明:exportfs的参数:
-r: Reexport all directories: 重新导出所有目录
-v: verbose,输出详情
6,如何查看当前配置为nfs共享的目录及其状态?
[root@localhost srv]# exportfs -v
/data/nfs/rw 192.168.3.162(sync,wdelay,hide,no_subtree_check,anonuid=973,anongid=973,sec=sys,rw,secure,root_squash,all_squash)
7,在本地做挂载测试:完整过程:
[root@localhost srv]# vi /etc/exports
说明:编辑内容:
/data/nfs/rw 192.168.3.162(rw,sync,all_squash,anonuid=973,anongid=973)
/data/nfs/ro 192.168.3.172(ro,sync,all_squash,anonuid=973,anongid=973)
其中:192.168.3.172是本机ip,可以挂载到本地
[root@localhost srv]# exportfs -rv
exporting 192.168.3.172:/data/nfs/ro
exporting 192.168.3.162:/data/nfs/rw
[root@localhost srv]# mount 192.168.3.172:/data/nfs/ro /mnt
[root@localhost mnt]# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 10M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 50G 6.5G 44G 13% /
/dev/mapper/cl-home xfs 26G 521M 25G 3% /home
/dev/sda1 ext4 976M 264M 646M 29% /boot
tmpfs tmpfs 376M 1.2M 375M 1% /run/user/42
tmpfs tmpfs 376M 4.6M 372M 2% /run/user/1000
/dev/sr0 iso9660 6.7G 6.7G 0 100% /run/media/liuhongdi/CentOS-8-BaseOS-x86_64
192.168.3.172:/data/nfs/ro nfs4 50G 6.5G 44G 13% /mnt
六,客户端测试挂载nfs
1,我们测试用的客户端是一台 fedora 30
[root@localhost liuhongdi]# cat /etc/redhat-release
Fedora release 30 (Thirty)
2,查看服务端输出的目录:
[root@localhost liuhongdi]# showmount -e 192.168.3.172
Export list for 192.168.3.172:
/data/nfs/ro 192.168.3.172
/data/nfs/rw 192.168.3.162
3,挂载到本地目录:
[root@localhost liuhongdi]# mount -t nfs 192.168.3.172:/data/nfs/rw /mnt
[root@localhost liuhongdi]# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 2.0G 1.6M 2.0G 1% /run
tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/fedora_localhost--live-root ext4 50G 22G 25G 47% /
tmpfs tmpfs 2.0G 4.0K 2.0G 1% /tmp
/dev/mapper/fedora_localhost--live-home ext4 25G 3.3G 20G 15% /home
/dev/sda1 ext4 976M 221M 688M 25% /boot
tmpfs tmpfs 391M 40K 391M 1% /run/user/1000
192.168.3.172:/data/nfs/rw nfs4 50G 6.4G 44G 13% /mnt
4,使客户端和服务端的用户id保持一致?
先查看本地nginx用户的id
[root@localhost mnt]# grep nginx /etc/passwd
nginx:x:979:979:Nginx web server:/var/lib/nginx:/sbin/nologin
把客户端的nginx用户id修改为和服务端一致:
[root@localhost mnt]# usermod -u 973 nginx
[root@localhost mnt]# groupmod -g 973 nginx
[root@localhost mnt]# grep nginx /etc/passwd
nginx:x:973:973:Nginx web server:/var/lib/nginx:/sbin/nologin
5,在客户端测试写入到nfs文件系统
[root@localhost mnt]# touch e.txt
[root@localhost mnt]# ll
总用量 0
-rw-r--r-- 1 root root 0 2月 24 14:03 a.txt
-rw-r--r-- 1 nginx nginx 0 2月 24 14:15 b.txt
-rw-r--r-- 1 nginx nginx 0 2月 24 14:18 c.txt
-rw-r--r-- 1 root root 0 2月 24 14:18 d.txt
-rw-r--r-- 1 nginx nginx 0 2月 24 14:21 e.txt
[root@localhost mnt]# sudo -u nginx more e.txt
[root@localhost mnt]# sudo -u nginx vi e.txt
[root@localhost mnt]# sudo -u nginx more e.txt
ccceee
说明:可以写入,以root写入和以nginx用户写入,效果一样,
文件的owner都是nginx
而且客户端使用客户端的nginx用户也可以正常的读写所创建的文件
6,生产环境中使用nfs4要注意的地方:
nfs的客户端往往不止一台,应该在搭建时把使用nfs的用户的uid/gid设置一致
避免读写时出现没有权限的错误
七,客户端机器启动后能自动加载nfs文件系统:
把mount命令:例如:mount -t nfs 192.168.3.172:/data/nfs/rw /mnt
写入到 /etc/rc.local
说明:有很多资料建议写入到/etc/fstab,
os启动时一般会先加载文件系统后启动网络,
在没有网络时nfs是无法加载的,总是出错,
所以还是建议放到/etc/rc.local中
八,如何查看nfs服务的版本?
1,客户端查看nfs服务的版本:
[sysop@webserver2 ~]$ nfsstat -m
2,服务端查看 nfs的版本
[root@loadserver ~]# nfsstat -s
3,客户端也可以用mount查看nfs服务的版本
[sysop@webserver2 ~]$ mount -v
4,如何查看nfsstat的帮助?
[root@loadserver ~]# nfsstat --help
九,查看本地centos的版本:
[root@localhost lib]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
centos8安装及配置nfs4的更多相关文章
- centos8 安装VNC配置远程连接
系统信息 [root@centos8 ~]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core) [root@centos8 ~] ...
- centos8安装fastdfs6.06集群方式三之:storage的安装/配置/运行
一,查看本地centos的版本 [root@localhost lib]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core) 说 ...
- centos8安装fastdfs6.06集群方式二之:tracker的安装/配置/运行
一,查看本地centos的版本 [root@localhost lib]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core) 说 ...
- CentOS7下NFS服务安装及配置固定端口
CentOS7下NFS服务安装及配置 系统环境:CentOS Linux release 7.4.1708 (Core) 3.10.0-693.el7.x86_64 软件版本:nfs-utils-1. ...
- centos8安装fastdfs6.06集群方式一之:软件下载与安装
一,查看本地centos的版本 [root@localhost lib]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core) 说 ...
- centos8 安装lnmp
1. 最小化安装 2. 配置基本信息 hostnamectl set-hostname aaa_name 为了每次系统重新启动时,都可以获取更大的ulimit值,将ulimit 加入到/etc/pro ...
- CentOS8 安装MySQL5.7
CentOS_8 安装MySQL5.7 1.在安装之前,如果你的系统曾经安装过Mariadb,请先卸载:yum remove mariadb*2.安装依赖 yum install -y epel-re ...
- CentOS8安装VirtualBox,并创建CentOS虚拟机
安装VirtualBox 执行以下命令并启用VirtualBox和EPEL包仓库 [root@localhost~] dnf config-manager --add-repo=https://dow ...
- CentOS8安装Geant4笔记(三):Geant4介绍、编译、安装支持Qt5界面并运行exampleB1例程显示Qt界面
前言 上一篇,安装了Qt5环境. 本篇在服务器CentOs8.2上安装geant4软件,geant4使用Qt5来显示. GEANT4 介绍 Geant4 是一个用于模拟粒子穿过物质的工具 ...
随机推荐
- synchronized的实现原理——锁膨胀过程
@ 目录 前言 正文 偏向锁 轻量锁 批量重偏向 批量撤销 重量锁 总结 前言 上一篇分析了优化后的synchronized在不同场景下对象头中的表现形式,还记得那个结论吗?当一个线程第一次获取锁后再 ...
- Java 9天入门(黑马程序员) 课程收尾 ------学生管理系统 (9.13)
1 实现功能 2 结构概述 分为两个包,各自一个类 Student.java 为学生类,目的是储存学生信息 StudentManager.java 是主程序的代码 3 Student.java 的代码 ...
- xss的变形--如何绕过xss过滤
我们可以通过构造xss代码进行各种变形,以绕过xss过滤器的检测 1.大小写检测 将payload进行大小写转化 如<Img SRC='#' Onerror="alert(/xss/ ...
- Linux磁盘管理及LVM讲解(1)
硬盘接口 从整体的角度上,硬盘接口分为IDE.SATA.SCSI和SAS四种,IDE接口硬盘多用于家用产品中,也部分应用于服务器,SCSI接口的硬盘则主要应用于服务器市场,而SAS只在高端服务器上,价 ...
- linux学习(一)认识阿里云
一.简介 阿里云,全球领先的云计算服务平台,阿里巴巴集团旗下公司.致力于打造公共.开放的云计算服务平台.提供云服务器ECS.关系型数据库服务RDS.开放存储服务OSS.内容分发网络CDN.对象存储OS ...
- Python-判断字符串是否以某个字符串开头或结尾?
案例: 某文件系统目录下有一系列文件: 1.c 2.py 3.java 4.sh 5.cpp ...... 编写一个程序,给其中所有的.sh文件和.py文件加上可执行权限 如何解决这个问题? 1. 先 ...
- Leetcode-dfs & bfs
102. 二叉树的层次遍历 https://leetcode-cn.com/problems/binary-tree-level-order-traversal/ 给定一个二叉树,返回其按层次遍历的节 ...
- MDK内的KEEP关键字以及$$Base $$Limit
使用mdk编程,假如有一个有用的函数你定义了但是没有显式的调用,mdk在默认方式下,将会把这个函数从整个程序总删除掉,以节省ROM. 比如,你在ROM的0x00002000处定位了一个函数,假设为vo ...
- USB虚拟串口 使用基于stm32的RT-Thread
参考我的RT Thread论坛文章 https://www.rt-thread.org/qa/thread-422644-1-1.html
- C语言普通写法实现:针对多次同步失败的节能处理机制
程序不美, 不来一一整理了. 以后有时间可以把这个功能封装为一个类的对象来操作.即使不封装为类,至少也该封装为一个独立的函数吧... 关键代码摘要如下: 无线同步信号发射端,每分钟发一次,每次发射的时 ...