nfs(网络文件系统)是unix系统和网络附加存储文件管理器常用的网络文件系统,允许多个客户端通过网络共享文件访问。它可用于提供对共享二进制目录的访问,也可以允许用户在同一工作组中从不同客户端访问其文件。
1、挂载
服务端
yum install nfs-utils -y
systemctl start nfs
systemctl restart firewalld
firewall-cmd --list-all
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=rpc-bind ##为客户分配端口
firewall-cmd --permanent --add-service=mountd ##用户挂载
firewall-cmd --reload
firewall-cmd --list-all
vim /etc/exports
1 /westos *(ro,sync) ##共享/westos *表示挂载给所有人,ro表示只读挂载,sync实时更新
exportfs -rv ##刷新修改
客户端
yum install nfs-utils -y
showmount -e 172.25.254.137
Export list for 172.25.254.137:
/westos *
mount 172.25.254.137:/westos /mnt/ ##挂载
df
2、自动挂载
1)
客户机
yum install autofs -y ##安装软件,实现自动挂载
systemctl start autofs
##vim /etc/sysconfig/autofs ##7.0以前版本
##rpm -qc autofs ##查看配置文件
vim /etc/autofs.conf ##7.0后版本的修改文件
15 timeout = 3 ##未操作下自动卸载时间为3秒
systemctl restart autofs
vim /etc/auto.master ##主配置文件
8 /opt /etc/auto.westos ##/opt是指定的要挂载的目录的上一目录, /etc/auto.westos是子配置文件
vim /etc/auto.westos
1 westos 172.25.254.137:/westos ##挂载再westos下,要挂载的是172.25.254.137:/westos
systemctl restart autofs.service
测试:
cd /opt
ls
cd westos
ls
df
显示挂载
cd
等待3妙
df
显示挂载已经卸
2)
服务端配置
vim /etc/exports
1 /westos *(ro,sync) 172.25.254.237(rw,sync) ##添加用户,读写权限n
exportfs -rv
客户端测试:
cd /opt/westos
touch file6
3)服务端配置
vim /etc/exports
1 /westos *(ro,sync) 172.25.254.237(rw,sync,no_root_squash) ##添加用户,读写权限no_root_squash,表示当用root用户时,保留用户名
exportfs -rv
客户端测试:
4)服务端配置
vim /etc/exports
1 /westos *(ro,sync) 172.25.254.237(rw,sync,anonuid=1002,anongid=1001) ##anonuid=1002,anongid=1001表示用户
exportfs -rv
测试在客户端:
5) 挂载选项
在客户端
vim /etc/auto.westos
westos -vers=3,soft 172.25.254.137:/westos ##添加soft参数,,如果nfs请求超时,三次尝试后返回错误,(默认是hard,当没有反馈时会无限次重试,会加大服务负载),vert=3使用其他nfs版本进行挂载,一般时向下兼容
cd /opt/westos
mount