Linux服务——二、配置NFS及autofs自动挂载服务

2021/11/16 7:10:00

本文主要是介绍Linux服务——二、配置NFS及autofs自动挂载服务,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、NFS服务配置步骤

NFS的作用:能够使两台虚拟机之间实现文件共享、数据同步

准备:主机名、网络、yum源

Server端:

1、安装nfs-util和rpcbind:(图形化自带)

[root@localhost ~]# yum -y install nfs-util rpcbind

2、新建共享目录及标记文件:

[root@localhost ~]# mkdir /opt/share
[root@localhost ~]# touch /opt/share/flag

3、开放读写权限:

[root@localhost ~]# chmod -R 777 /opt/share

4、修改配置文件:

[root@localhost ~]# vim /etc/exports
写入:/opt/share 192.168.100.0/24(rw,sync)

5、生效配置:

[root@localhost ~]# exportfs -r

6、启动并开机自启NFS服务:

[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl enable nfs

7、查看挂载目:

[root@localhost ~]# showmount -e 192.168.100.10

8、查看端口是否开启(111和2049):

[root@localhost ~]# netstat -pant

Client端:

1、安装nfs-util和rpcbind:(图形化自带)

[root@localhost ~]# yum -y install nfs-util rpcbind

2、关闭SELinux服务:

[root@localhost ~]# setenforce  0

3、挂载共享目录:

[root@localhost ~]# mount -t nfs 192.168.100.10:/opt/share /mnt

4、查看挂载情况:

[root@localhost ~]# df -h

5、在/mnt里面创建文件验证

[root@localhost ~]# cd /mnt
[root@localhost mnt]# touch abc

二、autofs自动挂载配置步骤

准备:要在NSF的基础上进行配置

Server端:

检查nfs是否开启:

[root@localhost ~]# systemctl  status  nfs

检查端口号:

[root@localhost ~]# netstat  -pant

检查防火墙:

[root@localhost ~]# systemctl  status  firewalld

Client端:

先查看挂载目:

[root@localhost ~]# showmount -e 192.168.100.10

1、安装autofs:

[root@localhost ~]# yum -y install autofs

2、配置/share:

[root@localhost ~]# vim /etc/auto.master.d/test.autofs
写入:/share	/etc/auto.test

3、配置pub:

[root@localhost ~]# vim /etc/auto.test
写入:pub	192.168.10.10:/opt/nfsshare

4、重启并开启自启:

[root@localhost ~]# systemctl restart autofs
[root@localhost ~]# systemctl enable autofs

5、访问目录:

[root@localhost ~]# cd /share/pub

注意:第一个文件要以autofs结尾,第二个配置文件名要与第一个配置文件里定义的参数一致



这篇关于Linux服务——二、配置NFS及autofs自动挂载服务的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程