4 在 RMT 服务器上镜像储存库 #
您可以在 RMT 服务器上镜像安装和更新储存库。这样便无需在每台计算机上下载更新,从而节省时间和容量。
在使用默认配置的情况下,RMT 每晚会自动镜像已启用的产品储存库一次。
    默认情况下,镜像的储存库存储在 /var/lib/rmt/public/repo 中。
  
      要更改镜像储存库的默认位置,请将 /usr/share/rmt/public/repo 符号链接指向所需的目录。这可以使用   命令来执行。
    
ln -sfn TARGET
      /usr/share/rmt/public/repo
      (请将 TARGET 替换为所需的目标)。确保该目标具有 rmt 用户和 nginx 组的读写权限。
    
    当启用的储存库完全镜像后,您可以通过在客户端计算机上运行 SUSEConnect --url
    https://RMT_HOSTNAME 来向 RMT 注册您的客户端系统。成功注册后,客户端计算机上的 Zypper 将使用来自 RMT 服务器的储存库。
  
RMT 不支持使用 SUSE Linux Enterprise Server 11 及以下版本的客户端。
4.1 镜像身份凭证 #
您需要有组织身份凭证才能创建 SUSE Linux Enterprise 储存库的本地镜像。您可以从 SUSE Customer Center 获取身份凭证。
要从 SUSE Customer Center 获取身份凭证,请执行以下步骤:
- 访问 SUSE Customer Center (http://scc.suse.com) 并登录。 
- 如果您是多个组织的成员,请从左侧边栏中选择要使用的组织。 
- 从顶部菜单中选择。 
- 右上角即会显示身份凭证。 
      应使用 YaST RMT 服务器配置模块对获取的身份凭证进行设置,或将其直接添加到 /etc/rmt.conf 文件中。有关 /etc/rmt.conf 文件的详细信息,请参见第 6.3.1 节 “/etc/rmt.conf”。
    
4.2 同步储存库元数据 #
需要使用从 SUSE Customer Center 下载的信息定期更新本地 RMT 数据库。其中包括有关可用产品和储存库的信息。
      同步是通过 systemd 计时器 rmt-server-sync.timer 实现的。要查看状态(例如下次运行时间),请使用 systemctl status:
    
#systemctl status rmt-server-sync.timer● rmt-server-sync.timer - RMT Sync timer Loaded: loaded (/usr/lib/systemd/system/rmt-server-sync.timer; enabled; vendor preset: disabled) Active: active (waiting) since Fri 2018-06-22 04:22:34 EDT; 2h 34min ago Trigger: Sat 2018-06-23 03:53:00 EDT; 20h left Jun 22 04:22:34 d31 systemd[1]: Started RMT Sync timer.
      要手动更新 RMT 数据库,请使用 rmt-cli
      sync 命令。有关详细信息,请参见第 6.1.2 节 “sync”。
    
4.3 镜像软件包 #
RMT 服务器上会镜像所启用的储存库的软件包。系统会每天定期下载一次软件包。不过,您也可以随时手动触发下载。
      定期镜像是通过 systemd 计时器 rmt-server-mirror.timer 实现的。要显示状态(例如下次运行时间),请使用 systemctl status:
    
#systemctl status rmt-server-mirror.timer● rmt-server-mirror.timer - RMT Mirror timer Loaded: loaded (/usr/lib/systemd/system/rmt-server-mirror.timer; enabled; vendor preset: disabled) Active: active (waiting) since Fri 2018-06-22 04:22:34 EDT; 2h 34min ago Trigger: Sat 2018-06-23 02:17:57 EDT; 19h left Jun 22 04:22:34 d31 systemd[1]: Started RMT Mirror timer.
      要手动更新镜像的软件包,请使用 rmt-cli
      mirror 命令。有关详细信息,请参见第 6.1.6 节 “mirror”。
    
4.4 启用和禁用储存库镜像 #
可以单独或者按产品启用或禁用储存库镜像。一次可以指定一个或多个储存库或产品。如果储存库处于启用状态,系统会在镜像过程中下载并更新其软件包。要启用或禁用储存库镜像,您需要提供产品字符串或 ID 或者储存库名称或 ID。您之所以想要启用或禁用某个产品,是因为这样会自动启用或禁用与该产品关联的所有储存库。
4.4.1 使用产品 #
        要启用或禁用产品的所有储存库,请使用 rmt-cli products enable
        ID 和 rmt-cli products
        disable ID 命令。要检索已启用产品的 ID,请使用 rmt-cli products
        list 命令。如果您想要获取仍然可用的已禁用产品的 ID,请运行 rmt-cli products list --all 命令。
      
示例:
>sudormt-cli products list --all+------+----------------------+---------+--------+--------------+--------------- | ID | Product | Version | Arch | Mirror? | Last mirrored +------+----------------------+---------+--------+--------------+--------------- [...] | 1743 | SUSE Package Hub | 15 | x86_64 | Don't Mirror | | | PackageHub/15/x86_64 | | | | [...]>sudormt-cli products enable 1743Found product by target 1743: SUSE Package Hub 15 x86_64. Enabling SUSE Package Hub 15 x86_64: SUSE Package Hub 15 x86_64: Enabled repository SLE-Module-Packagehub-Subpackages15-Pool. Enabled repository SLE-Module-Packagehub-Subpackages15-Updates. Enabled repository SUSE-PackageHub-15-Pool. Enabled repository SUSE-PackageHub-15-Standard-Pool..>sudormt-cli products disable 1743Found product by target 1743: SUSE Package Hub 15 x86_64. Disabling SUSE Package Hub 15 x86_64: SUSE Package Hub 15 x86_64: Disabled repository SLE-Module-Packagehub-Subpackages15-Pool. Disabled repository SLE-Module-Packagehub-Subpackages15-Updates. Disabled repository SUSE-PackageHub-15-Pool. Disabled repository SUSE-PackageHub-15-Standard-Pool. To clean up downloaded files, run 'rmt-cli repos clean'
要一次启用或禁用多个产品,请指定产品 ID 或字符串的空格分隔列表,例如:
>sudormt-cli products enable 1743 SLES/15/x86_64 SLES/12Found product by target 1743: SUSE Package Hub 15 x86_64. Enabling SUSE Package Hub 15 x86_64: SUSE Package Hub 15 x86_64: Enabled repository SLE-Module-Packagehub-Subpackages15-Pool. Enabled repository SLE-Module-Packagehub-Subpackages15-Updates. Enabled repository SUSE-PackageHub-15-Pool. Enabled repository SUSE-PackageHub-15-Standard-Pool. Found product by target SLES/15/x86_64: SUSE Linux Enterprise Server 15 x86_64. Enabling SUSE Linux Enterprise Server 15 x86_64: SUSE Linux Enterprise Server 15 x86_64: Enabled repository SLE-Product-SLES15-Pool. Enabled repository SLE-Product-SLES15-Updates. Enabled repository SLE15-Installer-Updates. Basesystem Module 15 x86_64: Enabled repository SLE-Module-Basesystem15-Pool. Enabled repository SLE-Module-Basesystem15-Updates. Server Applications Module 15 x86_64: Enabled repository SLE-Module-Server-Applications15-Pool. Enabled repository SLE-Module-Server-Applications15-Updates. Found product by target SLES/12: SUSE Linux Enterprise Server 12 x86_64. Enabling SUSE Linux Enterprise Server 12 x86_64: SUSE Linux Enterprise Server 12 x86_64: Enabled repository SLES12-Pool. Enabled repository SLES12-Updates.
4.4.2 使用储存库 #
        要启用或禁用特定储存库的镜像,请使用 rmt-cli repos enable ID 和 rmt-cli repos disable
        ID 命令。要检索已启用储存库的 ID,请使用 rmt-cli repos
        list 命令。如果您需要获取已禁用但可访问的储存库的 ID,请执行 rmt-cli repos list --all 命令。
      
示例:
>sudormt-cli repos list --all+--------+-------------------------+-------------------------------------------+ | ID | Name | Description | +--------+-------------------------+-------------------------------------------+ [...] | 3061 | SUSE-PackageHub-15-Pool | SUSE-PackageHub-15-Pool for sle-15-x86_64 | [...] +--------+-------------------------+-------------------------------------------+>sudormt-cli repos enable 3061Repository by ID 3061 successfully enabled.>sudormt-cli repos disable 3061Repository by ID 3061 successfully disabled. To clean up downloaded files, please run 'rmt-cli repos clean'
要一次启用或禁用多个储存库,请指定储存库 ID 的空格分隔列表,例如:
>sudormt-cli repos enable 2526 3263Repository by ID 2526 successfully enabled. Repository by ID 3263 successfully enabled.>sudormt-cli repos disable 2526 3263Repository by ID 2526 successfully disabled. Repository by ID 3263 successfully disabled. To clean up downloaded files, run 'rmt-cli repos clean'
4.5 删除镜像数据 #
按第 4.4 节 “启用和禁用储存库镜像”中所述禁用储存库或产品镜像后,已镜像的数据将保留在本地硬盘上。其中包括镜像的 RPM 软件包。
      要删除已禁用储存库的数据,请使用 rmt-cli
      repos clean 命令。使用此命令时,RMT 将校验是否仅镜像了已启用的储存库,并提供删除无效数据的途径。
    
      在去除任何数据之前,该命令将列出受影响的储存库,并要求用户输入 yes 以继续。
    
>sudormt-cli repos cleanRMT found locally mirrored files from the following repositories which are not marked to be mirrored: SLE-Product-SLES15-Updates for sle-15-x86_64 SLE-Product-SLES15-Pool for sle-15-x86_64 SLE15-Installer-Updates for sle-15-x86_64 Would you like to continue and remove the locally mirrored files of these repositories? Only 'yes' will be accepted. Enter a value: yes Deleted locally mirrored files from repository 'SLE-Product-SLES15-Updates for sle-15-x86_64'. Deleted locally mirrored files from repository 'SLE-Product-SLES15-Pool for sle-15-x86_64'. Deleted locally mirrored files from repository 'SLE15-Installer-Updates for sle-15-x86_64'. Clean finished. An estimated 157 MB were removed.
要删除已禁用的储存库数据,请手动去除其对应的目录:
>sudorm -r /usr/share/rmt/public/repo/SUSE/Products/PRODUCT/VERSION/ARCHITECTURE/
4.6 添加自定义储存库 #
      您可以使用 RMT 服务器镜像自定义储存库。这些储存库不是 SUSE Customer Center 提供的。它们可能是第三方供应商(例如 Open Build Service)提供的,也可能是使用 createrepo 创建的。
    
自定义储存库可以作为独立储存库使用,也可以关联到产品。这样,您便可以在已注册到 RMT 服务器的客户端上使用一个命令连接多个储存库。
下面的示例过程演示了镜像第三方储存库的过程。
- 将远程储存库添加到 RMT 服务器。将 URL 替换为储存库的 URL。将 NAME 替换为您为储存库所选择的名称。 - #- rmt-cli repos custom add URL NAME
- 列出所有自定义储存库以获取新储存库的 ID。 - #- rmt-cli repos custom list
- (可选)将新的自定义储存库关联到某个产品。例如,如果所有桌面客户端都需要这个新的自定义储存库,则可将其关联到 - SUSE Linux Enterprise Desktop产品。- #- rmt-cli repos custom attach REPOSITORY_ID PRODUCT_ID- 将 REPOSITORY_ID 替换为新自定义储存库的 ID。将 PRODUCT_ID 替换为要将储存库关联到的产品的 ID。如果您需要检索 PRODUCT_ID,请使用命令 - rmt-cli products list --all。重要- 当自定义储存库与某个产品相关联时,在该产品中注册的客户端将会发现它们处于禁用状态。要启用该储存库,请使用 - zypper lr命令确定其 ID,然后运行:- #zypper mr -e REPO_ID
- 启用新自定义储存库的镜像。 - #- rmt-cli repos custom enable REPOSITORY_ID
      要获取所有可用自定义储存库命令的列表,请参见第 6.1.4 节 “repos”。
    
4.7 导出和导入储存库 #
RMT 具有可导入和导出有关可用储存库和镜像软件包的数据的内置函数。例如,可以通过在本地复制已镜像的 RPM 软件包来加快新 RMT 服务器的设置。
另一个用例是脱机模式。通过脱机模式,可以将数据传输到断开连接的 RMT 服务器,从而实现为气隙网络中的计算机提供更新等目的。
      下面的过程说明了如何使用 USB 驱动器在两台 RMT 服务器之间传输数据及镜像的 RPM。服务器 sun 与 SUSE Customer Center 相连,而服务器 sirius 则位于气隙网络中。
    
- 登录到服务器 - sun。- root@sun #- rmt-cli sync- root@sun #- rmt-cli mirror
- 连接一个 USB 驱动器(假设为 - /dev/sdb),并将其挂载到所需位置(例如- /mnt/external)。- root@sun #- mount /dev/sdb1 /mnt/external
- 导出有关可用储存库和产品的数据。 - root@sun #- rmt-cli export data /mnt/external/
- 导出已启用储存库的列表。在下一步导出储存库时需要使用该导出文件。 - root@sun #- rmt-cli export settings /mnt/external/
- 导出镜像的 RPM 软件包。此过程可能需要较长时间,具体视镜像储存库的大小而定。 - root@sun #- rmt-cli export repos /mnt/external/
 
- 从 - sun卸载并拔出磁盘,然后转到- sirius。- root@sun #- umount /mnt/external
- 通过运行 - yast2 rmt在- sirius上设置 RMT(如果尚未执行该操作)。如果进行的是脱机 RMT 设置,请在屏幕上选择。
- 将 USB 驱动器连接到 - sirius,并将其挂载到- /mnt/external中。- root@sirius #- mount /dev/sdb1 /mnt/external
- 导入有关可用储存库和产品的元数据。 - root@sirius #- rmt-cli import data /mnt/external/
- 导入镜像的 RPM 软件包。此过程可能需要较长时间,具体视镜像储存库的大小而定。 - root@sirius #- rmt-cli import repos /mnt/external/
 
- 在 - sirius上根据需要启用储存库。有关详细信息,请参见第 4.4 节 “启用和禁用储存库镜像”。
        如果您的气隙服务器 (sirius) 具有许多启用的储存库,或者启用的储存库经常更改,我们建议从此服务器中导出储存库设置。
      
        然后可将导出的设置导入到与 SUSE Customer Center 相连的服务器 (sun) 中。这样便能确保 sun 下载 sirius 所需的所有数据。
      
