RHCSA 08 - automount配置

Posted 王万林 Ben

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RHCSA 08 - automount配置相关的知识,希望对你有一定的参考价值。

前言

目录按需挂载,空闲时自动卸载,可以采用automount技术。尤其是在大型HPC环境,成千上万的用户家目录,使用automount降低seek time,提高dentry缓存命中率,可大大节省内存资源。

环境

RHEL 8

实践

安装nfs-utils,它提供nfs server,

[root@112c000520eb ~]# dnf install -y nfs-utils
Rocky Linux 8 - AppStream                                                            14 kB/s | 4.8 kB     00:00    
Rocky Linux 8 - AppStream                                                            20 MB/s | 8.8 MB     00:00    
Rocky Linux 8 - BaseOS                                                               17 kB/s | 4.3 kB     00:00    
Rocky Linux 8 - BaseOS                                                              8.7 MB/s | 3.6 MB     00:00    
Rocky Linux 8 - Extras                                                               14 kB/s | 3.5 kB     00:00    
Rocky Linux 8 - Extras                                                               39 kB/s |  11 kB     00:00    
Dependencies resolved.
====================================================================================================================
 Package                          Architecture          Version                         Repository             Size
====================================================================================================================
Installing:
 nfs-utils                        x86_64                1:2.3.3-51.el8                  baseos                503 k
Installing dependencies:
 gssproxy                         x86_64                0.8.0-20.el8                    baseos                118 k
 keyutils                         x86_64                1.5.10-9.el8                    baseos                 65 k
 libverto-libevent                x86_64                0.3.0-5.el8                     baseos                 15 k
 python3-pyyaml                   x86_64                3.12-12.el8                     baseos                192 k
 quota                            x86_64                1:4.04-14.el8                   baseos                213 k
 quota-nls                        noarch                1:4.04-14.el8                   baseos                 94 k
 rpcbind                          x86_64                1.2.5-8.el8                     baseos                 69 k

Transaction Summary
====================================================================================================================
Install  8 Packages

Total download size: 1.2 M
Installed size: 3.8 M
Downloading Packages:
(1/8): libverto-libevent-0.3.0-5.el8.x86_64.rpm                                     333 kB/s |  15 kB     00:00    
(2/8): gssproxy-0.8.0-20.el8.x86_64.rpm                                             2.3 MB/s | 118 kB     00:00    
(3/8): keyutils-1.5.10-9.el8.x86_64.rpm                                             1.2 MB/s |  65 kB     00:00    
(4/8): python3-pyyaml-3.12-12.el8.x86_64.rpm                                         16 MB/s | 192 kB     00:00    
(5/8): nfs-utils-2.3.3-51.el8.x86_64.rpm                                             23 MB/s | 503 kB     00:00    
(6/8): quota-nls-4.04-14.el8.noarch.rpm                                              10 MB/s |  94 kB     00:00    
(7/8): rpcbind-1.2.5-8.el8.x86_64.rpm                                                11 MB/s |  69 kB     00:00    
(8/8): quota-4.04-14.el8.x86_64.rpm                                                  10 MB/s | 213 kB     00:00    
--------------------------------------------------------------------------------------------------------------------
Total                                                                               4.5 MB/s | 1.2 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                            1/1 
  Running scriptlet: rpcbind-1.2.5-8.el8.x86_64                                                                 1/8 
  Installing       : rpcbind-1.2.5-8.el8.x86_64                                                                 1/8 
  Running scriptlet: rpcbind-1.2.5-8.el8.x86_64                                                                 1/8 
  Installing       : quota-nls-1:4.04-14.el8.noarch                                                             2/8 
  Installing       : quota-1:4.04-14.el8.x86_64                                                                 3/8 
  Installing       : python3-pyyaml-3.12-12.el8.x86_64                                                          4/8 
  Installing       : libverto-libevent-0.3.0-5.el8.x86_64                                                       5/8 
  Installing       : gssproxy-0.8.0-20.el8.x86_64                                                               6/8 
  Running scriptlet: gssproxy-0.8.0-20.el8.x86_64                                                               6/8 
  Installing       : keyutils-1.5.10-9.el8.x86_64                                                               7/8 
  Running scriptlet: nfs-utils-1:2.3.3-51.el8.x86_64                                                            8/8 
  Installing       : nfs-utils-1:2.3.3-51.el8.x86_64                                                            8/8 
  Running scriptlet: nfs-utils-1:2.3.3-51.el8.x86_64                                                            8/8 
  Verifying        : gssproxy-0.8.0-20.el8.x86_64                                                               1/8 
  Verifying        : keyutils-1.5.10-9.el8.x86_64                                                               2/8 
  Verifying        : libverto-libevent-0.3.0-5.el8.x86_64                                                       3/8 
  Verifying        : nfs-utils-1:2.3.3-51.el8.x86_64                                                            4/8 
  Verifying        : python3-pyyaml-3.12-12.el8.x86_64                                                          5/8 
  Verifying        : quota-1:4.04-14.el8.x86_64                                                                 6/8 
  Verifying        : quota-nls-1:4.04-14.el8.noarch                                                             7/8 
  Verifying        : rpcbind-1.2.5-8.el8.x86_64                                                                 8/8 

