autofs自动挂载

安装autofs

 

[root@Raygussie ~]# yum -y install autofs
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
CentOS-8 - AppStream - mirrors.aliyun.com         4.0 kB/s | 4.3 kB     00:01    
CentOS-8 - AppStream - mirrors.aliyun.com         2.2 MB/s | 6.3 MB     00:02    
CentOS-8 - Base - mirrors.aliyun.com              3.4 kB/s | 3.9 kB     00:01    
CentOS-8 - Base - mirrors.aliyun.com              983 kB/s | 2.3 MB     00:02    
CentOS-8 - Extras - mirrors.aliyun.com            1.4 kB/s | 1.5 kB     00:01    
CentOS-8 - Extras - mirrors.aliyun.com            4.0 kB/s | 9.2 kB     00:02    
Docker CE Stable - x86_64                         1.5 kB/s | 3.5 kB     00:02    
Dependencies resolved.

 

 

设置开机自动启动

 

[root@Raygussie ~]# systemctl enable --now autofs
Created symlink /etc/systemd/system/multi-user.target.wants/autofs.service → /usr/lib/systemd/system/autofs.service.

 

 

编辑主配置文件

[root@Raygussie ~]# vi /etc/auto.master

#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc   /etc/auto.misc
/media  /etc/cdrom.misc      //主配置挂载路径

 

编辑子配置文件

 

[root@Raygussie ~]# vi /etc/cdrom.misc

cdrom -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

 

 

 

重启autofs

[root@Raygussie ~]# systemctl restart autofs
[root@Raygussie ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               1.9G     0  1.9G   0% /dev
tmpfs                  2.0G     0  2.0G   0% /dev/shm
tmpfs                  2.0G  9.5M  2.0G   1% /run
tmpfs                  2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/mapper/rhel-root   17G  6.0G   12G  36% /
/dev/sda1             1014M  146M  869M  15% /boot

 

配置nfs服务器

创建nfs共享文件

 

[root@luyi ~]# yum -y install nfs-utils rpcbind
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:17:08 ago on Mon 15 Mar 2021 01:23:01 AM CST.
Package nfs-utils-1:2.3.3-35.el8.x86_64 is already installed.
Package rpcbind-1.2.5-7.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@luyi ~]# mkdir -p /nfsfile/test
[root@luyi ~]# echo "i am chinese" > /nfsfile/test/file

 

nfs服务端文件配置

[root@luyi ~]# vi /etc/exports

/nfsfile/test 192.168.186.* (rw,sync,root_squash)

nfs客户端配置

//安装nfs-utils和rpcbind
[root@Raygussie ~]# yum -y install nfs-utils rpcbind

使用showmount命令查询NFS服务端共享信息(建议关闭防火墙)

[root@Raygussie ~]# showmount -e 192.168.186.131
Export list for 192.168.186.131:
/nfsfile/test (everyone)

创建挂载目录

[root@Raygussie ~]# mkdir /nfsfile
[root@Raygussie ~]# mount 192.168.186.131:/nfsfile /nfsfile
[root@Raygussie ~]# cat /nfsfile/test/file
i am chinese

设置自动挂载

[root@Raygussie ~]# vi /etc/auto.master

#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc   /etc/auto.misc
/media  /etc/cdrom.misc
/nfsfile  /etc/test.misc

[root@Raygussie ~]# vi /etc/test.misc

test  -rw 192.168.186.131:/nfsfile

[root@Raygussie ~]# systemctl restart autofs
[root@Raygussie ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               1.9G     0  1.9G   0% /dev
tmpfs                  2.0G     0  2.0G   0% /dev/shm
tmpfs                  2.0G  9.0M  2.0G   1% /run
tmpfs                  2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/mapper/rhel-root   17G  2.3G   15G  14% /
/dev/sda1             1014M  146M  869M  15% /boot
tmpfs                  392M     0  392M   0% /run/user/0
[root@Raygussie ~]# cd /nfsfile/test
[root@Raygussie test]# df -h
Filesystem                Size  Used Avail Use% Mounted on
devtmpfs                  1.9G     0  1.9G   0% /dev
tmpfs                     2.0G     0  2.0G   0% /dev/shm
tmpfs                     2.0G  9.0M  2.0G   1% /run
tmpfs                     2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/mapper/rhel-root      17G  2.3G   15G  14% /
/dev/sda1                1014M  146M  869M  15% /boot
tmpfs                     392M     0  392M   0% /run/user/0
192.168.186.131:/nfsfile   17G  1.6G   16G  10% /nfsfile/test
[root@Raygussie test]# ls
test
[root@Raygussie test]# cat test/file 
i am chinese
[root@Raygussie test]#

 

posted @ 2021-03-15 09:01  Raygussie  阅读(64)  评论(0编辑  收藏  举报