配置与管理NFS服务器

配置与管理NFS服务器

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

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

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

工作原理

安装NFS服务器

shell 复制代码
#查看必要软件包
[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服务器

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

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

3,配置NFS客户端

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

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

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

#卸载nfs服务器
umount 挂载点

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

综合案列

shell 复制代码
`	#配置一台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提供数据,可读

服务器

shell 复制代码
#在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

客户端

shell 复制代码
#安装客户端软件
[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
shell 复制代码
#在客户端上建立/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目录挂载到刚建的目录下
相关推荐
少妇的美梦5 小时前
logstash教程
运维
chen9455 小时前
k8s集群部署vector日志采集器
运维
chen9456 小时前
aws ec2部署harbor,使用s3存储
运维
christine-rr10 小时前
linux常用命令(4)——压缩命令
linux·服务器·redis
東雪蓮☆11 小时前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
qq_2642208911 小时前
LVS负载均衡群集和LVS+Keepalived群集
运维·负载均衡·lvs
乌萨奇也要立志学C++11 小时前
【Linux】进程概念(二):进程查看与 fork 初探
linux·运维·服务器
雨落Liy11 小时前
Nginx 从入门到进阶:反向代理、负载均衡与高性能实战指南
运维·nginx·负载均衡
Yyyy48212 小时前
Nginx负载均衡集群实验步骤
运维·nginx·负载均衡
绿箭柠檬茶12 小时前
Ubuntu 服务器配置转发网络访问
服务器·网络·ubuntu