IBM Cloud Docs
指定定制网络时间协议 (NTP) 服务器

指定定制网络时间协议 (NTP) 服务器

保持时间是任何系统的一个组成部分。 您可以选择允许访问 Red Hat 网络时间协议(NTP)服务器,也可以配置对定制网络时间协议 (NTP) 服务器的访问。

只能为 Red Hat CoreOS 主机指定定制 NTP 服务器。

为未连接的主机指定定制 NTP 服务器

要将主机配置为在将其连接到位置之前使用定制 NTP 服务器,请编辑主机脚本以包含定制 NTP 服务器信息。 此示例使用 chrony NTP 服务器。

  1. 创建类似于以下示例的 chrony.conf 文件。

    pool time.adn.networklayer.com iburst
    
    server time.adn.networklayer.com iburst minpoll 3 maxpoll 4
    
    # Record the rate at which the system clock gains/losses time.
    driftfile /var/lib/chrony/drift
    
    # Allow the system clock to be stepped in the first three updates
    # if its offset is larger than 1 second.
    makestep 1.0 3
    
    # Enable kernel synchronization of the real-time clock (RTC).
    rtcsync
    
    # Specify file containing keys for NTP authentication.
    keyfile /etc/chrony.keys
    
    # Get TAI-UTC offset and leap seconds from the system tz database.
    leapsectz right/UTC
    
    # Specify directory for log files.
    logdir /var/log/chrony
    
  2. 将内容转换为 base64。

    cat chrony.conf | base64
    
  3. 下载您所在位置的附加脚本。 对于 RHCOS 主机,连接脚本是一个点火 (.ign) 脚本。

    ibmcloud sat host attach --location LOCATION --operating-system RHCOS
    
  4. 编辑脚本并向 storage.files 数组添加条目,其中 BASE64_ENCODED_CHRONY_FILE_DATA 是步骤 2 中的基本 64 位字符串。

    {
      "overwrite": true,
      "path": "/etc/chrony.conf",
      "contents": {
        "source":"data:text/plain;base64,BASE64_ENCODED_CHRONY_FILE_DATA"
        },
        "mode": 420
     }
    
  5. 保存脚本。

  6. 验证脚本。

    cat IGNITION_FILE_PATH | jq -r
    

验证脚本后,可以将主机 连接 到您的位置。

为连接的主机指定定制 NTP

您可以在主机连接到位置后为其配置定制 NTP 服务器。

  1. 创建类似于以下示例的 chrony.conf 文件。

    pool time.adn.networklayer.com iburst
    
    server time.adn.networklayer.com iburst minpoll 3 maxpoll 4
    
    # Record the rate at which the system clock gains/losses time.
    driftfile /var/lib/chrony/drift
    
    # Allow the system clock to be stepped in the first three updates
    # if its offset is larger than 1 second.
    makestep 1.0 3
    
    # Enable kernel synchronization of the real-time clock (RTC).
    rtcsync
    
    # Specify file containing keys for NTP authentication.
    keyfile /etc/chrony.keys
    
    # Get TAI-UTC offset and leap seconds from the system tz database.
    leapsectz right/UTC
    
    # Specify directory for log files.
    logdir /var/log/chrony
    
  2. 登录到主机系统。

  3. 更新该主机的 chrony.conf 文件,其中 CHRONY_FILE_DATA 是您在步骤 1 中创建的文件的名称。 请勿将此文件转换为 base64。

    cat >"/etc/chrony.conf" <<EOF
    CHRONY_FILE_DATA
    EOF
    systemctl restart chronyd
    

更新 chrony.conf 文件后,主机将使用定制 NTP 服务器。