#######
##nfs##
#######
##1.搭建环境,服务端共享出一个目录,客户端可以访问
服务端
vim /etc/yum.repos.d/rhel_dvd.repo 配置yum源
yum install nfs-utils -y 下载服务
firewall-cmd --get-services 在火墙里添加策略
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --permanent --add-service=mountd
firewall-cmd --reload
systemctl start nfs 开启服务
firewall-cmd --list-all
netstat -antlupe | grep nfs 查看端口
mkdir /westos/nfs -p 建立共享目录
vim /etc/exports 编辑目录规则
/westos/nfs *(sync) 时是更新目录
exportfs -rv 刷新更改的规则
客户端
showmount -e 172.25.254.11 显示挂载的共享目录
mount 172.25.254.11:/westos/nfs /mnt 挂载共享目录
df 查看挂载情况
##2.在客户端我想用的时候挂载不想用的时候不挂载
在客户端配置yum源
下载服务autofs.x86_64
ls -ld /net
ls: cannot access /net: No such file or directory
systemctl start autofs 开启服务自动产生/net目录
ls -ld /net
drwxr-xr-x. 2 root root 0 Dec 8 21:09 /net
systemctl stop autofs 关闭服务目录自动消失
ls -ld /net
ls: cannot access /net: No such file or directory
systemctl start autofs
vim /etc/sysconfig/autofs
timeout=5 编辑配置文件让挂载目录在不用时五秒自动卸载
systemctl restart autofs.service 重启服务
umount /mnt 先卸载挂载的共享目录
cd /net/172.25.254.11/westos/nfs/ 再进入11的共享目录
df查看挂载上了 过五秒以上再看已经卸载
##3.把共享目录挂载到指定的目录下
vim /etc/auto.master 编辑主配置目录
/westos/linux /etc/auto.nfs
挂载点的上层目录 指定到的子配置目录
vim /etc/auto.nfs
nfs -rw 172.25.254.139:/westos/nfs
挂载点 读取方式 共享设备和目录
systemctl restart autofs.service
cd /westos/linux/
ls 并没有显示linux下的nfs文件,但是可以切换进去
cd nfs
pwd 显示当前位置为/westos/linux/nfs
df 查看确实挂载到了自己指定的目录
##4.共享目录的读写
>>匿名读写
服务端
vim /etc/exports
/westos/nfs *(sync,rw)
exportfs -rv
chmod 777 /westos/nfs/
客户端
cd /westos/linux/nfs
touch file1
ls -l
total 0
-rw-r--r--. 1 nfsnobody nfsnobody 0 Dec 8 22:15 file1
>>指定id读写
服务端
vim /etc/exports
/westos/nfs *(sync,rw,anonuid=1000,anongid=1000)
exportfs -rv
客户端
touch file2
ls -l
total 0
-rw-r--r--. 1 nfsnobody nfsnobody 0 Dec 8 22:15 file1
-rw-r--r--. 1 student student 0 Dec 8 22:16 file2
>>客户端超户登陆服务端身份也是超户,其他人匿名
服务端
vim /etc/exports
/westos/nfs *(sync,rw,no_root_squash)
/westos/nfs 172.25.254.139(sync,rw,no_root_squash) *(sync,ro)
还可以配置不同的设备,如上139执行第一条策略 其他人执行后边策略
exportfs -rv
客户端
touch file3
ls -l
total 0
-rw-r--r--. 1 nfsnobody nfsnobody 0 Dec 8 22:15 file1
-rw-r--r--. 1 student student 0 Dec 8 22:16 file2
-rw-r--r--. 1 root root 0 Dec 8 22:17 file3