1.NFS(网络文件服务)
NFS 是一种基于 TCP/IP 传输的网络文件系统协议
NFS 服务的实现依赖于 RPC(Remote Process Call,远端过程调用)机制,以完成远 程到本地的映射过程。在 CentOS 7 系统中,需要安装 nfs-utils、rpcbind 软件包来提供 NFS 共享服务,前者用于 NFS 共享发布和访问,后者用于 RPC 支持。NFS端口号2049,RPC端口号111
但是,NFC没有用户认证机制,而且数据在网络上明文传输,所以安全性很差,一般只能在局域网内使用
2.配置案例
2.1 安装nfs-utils、rpcbind 软件包
[root@localhost ~]# yum -y install nfs-utils.x86_64 rpcbind.x86_64
。。。
nfs-utils.x86_64 1:1.3.0-0.68.el7 rpcbind.x86_64 0:0.2.0-49.el7
完毕!
[root@localhost ~]#
2.2 设置共享目录
NFS的配置文件为/etc/exports,文件内容默认为空(无任何共享)。在exports文件中的记录格式为
<目录位置> <客户机地址>(权限选项)
[root@localhost ~]# mkdir -p /www/html //创建共享目录
[root@localhost ~]# vi /etc/exports //编辑配置文件
/www/html 192.168.30.5(rw,sync,no_root_squash) //将/www/html共享给主机192.168.30.5(允许读写,同步写入,赋予root权限)
~
2.3 启动服务
[root@localhost ~]# systemctl start rpcbind //先启动rpcbind
[root@localhost ~]# systemctl start nfs //再启动nfs
[root@localhost ~]# netstat -anpt |grep 111 //监听rpcbind端口
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 72854/rpcbind
tcp 0 0 192.168.30.5:22 192.168.30.254:62433 ESTABLISHED 9111/sshd: root@not
tcp6 0 0 :::111 :::* LISTEN 72854/rpcbind
[root@localhost ~]# showmount -e //查看本机发布的nfs共享目录
Export list for localhost.localdomain:
/www/html 192.168.30.5
2.4 客户机安装启动服务
[root@localhost ~]# systemctl start rpcbind //先启动rpcbind
[root@localhost ~]# systemctl start nfs //再启动nfs
[root@localhost ~]# showmount -e 192.168.30.4 //查看该服务器共享目录
Export list for 192.168.30.4:
/www/html 192.168.30.5
[root@localhost ~]#
2.5 客户机创建挂载点并挂载共享目录
[root@localhost etc]# mount -t nfs 192.168.30.4:/www/html /var/www/html //挂载网络节点
[root@localhost etc]# cd /var/www/html/ //进入挂载点
[root@localhost html]# ls //查看文件(在nfs服务器上新建的1)
1
2.6 客户机尝试创建文件
2.7 模拟nfs服务器挂掉