准备 Red Hat/CentOS 7 模板的推荐方法是什么?

Aar*_*ley 9 virtualization redhat centos templates disk-image

如果我需要从模板部署 Red Hat 7,我想采取推荐的步骤来使我的“黄金映像”变得干净。它应该引导到第一个引导提示并引导用户完成典型步骤。

在 Red Hat 5/6 中,我遵循了供应商提供的文档。但是,我找不到 Red Hat 7 的等效项。具体来说,touch /.unconfigured不会触发第一次启动设置。

9.3.1. 密封 Linux 虚拟机以作为模板进行部署

总结
在将 Linux 虚拟机制作成模板之前对其进行泛化(密封)。这可以防止从模板部署的虚拟机之间发生冲突。

程序 9.6。密封 Linux 虚拟机

登录虚拟机。通过以 root 身份运行以下命令来标记系统以进行重新配置:

  1. # touch /.unconfigured
  2. 删除 ssh 主机密钥。跑:
    # rm -rf /etc/ssh/ssh_host_*
  3. 设置HOSTNAME=localhost.localdomain/etc/sysconfig/network
  4. 删除 /etc/udev/rules.d/70-*。跑:
    # rm -rf /etc/udev/rules.d/70-*
  5. 从 中删除HWADDR=UUID=/etc/sysconfig/network-scripts/ifcfg-eth*
  6. (可选)从 中删除所有日志/var/log并从中构建日志/root
  7. 关闭虚拟机。跑:
    # poweroff

编辑:步骤 1 和 7 可以通过sys-unconfig最后运行来组合。或者,virt-syspreplibguestfs-tools-c中查看它的功能更多。

 [user@hostname ~]$ virt-sysprep --list-operations
 abrt-data * Remove the crash data generated by ABRT
 bash-history * Remove the bash history in the guest
 blkid-tab * Remove blkid tab in the guest
 ca-certificates   Remove CA certificates in the guest
 crash-data * Remove the crash data generated by kexec-tools
 cron-spool * Remove user at-jobs and cron-jobs
 delete * Delete specified files or directories
 dhcp-client-state * Remove DHCP client leases
 dhcp-server-state * Remove DHCP server leases
 dovecot-data * Remove Dovecot (mail server) data
 firewall-rules   Remove the firewall rules
 firstboot * Add scripts to run once at next boot
 flag-reconfiguration   Flag the system for reconfiguration
 hostname * Change the hostname of the guest
 kerberos-data   Remove Kerberos data in the guest
 logfiles * Remove many log files from the guest
 lvm-uuids * Change LVM2 PV and VG UUIDs
 machine-id * Remove the local machine ID
 mail-spool * Remove email from the local mail spool directory
 net-hostname * Remove HOSTNAME in network interface configuration
 net-hwaddr * Remove HWADDR (hard-coded MAC address) configuration
 pacct-log * Remove the process accounting log files
 package-manager-cache * Remove package manager cache
 pam-data * Remove the PAM data in the guest
 password * Set root or user password
 puppet-data-log * Remove the data and log files of puppet
 random-seed * Generate random seed for guest
 rhn-systemid * Remove the RHN system ID
 rpm-db * Remove host-specific RPM database files
 samba-db-log * Remove the database and log files of Samba
 script * Run arbitrary scripts against the guest
 smolt-uuid * Remove the Smolt hardware UUID
 ssh-hostkeys * Remove the SSH host keys in the guest
 ssh-userdir * Remove ".ssh" directories in the guest
 sssd-db-log * Remove the database and log files of sssd
 tmp-files * Remove temporary files
 udev-persistent-net * Remove udev persistent net rules
 user-account   Remove the user accounts in the guest
 utmp * Remove the utmp file
 yum-uuid * Remove the yum UUID
Run Code Online (Sandbox Code Playgroud)

Mic*_*ton 5

我们认为的初始设置实际上分为三个部分。前两个是:

  • 初始设置,要求您接受许可并创建用户
  • Firstboot,它会要求您配置 kdump 并(在 RHEL 上)设置您的订阅

这两个现在都通过 systemd 启用;一旦完成,他们就会禁用自己。

因此,您所要做的就是删除在第一个初始设置过程中创建的所有本地用户并重新启用这些服务:

systemctl enable initial-setup-graphical.service
systemctl enable firstboot-graphical.service
> /etc/sysconfig/firstboot
Run Code Online (Sandbox Code Playgroud)

并重新启动。

我不完全确定第三部分,它要求您输入语言并创建用户帐户或将机器加入域。这至少会继续回来,直到您真正完成向导。(所以不要那样做。)

清理主机密钥和任何特定于硬件的配置仍然是一个好主意。(udev 规则和接口配置文件中的 Mac 地址。)