Linux中的NFS文件系统

1.安装nfs文件系统的软件
1 客户端和服务端都安装软件然后开启服务
服务端安装服务打开火墙开启服务
[root@shenzhen ~]# yum install nfs-utils
在这里插入图片描述
在这里插入图片描述
客户端安装服务,开启服务,打开防火墙
[root@localhost ~]# yum install nfs-utils
在这里插入图片描述
[root@localhost ~]# systemctl start nfs
在这里插入图片描述
2 打开两边的防火墙,服务端添加服务
服务端先添加nfs服务
在这里插入图片描述
客户端测试报错
在这里插入图片描述
服务端添加rpc-bind服务

[root@shenzhen ~]# firewall-cmd --permanent --add-service=rpc-bind 
success
[root@shenzhen ~]# firewall-cmd --reload
success

在这里插入图片描述
客户端再次查看,出现的报错与上次不同
在这里插入图片描述
服务端添加mountd服务

[root@shenzhen ~]# firewall-cmd --permanent --add-service=mountd
success
[root@shenzhen ~]# firewall-cmd --reload
success

在这里插入图片描述
客户端再次查看,查看成功
在这里插入图片描述
服务端列出所有服务

[root@shenzhen ~]# firewall-cmd --list-all
public (default, active)
  interfaces: eth0
  sources: 
  services: dhcpv6-client http mountd nfs rpc-bind ssh
  ports: 8080/tcp
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 

在这里插入图片描述
3 编辑文件

[root@shenzhen ~]# vim /etc/exports
/westos  *(ro,sync) (给所有人只读共享)
/westos (要共享的目录)   
刷新nfs服务
[root@shenzhen ~]# exportfs -rv
exporting *:/westos

在这里插入图片描述
在这里插入图片描述
4 客户端检测

[root@localhost ~]# showmount -e 172.25.254.127
Export list for 172.25.254.127:
/westos *

在这里插入图片描述
2.共享文件在客户端的自动挂载和自动卸载

1)系统默认挂载点,更改自动卸载时间
1 安装软件,开启服务
[root@localhost ~]# yum install autofs.x86_64 -y
在这里插入图片描述
[root@localhost ~]# systemctl start autofs
在这里插入图片描述

[root@localhost ~]# cd /net
[root@localhost net]# cd 172.25.254.127
[root@localhost 172.25.254.127]# ls
westos
[root@localhost 172.25.254.127]# cd westos
[root@localhost westos]# ls
file1  file2  file3

在这里插入图片描述
服务段可以验证,就是共享目录中的内容
在这里插入图片描述

可以看到共享目录已挂载到当前目录下
在这里插入图片描述
[root@localhost westos]# cd
默认的自动卸载是见是300S在这里插入图片描述
在这里插入图片描述
2 编辑配置文件

[root@localhost ~]# vim /etc/autofs
timeout=3
[root@localhost ~]# systemctl restart autofs.service

在这里插入图片描述
在这里插入图片描述
3 再次自动挂载
在这里插入图片描述
2)指定挂载目录

1 编辑主策略文件

[root@localhost ~]# vim /etc/auto.master
/opt                       /etc/auto.westos
最终挂载点的上层目录          子策略文件的名称

在这里插入图片描述
在这里插入图片描述
2 手动建立子策略文件
在这里插入图片描述

westos          172.25.254.127:/westos
最终挂载点        挂载目录(共享文件)

在这里插入图片描述
重启服务
在这里插入图片描述
3 访问目录/opt/westos自动挂载

[root@localhost ~]# cd /opt
[root@localhost opt]# ls
[root@localhost opt]# cd westos
[root@localhost westos]# ls
file1  file2  file3
[root@localhost westos]# df
文件系统                  1K-块    已用    可用 已用% 挂载点
/dev/vda1              10473900 3150140 7323760   31% /
devtmpfs                 927060       0  927060    0% /dev
tmpfs                    942648      80  942568    1% /dev/shm
tmpfs                    942648   17032  925616    2% /run
tmpfs                    942648       0  942648    0% /sys/fs/cgroup
172.25.254.127:/westos 10473984 3639552 6834432   35% /opt/westos

在这里插入图片描述
4 退出目录之后自动卸载
在这里插入图片描述

3.设置挂载的其他参数

1)设置所有用户只读挂载,但某个用户读写挂载

默认所有人的身份都会转换为nfsnobody------>匿名用户

[root@shenzhen ~]# vim /etc/exports
在这里插入图片描述
在这里插入图片描述
刷新

[root@shenzhen ~]# exportfs -rv
exporting 172.25.254.227:/westos
exporting *:/westos

在这里插入图片描述

测试:
客户端切换目录自动挂载。建立文件,查看属性,用户身份被转换

在这里插入图片描述
2)不转换身份建立文件

服务端
[root@shenzhen ~]# vim /etc/exports
/westos *(ro,sync) 172.25.254.227(rw,sync,no_root_squash)
在这里插入图片描述
刷新

[root@shenzhen ~]# exportfs -rv
exporting 172.25.254.227:/westos
exporting *:/westos

在这里插入图片描述
客户端:
在这里插入图片描述
3)指定加案例文件的用户身份

[root@shenzhen ~]# vim /etc/exports
/westos *(ro,sync) 172.25.254.227(rw,sync,anonuid=1002)
在这里插入图片描述
刷新

[root@shenzhen ~]# exportfs -rv
exporting 172.25.254.227:/westos
exporting *:/westos

客户端:
在这里插入图片描述
4)指定新建文件的所有组

服务端;
[root@shenzhen ~]# vim /etc/exports
/westos *(ro,sync) 172.25.254.227(rw,sync,anonuid=1002,anongid=1000)
在这里插入图片描述
刷新
[root@shenzhen ~]# exportfs -rv
exporting 172.25.254.227:/westos
exporting *:/westos

客户端测试:
在这里插入图片描述

[root@shenzhen ~]# id haha
uid=1002(haha) gid=1002(haha) 组=1002(haha)
[root@shenzhen ~]# id westos
uid=1001(westos) gid=1001(westos) 组=1001(westos)
[root@shenzhen ~]# id student
uid=1000(student) gid=1000(student) 组=1000(student),10(wheel)

5)指定挂载的版本,默认是ver4

客户端:
[root@localhost ~]# cd /opt/westos
[root@localhost westos]# mount
在这里插入图片描述
在这里插入图片描述
[root@localhost westos]# cd
编辑文件

[root@localhost westos]# vim /etc/auto.westos 
[root@localhost westos]# systemctl restart autofs

在这里插入图片描述

[root@localhost ~]# cd /opt/westos
[root@localhost westos]# mount
在这里插入图片描述
在这里插入图片描述
试验后将设置还原
在这里插入图片描述
6)指定挂载的模式

soft会有响应,返回报错
hard是会无限尝试

服务端:
1 soft
[root@shenzhen ~]# mount 172.25.254.127:/westos /mnt -o soft
[root@shenzhen ~]# mount
在这里插入图片描述
在这里插入图片描述
[root@shenzhen ~]# umount /mnt
2 hard
[root@shenzhen ~]# mount 172.25.254.127:/westos /mnt
[root@shenzhen ~]# mount
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_44224894/article/details/88652688