20.4. 将 autofs 配置为使用 ldap 存储和检索自动挂载映射
您可以配置 autofs 服务,来检索存储在 LDAP 目录中的自动挂载映射。
先决条件
-
autofs和openldap软件包已安装。 - 为安全身份验证运行支持 Kerberos 的服务。
流程
-
要配置 LDAP 访问,请修改
/etc/openldap/ldap.conf文件。确保设置了BASE和URI选项,以反映合适的服务器和定位自动挂载条目的基础。 在
/etc/autofs.conf文件中,为自动挂载映射配置 LDAP 模式。默认情况下,autofs将按配置文件中指定的顺序检查常用的模式:# # Define the LDAP schema to used for lookups # # If no schema is set autofs will check each of the schemas # below in the order given to try and locate an appropriate # basdn for lookups. If you want to minimize the number of # queries to the server set the values here. # #map_object_class = nisMap #entry_object_class = nisObject #map_attribute = nisMapName #entry_attribute = cn #value_attribute = nisMapEntry # # Other common LDAP naming # #map_object_class = automountMap #entry_object_class = automount #map_attribute = ou #entry_attribute = cn #value_attribute = automountInformation # #map_object_class = automountMap #entry_object_class = automount #map_attribute = automountMapName #entry_attribute = automountKey #value_attribute = automountInformation注意您还可以明确设置这些值,来略微减少 LDAP 查询。您可以在
/etc/autofs.conf文件中以小写和大写形式写属性。rfc2307bis草案中描述了最近建立的用于在 LDAP 中存储自动映射的模式。要使用此模式,请通过取消ldap_schema选项的注释,并为其设置合适的值,来在/etc/autofs.conf文件中配置它。例如,如果您使用非标准模式,或需要覆盖默认行为,您可以在/etc/autofs.conf文件中指定相关的模式属性。以下值与常用的模式设置相对应,如rfc2307bis草案中的设置:default_map_object_class = automountMap default_entry_object_class = automount default_map_attribute = automountMapName default_entry_attribute = automountKey default_value_atrribute = automountInformation请注意,autofs 会自动检测标准模式,并且通常仅在自定义或混合架构环境中需要时才指定这些设置。如果使用了,应该只有一组完整的模式定义处于活动状态。
如果您选择在配置中指定自定义模式,请确保只有一组与模式相关的条目处于活动状态。注释掉任何其他内容以避免冲突。在
rfc2307bis模式中,automountKey属性代替了旧的rfc2307模式中使用的cn属性。以下是相应的 LDAP 数据交换格式(LDIF)配置的一个示例:# auto.master, example.com dn: automountMapName=auto.master,dc=example,dc=com objectClass: top objectClass: automountMap automountMapName: auto.master # /home, auto.master, example.com dn: automountMapName=auto.master,dc=example,dc=com objectClass: automount automountKey: /home automountInformation: auto.home # auto.home, example.com dn: automountMapName=auto.home,dc=example,dc=com objectClass: automountMap automountMapName: auto.home # foo, auto.home, example.com dn: automountKey=foo,automountMapName=auto.home,dc=example,dc=com objectClass: automount automountKey: foo automountInformation: filer.example.com:/export/foo # /, auto.home, example.com dn: automountKey=/,automountMapName=auto.home,dc=example,dc=com objectClass: automount automountKey: / automountInformation: filer.example.com:/export/&要允许从 LDAP 服务器进行身份验证,请编辑
/etc/autofs_ldap_auth.conf文件:-
将
authrequired更改为 yes。 将主体设置为 LDAP 服务器的 Kerberos 主机主体
host/FQDN@REALM。主体名称用于连接到目录,作为 GSS 客户端身份验证的一部分:<autofs_ldap_sasl_conf usetls="no" tlsrequired="no" authrequired="yes" authtype="GSSAPI" clientprinc="host/server.example.com@EXAMPLE.COM"/> secret="<ldap password>"/>有关主机主体的更多信息,请参阅在 在 IdM 中使用规范化的 DNS 主机名。您还可以运行
klist -k来获取确切的主机主体信息。
-
将