一、NFS概述
nfs共享存储服务 全称:netwoke file system 在计算机网络中共享文件系统的协议。
计算机之间可以通过网络共享目录和文件
rpcbind 远程共享调用
nfs 共享服务
配置nfs时,要先启动调用rpcbind在开启nfs
rpcbind端口111
nfs 2049(查询不到)
二、实验
实现指定主机进行共享
1、首先在opt目录下创建gx目录
主机ip192.168.10.20
vim /etc/exports
/opt/gx 192.168.10.40(rw,sync,no_root_squash)
主机也可以实现在同一网段下的所有主机均可访问,
192.168.10.0/24声明网段,谁可以访问本机的共享目录
rw读写 ro只读
sync同步写入到硬中(共享用户的操作)
no_root_squash如果客户机root用户访问共享目录,就给你和本机的root用户一样的权限
root_squash客户机root用户登录访问共享目录,就会把你变成匿名用户
vim /etc/exports
/opt/gx 192.168.10.0/24(rw,sync,no_root_squash) #192.168.10.0网段
2、安装服务
[root@localhost ~]# yum -y install rpcbind
[root@localhost ~]# yum -y install nfs-utils.x86_64
重启rpcbind在启动nfs
[root@localhost /]# systemctl restart rpcbind
[root@localhost /]# systemctl restart nfs
showmount -e 查看本机共享出去的目录
[root@localhost /]# showmount -e
Export list for localhost.localdomain:
/opt/gx 192.168.10.40
客户机 ip192.168.10.40
安装服务
[root@localhost ~]# yum -y install rpcbind
[root@localhost ~]# yum -y install nfs-utils.x86_64
重启rpcbind在启动nfs
[root@localhost /]# systemctl restart rpcbind
[root@localhost /]# systemctl restart nfs
showmount -e 192.168.10.20 查看目标主机暴露出的共享目录
[root@localhost test1]# showmount -e 192.168.10.20
Export list for 192.168.10.20:
/opt/gx 192.168.10.40
挂载
[root@localhost opt]# mount 192.168.10.20:/opt/gx /opt/test1
永久挂载
永久
192.168.10.20:/opt/gongxiang /opt/tests1 nfs defaults,_netdev 0 0
# _netdev :有网络该目录才能挂载成功
实现共享,均可对文件进行增删改查等操作
主机
客户机