Installed:
  gssproxy-0.8.0-20.el8.x86_64        keyutils-1.5.10-9.el8.x86_64          libverto-libevent-0.3.0-5.el8.x86_64    
  nfs-utils-1:2.3.3-51.el8.x86_64     python3-pyyaml-3.12-12.el8.x86_64     quota-1:4.04-14.el8.x86_64              
  quota-nls-1:4.04-14.el8.noarch      rpcbind-1.2.5-8.el8.x86_64           

Complete!

创建目录并导出,启动nfs server,

[root@112c000520eb ~]# mkdir -p /users/nfs/lisa,linda,anna
[root@112c000520eb ~]# echo "/users *(rw,no_root_squash)" > /etc/exports
[root@112c000520eb ~]# systemctl enable --now nfs-server
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.
[root@112c000520eb ~]# showmount -e localhost
Export list for localhost:
/users *

在客户端,安装autofs,

[root@112c000520eb ~]# dnf install -y autofs
Last metadata expiration check: 0:00:19 ago on Sat 02 Jul 2022 07:14:43 AM CEST.
Dependencies resolved.
====================================================================================================================
 Package                  Architecture             Version                           Repository                Size
====================================================================================================================
Installing:
 autofs                   x86_64                   1:5.1.4-82.el8                    baseos                   706 k

Transaction Summary
====================================================================================================================
Install  1 Package

Total download size: 706 k
Installed size: 2.8 M
Downloading Packages:
autofs-5.1.4-82.el8.x86_64.rpm                                                      9.6 MB/s | 706 kB     00:00    
--------------------------------------------------------------------------------------------------------------------
Total                                                                               2.6 MB/s | 706 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                            1/1 
  Installing       : autofs-1:5.1.4-82.el8.x86_64                                                               1/1 
  Running scriptlet: autofs-1:5.1.4-82.el8.x86_64                                                               1/1 
  Verifying        : autofs-1:5.1.4-82.el8.x86_64                                                               1/1 

Installed:
  autofs-1:5.1.4-82.el8.x86_64                                                                                      

Complete!

参考/misc配置项,对家目录进行配置,并启动autofs服务,

[root@112c000520eb ~]# grep '^/misc' /etc/auto.master
/misc   /etc/auto.misc
[root@112c000520eb ~]# echo "/home/nfs  /etc/auto.nfs" >> /etc/auto.master
[root@112c000520eb ~]# grep -i linux /etc/auto.misc
#linux          -ro,soft                ftp.example.org:/pub/linux
[root@112c000520eb ~]# echo "*   -rw   localhost:/users/nfs/&" > /etc/auto.nfs
[root@112c000520eb ~]# systemctl enable --now autofs
Created symlink /etc/systemd/system/multi-user.target.wants/autofs.service → /usr/lib/systemd/system/autofs.service.

检查/home/nfs目录,没有任何文件(夹),

[root@112c000520eb ~]# ls -al /home/nfs
total 0
drwxr-xr-x. 2 root root  0 Jul  2 07:15 .
drwxr-xr-x. 4 root root 31 Jul  2 07:15 ..

触发一下其中一个子目录,可以看到挂载上了,

[root@112c000520eb ~]# cd /home/nfs/linda
[root@112c000520eb linda]# pwd
/home/nfs/linda
[root@112c000520eb linda]# mount | tail -5
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
/etc/auto.misc on /misc type autofs (rw,relatime,fd=5,pgrp=10818,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=41624)
-hosts on /net type autofs (rw,relatime,fd=11,pgrp=10818,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=41636)
/etc/auto.nfs on /home/nfs type autofs (rw,relatime,fd=17,pgrp=10818,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=41640)
/dev/mapper/rl-root on /home/nfs/linda type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)

后记

在大型HPC环境,一般在LDAP里配置好不同location的AUTOMOUNT,实现统一配置。

以上是关于RHCSA 08 - automount配置的主要内容,如果未能解决你的问题,请参考以下文章

RHCSA-A1.配置网络设置

RHCSA-A10.配置用户账户

RHCSA-A2.配置默认软件仓库

RHCSA-A7.配置NTP时间同步

RHCSA-A9.配置文件ACL权限

RHCSA-B2. 配置YUM源