1. 要点概述
- nfs服务是什么
- nfs服务举例说明
- rpc与nfs的工作流程
- 安装使用
2. nfs服务及说明
Network File System 网络文件系统,主要用于各个主机之间共享文件,需要通过挂载的方式,客户端挂载服务端的共享目录,挂载后,大家共享一个目录,无论是客户端在共享目录的操作还是服务端在共享目录的操作,所有主机都是同步的、都是一样的,会让你感觉就像是在自己电脑上对某一个文件夹内的文件进行操作一样
挂载使用后,举例:
client1 在/share目录创建一个文件a.txt,client2和nfs服务端马上就能看到,如果client2对a.txt文件进行内容修改,那么另外两个主机可以同步看到
3. rpc与nfs
RPC与NFS
RPC是nfs服务里比较核心的东西,主要负责端口管理和注册,举例,nfs服务共享文件的时候,需要开放某些端口,此时需要先向rpc进行注册,注册成功后可以获得这些端口,由于这些端口是随机的,当客户端需要跟服务端进行文件传输的时候,就需要先向服务端的RPC询问相关文件通过哪些端口进行传输,查询到之后,再跟服务端的对应端口连接,进行文件的传输
rpc服务默认监听端口111
nfs服务默认监听端口2049
在启动nfs服务之前请务必确保rpcbind服务是启动的,如果rpcbind没有启动,那么你的nfs将无法使用
正确的操作是这样的:
systemctl start rpcbind
systemc start nfs
在图形化的centos7系统中,直接启动nfs服务就可以,会默认帮你启动rpcbind,但是在字符界面系统中,需要先启动rpcbind,否则nfs无法启动
4. nfs操作部分
1)检测服务端是否按照相应的软件包
[root@localhost ~]# rpm -qa | grep rpcbind
rpcbind-0.2.0-38.el7.x86_64
[root@localhost ~]# rpm -qa | grep nfs-utils
nfs-utils-1.3.0-0.33.el7.x86_64
如果未安装,用yum安装,如下:
[root@localhost ~]# yum -y install rpcbind nfs-utils
2)修改nfs服务配置文件
[root@localhost ~]# vim /etc/exports
/public 192.168.20.0/24(rw,sync,no_root_squash)
/public nfs的共享目录,如果没有,需要创建
192.168.20.0/24 表示允许访问共享目录的ip有哪些
(rw,sync,no_root_squash) 权限设置:
rw可读可写
sync表示将数据同时写入内存和磁盘,这种方式数据更安全
no_root_squash表示当客户端用root用户登录时,即获得root权限
root_squash 当客户端用root登录时,权限是匿名用户的权限
3)启动服务
[root@localhost ~]# mkdir /public
[root@localhost ~]# date > /public/date.txt
[root@localhost ~]# chmod -R 777 /public/
[root@localhost ~]# firewall-cmd --permanent --add-port=111/tcp
success
[root@localhost ~]# firewall-cmd --permanent --add-port=2049/tcp
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs
4)客户端使用nfs
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum -y install nfs-utils
[root@localhost ~]# mkdir /share
[root@localhost ~]# mount -t nfs 192.168.20.124:/public /share/
[root@localhost ~]# ls /share/
date.txt