一、题目要求
要求serverb来托管包含需要按需提供的重要文档的共享目录,当用户登录servera时,他们需要访问自动挂载的共享目录。
1、serverb将作为NFS共享导出/shares/indirect目录,其中包含west、central和east子目录。
2、serverb将作为NFS共享导出/shares/direct/external目录。
servera的预期挂载点是/external演示直接映射,另外一个挂载点是/internal演示间接映射。
二、开始安装autofs
yum install autofs
三、开始直接映射到indirect
1、在开始配置前可以使用mount挂载映射,来测试NFS服务器和共享
mount -t nfs serverb.lab.example.com:/shares/direct/external /mnt
查看:
ls -la /mnt/
total 4
drwxrws---. 2 root contractors 24 May 20 04:38 .
dr-xr-xr-x. 21 root root 279 May 20 05:16 ..
-rw-r--r--. 1 root contractors 22 May 20 04:38 README.txt
解除挂载:umount /mnt
2、开始直接映射挂载
所有直接映射都是以/-作为基础目录,在auto里面创建以autofs为开头文件
创建下列文件:
cat /etc/auto.master.d/direct.autofs
/- /etc/auto.direct
创建:cp /etc/auto.misc /etc/auto.direct
编辑直接挂载路径:
cat /etc/auto.direct
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
/external -fstype=nfs,rw,sync serverb.lab.example.com:/shares/direct/external
# the following entries are samples to pique your imagination
#linux -ro,soft,intr ftp.example.org:/pub/linux
#boot -fstype=ext2 :/dev/hda1
#floppy -fstype=auto :/dev/fd0
#floppy -fstype=ext2 :/dev/fd0
#e2floppy -fstype=ext2 :/dev/fd0
#jaz -fstype=ext2 :/dev/sdc1
#removable -fstype=ext2 :/dev/hdd
按需访问:需要访问时,才会显示挂载路径。
cd /external/
[root@servera external]# ls -al
total 4
drwxrws---. 2 root contractors 24 May 20 04:38 .
dr-xr-xr-x. 21 root root 279 May 20 05:16 ..
-rw-r--r--. 1 root contractors 22 May 20 04:38 README.txt
[root@servera external]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 887M 0 887M 0% /dev
tmpfs tmpfs 914M 0 914M 0% /dev/shm
tmpfs tmpfs 914M 17M 897M 2% /run
tmpfs tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/vda3 xfs 9.9G 1.6G 8.4G 16% /
/dev/vda2 vfat 100M 6.8M 94M 7% /boot/efi
tmpfs tmpfs 183M 0 183M 0% /run/user/1000
serverb.lab.example.com:/shares/direct/external nfs4 9.9G 1.6G 8.4G 16% /external
四、间接映射
1、还是继续使用mount检测挂载目录,
mount -t nfs serverb.lab.example.com:/shares/indirect /mnt/
输入完以上检测:
df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 887M 0 887M 0% /dev
tmpfs tmpfs 914M 0 914M 0% /dev/shm
tmpfs tmpfs 914M 17M 897M 2% /run
tmpfs tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/vda3 xfs 9.9G 1.6G 8.4G 16% /
/dev/vda2 vfat 100M 6.8M 94M 7% /boot/efi
tmpfs tmpfs 183M 0 183M 0% /run/user/1000
serverb.lab.example.com:/shares/direct/external nfs4 9.9G 1.6G 8.4G 16% /external
serverb.lab.example.com:/shares/indirect nfs4 9.9G 1.6G 8.4G 16% /mnt
有一条显示已经挂载到/mnt路径上了。
接触挂载:umount /mnt
2、开始间接映射:创建indirect.autofs文件。
cat /etc/auto.master.d/indirect.autofs
/internal /etc/auto.indirect
按照2步骤创造挂载路径的详细配置文件。
cp /etc/auto.misc /etc/auto.indirect
详细配置文件如下:cat /etc/auto.indirect
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
* -fstype=nfs,rw,sync serverb.lab.example.com:/shares/indirect/&
# the following entries are samples to pique your imagination
#linux -ro,soft,intr ftp.example.org:/pub/linux
#boot -fstype=ext2 :/dev/hda1
#floppy -fstype=auto :/dev/fd0
#floppy -fstype=ext2 :/dev/fd0
#e2floppy -fstype=ext2 :/dev/fd0
#jaz -fstype=ext2 :/dev/sdc1
#removable -fstype=ext2 :/dev/hdd