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

x33g5p2x  于2021-11-19 转载在 Linux  
字(2.1k)|赞(0)|评价(0)|浏览(293)

一、NFS服务配置步骤

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

(一)准备:主机名、网络、yum源

1、更改主机名:
[root@localhost ~]# hostnamectl set-hostname $主机名
[root@localhost ~]# bash	#环境变量重载
2、配置网络

(1)虚拟交换机、网络适配器选择仅主机模式,并且配置为192.168.100.0网段;

(2)编辑网络配置文件:

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
修改:	BOOTPROTO=static	#改为静态IP地址
	ONBOOT=yes		#改为开机自启
	IPADDR=192.168.100.10
	PREFIX=24  或者  NETMASK=255.255.255.0

(3)重启网络服务:

[root@localhost ~]# systemctl restart network
3、配置yum源

(1)先在VMware里面把系统镜像文件连接到虚拟机的光驱上;

(2)挂载光驱里的镜像:

[root@localhost ~]# mount /dev/cdrom /media

(3)修改yum源配置文件:

[root@localhost ~]# vim /etc/yum.repos.d/local.repo
	[rhel]
	name=rhel
	baseurl=file:///media
	enabled=1
	gpgcheck=0

(4)清空yum源缓存信息:

[root@localhost ~]# yum clean all

(5)检索当前yum源信息:

[root@localhost ~]# yum repolist

(二)配置NFS服务步骤

Server端:

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

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

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

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

3、开放读写权限:

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

4、修改配置文件:

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

5、生效配置:

[root@server ~]# exportfs -r

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

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

7、查看挂载目:

[root@server ~]# showmount -e 192.168.100.10

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

[root@server ~]# netstat -pant
Client端:

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

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

2、关闭SELinux服务:

[root@client ~]# setenforce  0

3、挂载共享目录:

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

4、查看挂载情况:

[root@client ~]# df -h

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

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

二、autofs自动挂载配置步骤

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

如上操作

(二)配置autofs步骤

Server端:

检查nfs是否开启:

[root@server ~]# systemctl status nfs

检查端口号:

[root@server ~]# netstat -pant

检查防火墙:

[root@server ~]# systemctl status firewalld
Client端:

先查看挂载目:

[root@client ~]# showmount -e 192.168.100.10

1、安装autofs:

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

2、配置/share:

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

3、配置pub:

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

4、重启并开启自启:

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

5、访问目录:

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

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

相关文章