在 RHEL 上为 SAP 解决方案定制操作系统镜像构建流程 IBM® Power® Virtual Server
以下信息介绍了如何在 Red Hat Enterprise Linux (RHEL) 上为 IBM® Power® Virtual Server 上的 SAP 软件构建自定义操作系统 (OS) 映像。
自定义操作系统镜像构建要求
在启动映像构建过程之前,请完成以下要求:
-
创建 IBM Cloud 账户 并获取必要的凭证,以便在 Power Virtual Server 上部署映像构建服务器。 有关身份和访问管理 (IAM) 的详细信息,请参阅 管理 IBM® Power® Virtual Server 的身份和访问管理(IAM)。
-
确保您可以访问 IBM Cloud Object Storage,以便上传基础图片。 有关如何开始的信息,请 参阅 IBM Cloud Object Storage 入门。
-
下载 Red Hat Enterprise Linux 9 KVM 客户机映像
rhel-9.4-ppc64le-kvm.qcow2
来自 Red Hat Enterprise Linux for Power little endian。以下是基于 RHEL 9.4 OS 映像构建自定义 OS 映像的指南。
-
创建镜像构建服务器,配置镜像构建环境并构建操作系统镜像。 它包括一个运行 RHEL 9.2 ( RHEL9-SP2-SAP-NETWEAVER ) 或更高版本 RHEL 的 Power Virtual Server 实例,以及 200 GByte 的额外存储容量。 有两种方法可以设置图像构建服务器:
-
对于手动方法,请参阅 开始使用 Power Virtual Server 和 创建 IBM Power 虚拟服务器中 的详细信息。
-
有关自动方法,请参阅 Power Virtual Server with VPC Landing Zonedeployment 指南。
-
设置构建镜像环境
以下步骤介绍了如何为创建映像设置构建服务器环境。
-
登录构建服务器,执行以下命令检查其注册状态。
subscription-manager status
-
更新 RHEL 操作系统软件包。
-
检查并调整构建环境的代理设置。 使用代理 IP 地址或 URL 配置临时 HTTPS 代理设置。 如果您使用 IBM Cloud 目录中的 VPC landing zone 部署了自动 Power Virtual Server,请使用此代理地址
http://10.30.40.7:3128/
进行配置。export https_proxy="http://10.30.40.7:3128/" || die "Set HTTPS proxy failed (rc $?)"
-
创建"/data "目录,并导出指向该目录的环境变量。
mkdir -p /data
export MOUNT_PATH=/data
-
附加一个容量为 200 GB 的存储卷,并创建
/data
文件系统。-
运行 multipath 命令识别可用存储卷及其万维网名 (WWN)。 确保命令输出只显示一个 200 GB 的存储卷。 否则,创建文件系统将无法正常工作。
multipath -ll
-
为物理卷和逻辑卷、卷组和挂载目录导出以下变量。
export PV_SIZE=200G
export LV_NAME=image_lv
export VG_NAME=image_vg
-
创建物理卷和逻辑卷。
devices=$(multipath -ll | grep -B 1 $PV_SIZE | grep dm- | awk '{print "/dev/"$2}' | tr '\n' ' ')
stripes=$(multipath -ll | grep -B 1 $PV_SIZE | grep dm- | awk '{print "/dev/"$2}' | wc | awk '{print $1}')
pvcreate $devices
vgcreate ${VG_NAME} ${devices}
lvcreate -i${stripes} -I64 -l100%VG -n ${LV_NAME} ${VG_NAME}
mkfs.xfs /dev/mapper/${VG_NAME}-${LV_NAME}
-
检查创建的逻辑卷是否处于活动状态。
lvscan
-
安装文件系统。
mount -t xfs -o defaults,nofail --source /dev/mapper/${VG_NAME}-${LV_NAME} --target ${MOUNT_PATH}
-
将文件系统添加到
/etc/fstab
文件。echo "/dev/mapper/${VG_NAME}-${LV_NAME} ${MOUNT_PATH} xfs defaults,nofail 0 0" >> /etc/fstab
-
确保文件系统出现在所有已加载文件系统的列表中。
df -h
-
-
创建保存基础图像的目录
/data/image
。 -
将图像
rhel-9.4-ppc64le-kvm.qcow2
复制到/data/image
。 -
创建
/data/tmp
目录,在构建过程中将临时图像保存在该目录中。 -
完成以下任务以配置构建服务器。 使用
dnf
RHEL 软件包管理器。-
安装
xfsprogs
和lvm2
系统软件包。 -
安装
make
、git
、libgcrypt-devel
和go-toolset
开发包。 -
安装
qemu-img
和cloud-utils-growpart
软件包。 -
在文件
~root/.bashrc
中添加代理主机,配置代理。export https_proxy='<your_https_proxy>'
-
-
在文件
/etc/modules-load.d/ndb.conf
中添加以下几行,配置 NBD 模块在启动时加载。nbd options nbd max_part=8
-
从 最新发布的
pvsadm-linux-ppc64le
GitHub 资源库中下载pvsadm
工具。 保存到名为/usr/local/bin/pvsadm
的文件中,并将模式更改为0755
。 有关该工具的详细信息,请参阅pvsadm
工具。
构建自定义操作系统映像
IBM Cloud PowerVS 定制操作系统镜像的构建过程包括以下任务。
-
检查 Red Hat Satellite 订阅凭证是否有效。
-
创建一个名为
image-prep.template
的空文件,并将其用作图像准备模板。 -
以下任务包含构建自定义映像所需的 shell 命令。 将这些命令添加到模板
image-prep.template
。 在使用pvsadm
工具创建镜像时,这些命令会更新基本操作系统镜像,以创建最终的 SAP 就绪操作系统镜像。 指挥命令非常重要,不应更改。-
复制以下几行,包括错误处理,作为模板页眉。
#!/usr/bin/env bash set -o errexit set -o nounset set -o pipefail die() { echo -e "\n${1}" set +o errexit set +o nounset exit 1 }
-
添加临时名称服务器。
echo "nameserver 9.9.9.9" >> /etc/resolv.conf \ || die "Add nameserver failed (rc $?)"
-
创建工作目录
/tmp/work
并作为环境变量导出。mkdir -p /tmp/work || die "Create work directory failed (rc $?)"
export WORK_DIR=/tmp/work
-
创建 25GB swap 文件,添加权限并检查创建是否正确。
fallocate -l 25G /swapfile || die "allocate swapfile failed (rc $?)"
chmod 600 /swapfile || die "chmod swapfile failed (rc $?)"
mkswap /swapfile || die "mkswap swapfile failed (rc $?)"
swapon /swapfile || die "swapon swapfile failed (rc $?)"
swapon --show
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab || die "update fstab with swapfile failed (rc $?)"
echo "swapon -s"
-
订阅 Red Hat Satellite 并启用 SAP 资源库。 订阅用户名、密码和发布版本请自行取值。
subscription-manager register \ --force --auto-attach \ --username=<SUBSCRIPTION_USER> \ --password=<SUBSCRIPTION_PASSWORD> \ --release=<OS_VERSION> \ || die "Register subscription failed (rc $?)"
subscription-manager repos \ --disable="*" \ --enable="rhel-9-for-$(uname -m)-baseos-e4s-rpms" \ --enable="rhel-9-for-$(uname -m)-appstream-e4s-rpms" \ --enable="rhel-9-for-$(uname -m)-sap-solutions-e4s-rpms" \ --enable="rhel-9-for-$(uname -m)-sap-netweaver-e4s-rpms" \ --enable="rhel-9-for-$(uname -m)-highavailability-e4s-rpms"\ --enable="codeready-builder-for-rhel-9-$(uname -m)-rpms" \ || die "Repository configuration failed (rc $?)"
-
安装软件包组服务器
dnf -y group install server \ || die "Installing server group packages failed (rc $?)"
-
安装系统软件包。
dnf -y install \ cloud-init \ device-mapper-multipath \ libxcrypt-compat \ glibc-langpack-en \ || die "Install system packages failed (rc $?)"
-
更新
grub2
.dnf -y reinstall grub2-common \ || die "Reinstall system package failed (rc $?)"
dnf -y update grub2 \ || die "Update grub2 package failed (rc $?)"
-
为 SAP 安装 Ansible 和 Red Hat 系统角色。
dnf -y install ansible-core rhel-system-roles rhel-system-roles-sap \ || die "Install Ansible and RH System Roles failed (rc $?)"
-
启用 EPEL 资源库。
dnf -y install "https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm" \ || die "Installation EPEL configuration failed (rc $?)"
-
配置 IBM Power 工具库。
dnf -y install "https://public.dhe.ibm.com/software/server/POWER/Linux/yum/download/ibm-power-repo-latest.noarch.rpm" \ || die "Installation IBM Power Tools configuration failed (rc $?)"
echo 'y' | (/opt/ibm/lop/configure \ || die "Power Tools configuration failed (rc $?)")
-
安装 IBM Power 工具并禁用存储库。
dnf config-manager --set-disabled Advance_Toolchain \ || die "Disable Advance Toolchain repository failed (rc $?)"
dnf -y install ibm-power-managed-rhel9 \ || die "Install IBM Power Tools failed (rc $?)"
dnf config-manager --set-disabled IBM_Power_Tools \ || die "Disable IBM Power Tools repository failed (rc $?)"
-
更新操作系统。
dnf -y update || die "OS update failed (rc $?)"
-
删除 EPEL 资源库。
dnf -y remove epel-release \ || die "Uninstall EPEL configuration failed (rc $?)"
-
从 Red Hat Satellite 服务器取消注册。
subscription-manager unregister \ || die "Unregister subscription failed (rc $?)"
subscription-manager clean \ || die "Clean subscription failed (rc $?)"
-
更改加密策略(禁用 SHA1/CBC )。
echo -e "cipher@ssh = -*-CBC\n" \ > /etc/crypto-policies/policies/modules/NO-CBC.pmod \ || die "Create of CBC disabling file failed (rc $?)"
update-crypto-policies --set DEFAULT:NO-SHA1:NO-CBC \ || die "Update of cryptografic policy failed (rc $?)"
-
创建基本的多路径配置。
echo -e "defaults {\n \ user_friendly_names no\n \ find_multipaths smart\n}\n" \ > /etc/multipath.conf \ || die "Create multipath configuration failed (rc $?)"
-
定义 Ansible 清单。
echo -e "localhost ansible_connection=local\n" > /root/inventory \ || die "Create Ansible inventory file failed (rc $?)"
-
为 SAP HANA 和 NetWeaver 创建 Ansible yml 文件。
cat <<EOF > /root/sap-hana.yml \ || die "Create SAP HANA Ansible file failed (rc $?)" - hosts: localhost vars: sap_hana_preconfigure_min_rhel_release_check: false sap_hana_preconfigure_install_ibm_power_tools: false sap_hana_preconfigure_add_ibm_power_repo: false connection: local roles: - redhat.sap_install.sap_general_preconfigure - redhat.sap_install.sap_hana_preconfigure EOF
cat <<EOF > /root/sap-netweaver.yml \ || die "Create SAP NetWeaver Ansible file failed (rc $?)" - hosts: localhost connection: local roles: - redhat.sap_install.sap_general_preconfigure - redhat.sap_install.sap_netweaver_preconfigure EOF
cat <<EOF > /root/sap-preconfigure.yml \ || die "Create SAP preconfiguration Ansible file failed (rc $?)" - hosts: localhost connection: local roles: - redhat.sap_install.sap_general_preconfigure EOF
-
更改
/etc/sysctl.conf
文件中的默认内核参数。cat <<EOF >> /etc/sysctl.conf \ || die "Change of kernel parameter failed (rc $?)" net.core.rmem_max = 56623104 net.core.wmem_max = 56623104 net.ipv4.tcp_rmem = 65536 262088 56623104 net.ipv4.tcp_wmem = 65536 262088 56623104 net.ipv4.tcp_mem = 56623104 56623104 56623104 EOF
-
在 ibmveth 设备上启用接收流转向 (RFS),调整文件
/etc/udev/rules.d/70-ibmveth-rfs.rules
。cat <<EOF >> /etc/udev/rules.d/70-ibmveth-rfs.rules \ || die "Create udev rule for RFS failed (rc $?)" # Enable Receive Flow Steering (RFS) on ibmveth devices SUBSYSTEM=="net",ACTION=="add",DRIVERS=="ibmveth",RUN{program}+="/bin/bash -c 'echo 32768 > /sys/\$DEVPATH/queues/rx-0/rps_flow_cnt';" EOF
在文件
/etc/sysctl.d/95-enable-rfs.conf
中启用接收流转向(RFS)。cat <<EOF >> /etc/sysctl.d/95-enable-rfs.conf \ || die "Create kernel parameter file for RFS failed (rc $?)" # Enable Receive Flow Steering (RFS) net.core.rps_sock_flow_entries=32768 EOF
-
配置 SSH 守护进程。
sed -i \ -e 's/^\(#\)\?PermitRootLogin .*/PermitRootLogin yes/g' \ -e 's/^\(#\)\?PasswordAuthentication .*/PasswordAuthentication no/g' \ -e 's/^\(#\)\?MaxStartups .*/MaxStartups 10:30:60/g' \ /etc/ssh/sshd_config \ || die "Failed SSH daemon configuration (rc $?)"
-
调整 GRUB。
-
检查 PReP 分区是否存在并进行更新。
prep_partition=$(fdisk -l | grep -i ppc | grep -i loop | awk '{print $1}') # Check if a PReP partition was found if [ -z "$prep_partition" ]; then echo "No PReP partition found with /dev/loop." exit 1 else echo "PReP partition found: $prep_partition" fi
-
在 PReP 分区上安装
grub2
。grub2-install "$prep_partition" \ || die "Install GRUB update failed (rc $?)"
-
执行引导列表命令。
bootlist -m normal -o || die "Setting boot list failed (rc $?)"
-
更改 GRUB 默认超时选项。
sed -i \ -e 's/GRUB_TIMEOUT=.*/GRUB_TIMEOUT=20/' \ /etc/default/grub || die "Fail to change default GRUB options (rc $?)"
-
更新 GRUB 配置。
grubby --update-kernel=ALL \ --remove-args="net.ifnames=0" \ --args="console=tty0 console=hvc0,115200n8 crashkernel=2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G rd.shell rd.debug rd.driver.pre=dm_multipath log_buf_len=1M elevator=none" \ || die "GRUB cmdline configuration update failed (rc $?)"
-
为所有内核启用多路径。
echo -e 'force_drivers+=" dm-multipath "\n' >/etc/dracut.conf.d/10-mp.conf\ || die "Create of multipath include file for dracut failed (rc $?)"
dracut --regenerate-all --force \ || die "Regenerate of initramfs images failed (rc $?)" for kernel in $(rpm -q kernel | sort -V | sed 's/kernel-//'); do dracut --kver ${kernel} --force --add multipath --include /etc/multipath\ /etc/multipath --include /etc/multipath.conf /etc/multipath.conf \ || die "Generate initramfs of ${kernel} failed (rc $?)" done
-
生成 GRUB 配置。
grub2-mkconfig -o /boot/grub2/grub.cfg \ || die "Generate GRUB configuration failed (rc $?)"
-
-
删除临时名称服务器。
sed -i '/nameserver 9.9.9.9/d' /etc/resolv.conf \ || die "Remove nameserver failed (rc $?)"
-
在下次启动时启用 SELinux 重新标记。
touch /.autorelabel || die "Create relabel file failed (rc $?)"
-
删除根用户密码。
usermod -p '!' root || die "Delete root password failed (rc $?)"
-
清理文件系统
rm -rf /etc/sysconfig/network-scripts/ifcfg-eth*
rm -rf /tmp/work
rm -rf /root/.ssh
rm -rf /etc/pki/entitlement/
rm -rf /setup.sh
-
删除命令历史记录。
history -c
-
-
在运行
pvsadm
工具之前,请确保已禁用构建服务器上的本地交换。 否则,在执行pvsadm
时会出现错误mkswap: error: /swapfile is mounted; will not make swapspace
。 要禁用交换功能,请运行以下命令。swapoff -a
-
使用
pvsadm
映像构建工具和qcow2ova
命令,将 qcow2 映像转换为 OVA 格式。 根据输入格式为命令标志设置自定义值。 请参阅下面的标志说明。--image-name <string> Name of the resultant OVA image --image-url <string> URL or absolute local file path to the qcow2 image --image-dist <string> Image Distribution(supported: rhel, centos, coreos) --target-disk-size <int> Size (in GB) of the target disk volume where OVA will be copied (default 120) --rhn-user <string> RedHat Subscription username. Required when Image distribution is rhel --rhn-password <string> RedHat Subscription password. Required when Image distribution is rhel --os-password <string> Root user password, will auto-generate the 12 bits password(applicable only for redhat and cento distro) --temp-dir <string> Scratch space to use for OVA generation --prep-template <string> Image preparation script template
例如,使用
rhel-9.4-ppc64le-image
作为新的操作系统镜像名称,rhel-9.4-ppc64le-kvm.qcow2
是位于/data/image
的基本操作系统镜像,因此 qcow2 镜像的绝对本地路径是/data/image/rhel-9.4-ppc64le-kvm.qcow2
,镜像分发是rhel
。 根据需要调整映像和目标磁盘的大小,目标磁盘卷的默认值为 120 GB。 图像准备脚本模板为image-prep.template
,脚本名称也可自定义。 为了简化pvsadm
映像构建工具的运行,还可以设置环境变量。export IMAGE_NAME=rhel-9.4-ppc64le-image export QCOW2_IMAGE_PATH=/data/image/rhel-9.4-ppc64le-kvm.qcow2 export IMAGE_SIZE=100 export TARGET_DISK_SIZE=100 export SUBSCRIPTION_USER=<RedHat subscription username> export SUBSCRIPTION_PASSWORD=<RedHat Subscription password> export IMAGE_BUILD_DIRECTORY=/data/tmp export IMAGE_PREP_SCRIPT=image-prep.template
pvsadm image qcow2ova --image-name ${IMAGE_NAME} \ --image-url ${QCOW2_IMAGE_PATH} \ --image-dist rhel \ --image-size ${IMAGE_SIZE} --target-disk-size ${TARGET_DISK_SIZE} \ --rhn-user ${SUBSCRIPTION_USER} \ --rhn-password ${SUBSCRIPTION_PASSWORD} \ --temp-dir ${IMAGE_BUILD_DIRECTORY} \ --prep-template ${IMAGE_PREP_SCRIPT}
pvsadm
工具有一个帮助菜单,详细介绍了使用方法、命令和标志。 运行以下命令访问帮助菜单。pvsadm --help
-
将自定义创建的操作系统镜像上传到 Cloud Object Storage (COS)。
在 Power Virtual Server 工作区导入操作系统映像
要导入自定义引导映像,请参阅 导入引导映像 指南。
从新导入的操作系统镜像创建 Power Virtual Server 实例
要配置新的 Power Virtual Server 实例,请按照 使用自定义启动映像配置新实例 中所述的步骤进行。