Red Hat Training

A Red Hat training course is available for RHEL 8

35.8. 将 ID 视图应用到 IdM 主机组

ipa idview-apply 命令接受 --hostgroups 选项。不过,选项充当一次性操作,它将 ID 视图应用到当前属于指定主机组的主机,但不动态地将 ID 视图与主机组本身关联。--hostgroups 选项将展开指定主机组的成员,并将 --hosts 选项分别应用到其中的每一个成员。

如果稍后向主机组添加新主机,您必须使用 ipa idview-apply 命令及 --hosts 选项,手动将 ID 视图应用到新主机。

类似地,如果您从主机组中删除主机,则移除后 ID 视图仍会分配给该主机。要从删除的主机中取消 ID 视图应用,您必须运行 ipa idview-unapply id_view_name --hosts=name_of_the_removed_host 命令。

按照以下流程实现以下目标:

  1. 如何创建主机组并向其添加主机。
  2. 如何将 ID 视图应用到主机组。
  3. 如何向主机组添加新主机,并将 ID 视图应用到新主机。

先决条件

流程

  1. 创建主机组并为其添加主机:

    1. 创建主机组.例如,创建名为 baltimore 的主机组:

      [root@server ~]# ipa hostgroup-add --desc="Baltimore hosts" baltimore
      ---------------------------
      Added hostgroup "baltimore"
      ---------------------------
      Host-group: baltimore
      Description: Baltimore hosts
    2. 将主机添加到主机组。例如,将 host102host103 添加到 baltimore 主机组:

      [root@server ~]# ipa hostgroup-add-member --hosts={host102,host103} baltimore
      Host-group: baltimore
      Description: Baltimore hosts
      Member hosts: host102.idm.example.com, host103.idm.example.com
      -------------------------
      Number of members added 2
      -------------------------
  2. 将 ID 视图应用到主机组中的主机。例如,要将 example_for_host1 ID 视图应用到 baltimore 主机组:

    [root@server ~]# ipa idview-apply --hostgroups=baltimore
    ID View Name: example_for_host1
    -----------------------------------------
    Applied ID View "example_for_host1"
    -----------------------------------------
      hosts: host102.idm.example.com, host103.idm.example.com
    ---------------------------------------------
    Number of hosts the ID View was applied to: 2
    ---------------------------------------------
  3. 将新主机添加到主机组,并将 ID 视图应用到新主机:

    1. 将新主机添加到主机组。例如,要将 somehost.idm.example.com 主机添加到 baltimore 主机组:

      [root@server ~]# ipa hostgroup-add-member --hosts=somehost.idm.example.com baltimore
        Host-group: baltimore
        Description: Baltimore hosts
        Member hosts:  host102.idm.example.com, host103.idm.example.com,somehost.idm.example.com
      -------------------------
      Number of members added 1
      -------------------------
    2. (可选)显示 ID 视图信息。例如,要显示 example_for_host1 ID 视图的详情:

      [root@server ~]# ipa idview-show example_for_host1 --all
        dn: cn=example_for_host1,cn=views,cn=accounts,dc=idm,dc=example,dc=com
        ID View Name: example_for_host1
      [...]
        Hosts the view applies to: host102.idm.example.com, host103.idm.example.com
        objectclass: ipaIDView, top, nsContainer

      输出显示 ID 视图没有应用到 somehost.idm.example.com(在 baltimore 主机组中新添加的主机)。

    3. 将 ID 视图应用到新主机。例如,要将 example_for_host1 ID 视图应用到 somehost.idm.example.com

      [root@server ~]# ipa idview-apply --host=somehost.idm.example.com
      ID View Name: example_for_host1
      -----------------------------------------
      Applied ID View "example_for_host1"
      -----------------------------------------
        hosts: somehost.idm.example.com
      ---------------------------------------------
      Number of hosts the ID View was applied to: 1
      ---------------------------------------------

验证步骤

  • 再次显示 ID 视图信息:

    [root@server ~]# ipa idview-show example_for_host1 --all
      dn: cn=example_for_host1,cn=views,cn=accounts,dc=idm,dc=example,dc=com
      ID View Name: example_for_host1
    [...]
      Hosts the view applies to: host102.idm.example.com, host103.idm.example.com, somehost.idm.example.com
      objectclass: ipaIDView, top, nsContainer

    输出显示 ID 视图现在已应用到 somehost.idm.example.com(在 baltimore 主机组中新添加的主机)。