NFS...

NFS实验

要求

开放/nfs/shared目录,供所有用户查阅资料
开放/nfs/upload目录为192.168.11.0/24网段的数据上传目录,并将所有用户及所属的用户组都映射为nfs-upload,其UID与GID均为300

配置步骤

服务端
安装启动nfs并关闭防火墙和selinux

[root@localhost ~]#  dnf -y install nfs-utils
[root@localhost ~]#  systemctl start nfs-server
[root@localhost ~]# ss -anlt
State   Recv-Q   Send-Q     Local Address:Port      Peer Address:Port  Process  
LISTEN  0        128              0.0.0.0:111            0.0.0.0:*              
LISTEN  0        128              0.0.0.0:20048          0.0.0.0:*              
LISTEN  0        128              0.0.0.0:22             0.0.0.0:*              
LISTEN  0        64               0.0.0.0:41631          0.0.0.0:*              
LISTEN  0        128              0.0.0.0:46975          0.0.0.0:*              
LISTEN  0        64               0.0.0.0:2049           0.0.0.0:*              
LISTEN  0        128                 [::]:111               [::]:*              
LISTEN  0        128                 [::]:20048             [::]:*              
LISTEN  0        64                  [::]:44819             [::]:*              
LISTEN  0        128                 [::]:22                [::]:*              
LISTEN  0        128                 [::]:60959             [::]:*              
LISTEN  0        64                  [::]:2049              [::]:*       
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

编辑/etc/exports文件

[root@localhost ~]# mkdir -p /nfs/upload
[root@localhost ~]# mkdir -p /nfs/shared

[root@localhost ~]# vim /etc/exports
/nfs/shared     *(ro)
/nfs/upload     192.168.11.*(rw,anonuid=300,anongid=300)

创建映射用户和共享目录并设置权限

[root@localhost ~]# vim /etc/exports
[root@localhost ~]# groupadd -r -g 300 nfs-upload
[root@localhost ~]# useradd -r -u 300 -g 300 nfs-upload
[root@localhost ~]# id nfs-upload
uid=300(nfs-upload) gid=300(nfs-upload) 组=300(nfs-upload)
[root@localhost ~]# setfacl -m u:nfs-upload:rwx /nfs/upload/
[root@localhost ~]# setfacl -m g:nfs-upload:rwx /nfs/upload/

重启服务

[root@localhost ~]# systemctl restart nfs-server

客户端
安装nfs并关闭防火墙和selinux

[root@localhost ~]# dnf -y install nfs-utils
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# ss -anlt
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port  Process  
LISTEN   0        32         192.168.122.1:53            0.0.0.0:*              
LISTEN   0        128              0.0.0.0:22            0.0.0.0:*              
LISTEN   0        5              127.0.0.1:631           0.0.0.0:*              
LISTEN   0        128              0.0.0.0:111           0.0.0.0:*              
LISTEN   0        128                 [::]:22               [::]:*              
LISTEN   0        5                  [::1]:631              [::]:*              
LISTEN   0        128                 [::]:111              [::]:*     

挂载
手动挂载

[root@localhost ~]# mount -t nfs 192.168.11.120:/nfs/ /media/
[root@localhost ~]#  df -h
文件系统             容量  已用  可用 已用% 挂载点
devtmpfs             865M     0  865M    0% /dev
tmpfs                895M     0  895M    0% /dev/shm
tmpfs                895M   18M  878M    2% /run
tmpfs                895M     0  895M    0% /sys/fs/cgroup
/dev/mapper/cs-root   17G  4.5G   13G   26% /
/dev/sda1           1014M  243M  772M   24% /boot
tmpfs                179M  1.2M  178M    1% /run/user/42
tmpfs                179M  3.4M  176M    2% /run/user/1000
/dev/sr0             9.0G  9.0G     0  100% /run/media/h/CentOS-Stream-8-x86_64-dvd
192.168.11.120:/nfs   17G  1.8G   16G   11% /media

测试

[root@localhost ~]#  cd /media/shared/
[root@localhost shared]# ls
[root@localhost shared]# ll
总用量 0
[root@localhost shared]# cd ../upload/
[root@localhost upload]# touch hf
[root@localhost upload]# ll
总用量 0
-rw-r--r--. 1 300 300 0 6月   6 03:56 hf

nfs工作流程

在这里插入图片描述

nfsnfs优点

a.节省本地存储空间将常用的数据存放在一台服务器可以通过网络访问
b.简单容易上手
c.方便部署非常快速,维护十分简单

nfs的应用场景

nfs有很多实际应用场景,以下是一些常用的场景:

多个机器共享一台CDROM或其他设备。这对于在多台机器中安装软件来说更加便宜与方便
在大型网络中,配置一台中心NFS服务器用来放置所有用户的home目录可能会带来便利。这些目录能被输出到网络以便用户不管在哪台工作站上登录,总能得到相同的home目录
不同客户端可在NFS上观看影视文件,节省本地空间
在客户端完成的工作数据,可以备份保存到NFS服务器上用户自己的路径下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值