8.2. 设置 web 服务器以安装 RHEL for Edge 镜像

提取了 RHEL for Edge 镜像内容后,建立一个 web 服务器,以使用 HTTP 向 RHEL 安装程序提供镜像提交详情。

下面的示例提供了使用容器建立 Web 服务器的步骤。

先决条件

流程

  1. 使用以下步骤创建 nginx 配置文件:

    events {
    
    }
    
    http {
        server{
            listen 8080;
            root /usr/share/nginx/html;
                    }
             }
    
    pid /run/nginx.pid;
    daemon off;
  2. 使用以下说明创建 Dockerfile:

    FROM registry.access.redhat.com/ubi8/ubi
    RUN yum -y install nginx && yum clean all
    COPY kickstart.ks /usr/share/nginx/html/
    COPY repo /usr/share/nginx/html/
    COPY nginx /etc/nginx.conf
    EXPOSE 8080
    CMD ["/usr/sbin/nginx", "-c", "/etc/nginx.conf"]
    ARG commit
    ADD ${commit} /usr/share/nginx/html/

    其中,

    • Kickstart.ks 是 RHEL for Edge 镜像的 Kickstart 文件的名称。Kickstart 文件包含指令信息。为了帮助您稍后管理镜像,建议包含用于 greenboot 检查的检查和设置。因此,您可以更新 Kickstart 文件以使其包含以下设置:

      lang en_US.UTF-8
      keyboard us
      timezone Etc/UTC --isUtc
      text
      zerombr
      clearpart --all --initlabel
      autopart
      reboot
      user --name=core --group=wheel
      sshkey --username=core "ssh-rsa AAAA3Nza…​."
      
      ostreesetup --nogpg --osname=rhel --remote=edge
      --url=https://mirror.example.com/repo/
      --ref=rhel/8/x86_64/edge
      
      %post
      cat << EOF > /etc/greenboot/check/required.d/check-dns.sh
      #!/bin/bash
      
      DNS_SERVER=$(grep nameserver /etc/resolv.conf | cut -f2 -d" ")
      COUNT=0
      
      # check DNS server is available
      ping -c1 $DNS_SERVER
      while [ $? != '0' ] && [ $COUNT -lt 10 ]; do
      
      							
      							
      							
      							
      							
      							COUNT++
      echo "Checking for DNS: Attempt $COUNT ."
      sleep 10
      ping -c 1 $DNS_SERVER
      done
      EOF
      %end

      任何 HTTP 服务都可以托管 OSTree 存储库,使用容器的示例只是如何执行此操作的一个选项。Dockerfile 执行以下任务:

      1. 使用最新的通用基础镜像(UBI)
      2. 安装 Web 服务器(nginx)
      3. 向服务器添加 Kickstart 文件
      4. 将 RHEL for Edge 镜像提交添加到服务器
  3. 构建 Docker 容器

    # podman build -t name-of-container-image --build-arg commit=uuid-commit.tar .
  4. 运行容器

    # podman run --rm -d -p port:8080 localhost/name-of-container-image

    因此,服务器建立起来了,并准备使用 commit.tar 存储库和 Kickstart 文件来启动 RHEL 安装程序。