第 8 章 使用 RHEL for Edge Simplified Installer 镜像的 Ignition 工具


RHEL for Edge 使用 Ignition 工具在引导过程的早期将用户配置注入到镜像中。Ignition 工具注入的用户配置包括:

  • 用户配置。
  • 写文件,如常规文件和 systemd 单元。

第一次引导时,Ignition 从远程 URL 或嵌入在简化的安装程序 ISO 中的文件读取其配置。然后,Ignition 将该配置应用到镜像中。

8.1. 创建一个 Ignition 配置文件

Butane 工具是创建 Ignition 配置文件的首选选项。Butane 使用一个 Butane Config YAML 文件,并以 JSON 格式生成一个 Ignition Config。在第一次启动时系统使用 JSON 文件。Ignition Config 应用镜像中的配置,如创建用户和 systemd 单元安装。

先决条件

  • 您已安装了 Butane 工具版本 v0.17.0 :

    $ sudo dnf/yum install -y butane

流程

  1. 创建一个 Butane Config 文件,并将它保存为 .bu 格式。对于 RHEL for Edge 镜像,您必须将 variant 条目指定为 r4e,将 version 条目指定为 1.0.0。版本 1.0.0 上的 butane r4e 变体以 Ignition spec 版本 3.3.0 为目标。以下是 Butane Config YAML 文件的一个示例:

    variant: r4e
    version: 1.0.0
    ignition:
      config:
        merge:
          - source: http://192.168.122.1:8000/sample.ign
    passwd:
      users:
        - name: core
          groups:
            - wheel
          password_hash: password_hash_here
          ssh_authorized_keys:
            - ssh-ed25519 some-ssh-key-here
    storage:
      files:
        - path: /etc/NetworkManager/system-connections/enp1s0.nmconnection
          contents:
            inline: |
              [connection]
              id=enp1s0
              type=ethernet
              interface-name=enp1s0
              [ipv4]
              address1=192.168.122.42/24,192.168.122.1
              dns=8.8.8.8;
              dns-search=
              may-fail=false
              method=manual
          mode: 0600
        - path: /usr/local/bin/startup.sh
          contents:
            inline: |
              #!/bin/bash
              echo "Hello, World!"
          mode: 0755
    systemd:
      units:
        - name: hello.service
          contents: |
            [Unit]
            Description=A hello world
            [Install]
            WantedBy=multi-user.target
          enabled: true
        - name: fdo-client-linuxapp.service
          dropins:
            - name: log_trace.conf
              contents: |
                [Service]
                Environment=LOG_LEVEL=trace
  2. 运行以下命令以使用 Butane Config YAML 文件,并生成一个 JSON 格式的 Ignition 配置:

    $ ./path/butane example.bu
    {"ignition":{"config":{"merge":[{"source":"http://192.168.122.1:8000/sample.ign"}]},"timeouts":{"httpTotal":30},"version":"3.3.0"},"passwd":{"users":[{"groups":["wheel"],"name":"core","passwordHash":"password_hash_here","sshAuthorizedKeys":["ssh-ed25519 some-ssh-key-here"]}]},"storage":{"files":[{"path":"/etc/NetworkManager/system-connections/enp1s0.nmconnection","contents":{"compression":"gzip","source":"data:;base64,H4sIAAAAAAAC/0yKUcrCMBAG3/csf/ObUKQie5LShyX5SgPNNiSr0NuLgiDzNMPM8VBFtHzoQjkxtPp+ITsrGLahKYyyGtoqEYNKwfeZc32OC0lKDb179rfg/HVyPgQ3hv8w/v0WT0k7T+7D/S1Dh7S4MRU5h1XyzqvsHVRg25G4iD5kp1cAAAD//6Cvq2ihAAAA"},"mode":384},{"path":"/usr/local/bin/startup.sh","contents":{"source":"data:;base64,IyEvYmluL2Jhc2gKZWNobyAiSGVsbG8sIFdvcmxkISIK"},"mode":493}]},"systemd":{"units":[{"contents":"[Unit]\nDescription=A hello world\n[Install]\nWantedBy=multi-user.target","enabled":true,"name":"hello.service"},{"dropins":[{"contents":"[Service]\nEnvironment=LOG_LEVEL=trace\n","name":"log_trace.conf"}],"name":"fdo-client-linuxapp.service"}]}}

    运行 Butane Config YAML 文件以检查并生成 Ignition Config JSON 文件后,在使用不支持的字段时(如分区)时可能会收到警告。您可以修复这些字段并重新运行检查。

现在,您已有一个 Ignition JSON 配置文件,可用于自定义蓝图。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.