配置与管理NFS服务器

本文详细介绍了如何在Linux系统中安装、配置NFS服务器,包括查看和安装必要的软件包,修改exports配置,以及配置NFS客户端挂载共享目录。还涉及了权限设置和防火墙管理等内容。
摘要由CSDN通过智能技术生成

配置与管理NFS服务器

NFS:即网络文件系统,只提供网络文件共享,不提供数据传输

作用:可以是用户在异构网络操作系统之间进行文件系统共享

概述:客户机与服务器之间可以共享文件,但不可数据传输功能;需要用到RPC(是一种进程间通过网络进行交互通信的机制)

工作原理image.png

安装NFS服务器

#查看必要软件包
[root@localhost ~]# rpm -qa | grep nfs-utils
[root@localhost ~]# rpm -qa | grep rpcbind
#yum安装NFS相关软件包
[root@localhost ~]# yum clean all
[root@localhost ~]# yum -y install nfs-utils rpcbind
#先启动rpc服务,再启动nfs服务
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs

配置NFS服务器

#改NFS配置文件/etc/exports,centos默认是没有exports文件需要手动添加
格式:共享目录 [客户端n(参数)]

(1)共享目录:nfs服务器需共享目录的实际路径
(2)客户端:指可以访问nfs服务器共享目录的计算机

image.png

3,配置NFS客户端

showmount命令:查看NFS服务器上的共享目录

#查看nfs服务器信息;关闭slinux和防火墙
showmount [选项] (参数)
-d:仅显示已被nfs服务器加载共享目录
-e:显示nfs服务器上所有的共享目录
参数:指定NFS服务器的IP地址或主机名

#挂载nfs服务器的共享目录
mount -t 服务器名或IP地址: 输出目录 本地挂载目录
当客户端上的用户无权访问nfs服务器上的共享目录,就无法进行挂载。
挂载成功后对目录的操作就等于在NFS服务器上的目录中进行操作。

#卸载nfs服务器
umount 挂载点

#启动时自动挂载nfs的共享目录
nfs服务器名或IP地址: 输出目录 本地挂载目录 nfs default 0 0

综合案列

`	#配置一台NFS服务器,IP地址为192.168.100.254.共享条件:
`(1)共享目录/mnt/share目录允许192.168.100.0/24网段访问,可读写
`(2)共享/mnt/managerdata目录允许zhang用户用IP地址192.168.100.0主机访问,可读写
`(3)共享/mnt/upload目录允许192.168.100.0/24网段主机作为上传目录,/mnt/upload的用户和所属组nfsupload,UID=GID=123
`(4)共享/home/nfs目录除允许192.168.100.0/24网段用户访问外,也向Internet提供数据,可读

服务器

#在nfs服务器端安装nfs服务软件包
[root@localhost ~]# yum -y install nfs-uils rpcbind

#创建相应目录和测试文件
[root@localhost ~]# mkdir -p /mnt/share
[root@localhost ~]# mkdir -p /mnt/managerdata
[root@localhost ~]# mkdir -p /mnt/upload
[root@localhost ~]# mkdir -p /mnt/nfs
[root@localhost ~]# touch /mnt/share/share1.txt
[root@localhost ~]# touch /mnt/share/share2.txt
[root@localhost ~]# touch /mnt/managerdata/managerdata1.txt
[root@localhost ~]# touch /mnt/managerdata/managerdata2.txt
[root@localhost ~]# touch /mnt/upload/upload.txt
[root@localhost ~]# touch /mnt/nfs1.txt
[root@localhost ~]# touch /mnt/nfs2.txt

#设置共享目录的权限属性
//要求1
[root@localhost ~]# chmod 1777 /mnt/share
[root@localhost ~]# ll -d /mnt/share/
drwxrwxrwt. 2 root root 42 May  1 08:58 /mnt/share
//要求2
[root@localhost ~]# useradd zhang
[root@localhost ~]# passwd zhang
Changing password for user zhang.
New password: 			#密码是:123
BAD PASSWORD: The password is a palindrome
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost mnt]# echo redhat | passwd --stdin zhang			#更新令牌
[root@localhost ~]# cat /etc/passwd |grep zhang
zhang:x:1001:1001::/home/zhang:/bin/bash
[root@localhost ~]# chmod 700 /mnt/managerdata/
[root@localhost ~]# chown -R zhang:zhang /mnt/managerdata/
[root@localhost ~]# ll -d /mnt/managerdata/
drwx------. 2 zhang zhang 54 May  2 20:40 /mnt/managerdata/

//要求3
[root@localhost ~]# groupadd -g 123 nfsupload
[root@localhost ~]# useradd -g 123 -u 123 -M nfsupload
[root@localhost ~]# cat /etc/passwd |grep nfs
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
nfsup:x:123:123::/home/nfsup:/bin/bash
[root@localhost ~]# chown -R nfsupload:nfsupload /mnt/upload
[root@localhost ~]# ll -d /mnt/upload
drwxr-xr-x. 2 nfsup nfsup 20 May  1 08:59 /mnt/up/
//要求4
[root@localhost ~]# ll -d /mnt/nfs
drwxr-xr-x. 2 root root 6 May  1 08:57 /mnt/nfs

#编辑/etc/exports文件
[root@localhost ~]# vim /etc/exports
/mnt/share      192.168.100.0/24(rw,no_root_squash)
/mnt/managerdata        192.168.100.10(rw)
/mnt/upload     192.168.100.0/24(rw,all_squash,anonuid=123,anongid=123)
/mnt/nfs        192.168.100.0/24 *(rw,sync,root_squash)

#关闭防火墙,设置Selinux为允许,并重启nfs服务
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce 
Permissive
[root@localhost ~]# systemctl restart nfs

客户端

#安装客户端软件
[root@localhost ~]# yum -y install nfs-utils
#连接服务器
[root@localhost mnt]# showmount -e 192.168.88.121
Export list for 192.168.88.121:
/mnt/nfs         (everyone)
/mnt/upload      192.168.100.0/24
/mnt/share       192.168.100.0/24
/mnt/managerdata 192.168.100.10

#在客户端上建立/mnt/CilentNFS目录,将NFS服务器上的/mnt/nfs目录挂载到刚建的目录下
[root@localhost mnt]# mkdir /mnt/CilentNFS/
[root@localhost mnt]# mount -t nfs 192.168.88.121:/mnt/nfs /mnt/ClientNFs/
[root@localhost mnt]# cd /mnt/ClientNFs/
[root@localhost ClientNFs]# ls
nfs1.txt  nfs2.txt
[root@localhost ClientNFs]# touch nfs3.txt
touch: cannot touch ‘nfs3.txt’: Permission denied

##在客户端上建立/mnt/CilentUpload目录,将NFS服务器上的/mnt/ClientUpload目录挂载到刚建的目录下

image.png

image.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值