7.22 NFS服务

一、nfs服务介绍
NFS(Network File System)⽹络⽂件系统
主要⽤于linux系统上实现⽂件共享的⼀种协议,其客户端主要是Linux
没有⽤户认证机制,且数据在⽹络上传送的时候是明⽂传送,⼀般只能在局域⽹中使⽤
⽀持多节点同时挂载及并发写⼊

该服务包括的组件:
RPC(Remote Procedure Call Protocol):
远程过程调⽤协议,它是⼀种通过⽹络从远程计算机程序上请求服务,不需要了解底层⽹络技术的协议

rpcbind       //负责NFS的数据传输,远程过程调⽤  ==tcp/udp协议 端⼝111==

nfs-utils       //控制共享哪些⽂件,权限管理

两台虚拟机(webserver,nfsserver)
webserver:

[root@webserver ~]# systemctl stop firewalld
[root@webserver ~]# systemctl disable firewalld
[root@webserver ~]# setenforce 0
[root@webserver ~]# vim /etc/selinux/config 
SELINUX=disabled
[root@localhost ~]# yum install --downloadonly --downloaddir=./soft nginx
[root@localhost ~]# ls soft/                      //安装包的位置

(1)安装createrepo制作仓库的软件
[root@localhost ~]# yum -y install createrepo
(2)把soft⽂件夹做成⼀个本地的⾃建仓库
[root@localhost ~]# createrepo soft/                   //使用createreop生成仓库
[root@localhost ~]# cd soft/
[root@localhost soft]# ls
(3)在/etc/yum.repos.d/下创建soft.repo
[root@localhost soft]# rm -rf /etc/yum.repos.d/*.repo            //删除其他仓库⽂件
[root@localhost soft]# vim /etc/yum.repos.d/soft.repo              //配置仓库文件
[soft]
name=soft_local
gpgcheck=0
baseurl=file:///root/soft
enable=1
[root@localhost soft]# yum clean all
[root@localhost soft]# yum makecache 
[root@localhost soft]# yum -y install nginx         //再次安装nginx,不用再次下载
[root@webserver ~]# nginx
[root@webserver ~]# netstat -lnput|grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2033/nginx: master  
tcp6       0      0 :::80                   :::*                    LISTEN      2033/nginx: master  

[root@nfsserver ~]# yum -y install nfs-utils.x86_64 rpcbind.x86_64             //      安装相关软件包

nfsserver:
[root@nfsserver ~]# yum -y install nfs-utils.x86_64 rpcbind.x86_64              //      安装相关软件包
[root@nfsserver ~]# mkdir /share                              //创建共享⽬录
[root@nfsserver ~]# touch /share/passwd                    
[root@nfsserver ~]# scp -r root@192.168.1.100:/usr/share/nginx/html /share/
[root@nfsserver ~]# vim /etc/exports                         //修改配置文件
./share  *(rw,sync)                            //sync同步,async异步
共享⽬录        共享选项


共享主机:
*   :代表所有主机
192.168.0.0/24:代表共享给某个⽹段
192.168.0.0/24(rw) 192.168.1.0/24(ro) :代表共享给不同⽹段
192.168.0.254:共享给某个IP
 *.itcast.com:代表共享给某个域下的所有主机

共享选项:
ro:只读
rw:读写
sync:实时同步,直接写⼊磁盘
async:异步,先缓存在内存再同步磁盘
anonuid:设置访问nfs服务的⽤户的uid,uid需要在/etc/passwd中存在
anongid:设置访问nfs服务的⽤户的gid
root_squash :默认选项 root⽤户创建的⽂件的属主和属组都变成nfsnobody,其他⼈nfs-server端是它⾃⼰,client端是nobody。
no_root_squash:root⽤户创建的⽂件属主和属组还是root,其他⼈server端是它⾃⼰uid,client端是nobody。
all_squash: 不管是root还是其他普通⽤户创建的⽂件的属主和属组都是nfsnobody

说明:
anonuid和anongid参数和all_squash⼀起使⽤。
all_squash表示不管是root还是其他普通⽤户从客户端所创建的⽂件在服务器端的拥有者和所属组都是nfsnobody;服务端为了对⽂件做相应管理,可以设置anonuid和anongid进⽽指定⽂件的拥有者和所属组


[root@nfsserver ~]# systemctl start rpcbind.service 
[root@nfsserver ~]# systemctl start nfs                              //启动服务
[root@nfsserver ~]# netstat -lnput|grep 111                    //查看端口占用
[root@nfsserver ~]# ls /share/            //共享目录
html  passwd  tdr.png
回到webserver:
[root@webserver ~]# mkdir /usr/share/nginx/html/static/                        //创建挂载点
[root@webserver ~]# mount -t nfs 192.168.1.125:/share /usr/share/nginx/html/static/          //挂载nfs-server端共享⽬录
[root@webserver ~]# df -h
文件系统                   容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root     17G   13G  4.5G   74% /
devtmpfs                   224M     0  224M    0% /dev
tmpfs                      236M     0  236M    0% /dev/shm
tmpfs                      236M  5.6M  230M    3% /run
tmpfs                      236M     0  236M    0% /sys/fs/cgroup
/dev/sr0                   8.8G  8.8G     0  100% /mnt
/dev/sda1                 1014M  130M  885M   13% /boot
tmpfs                       48M     0   48M    0% /run/user/0
192.168.1.125:/share        17G   12G  5.9G   66% /usr/share/nginx/html/static
[root@webserver ~]# ls /usr/share/nginx/html/static/
html  passwd  tdr.png                                         //可以看到nfsserver主机共享目录下的文件
[root@webserver ~]# vim /usr/share/nginx/html/index.html                   //测试
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
< img src="static/tdr.png" />
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值