文档

配置SUSE linux实例的NTP/Chrony时钟同步服务

更新时间:
一键部署

问题描述

您希望了解如何修改Linux系统的ECS实例的时区,以及如何开启、配置及使用NTP/Chrony服务,保证实例的时间精确同步。

适用于

  • SUSE Linux Enterprise for SAP 12
  • SUSE Linux Enterprise for SAP 15

说明和使用限制

  • NTP服务的通信端口为UDP 123,您需要在实例安全组的入方向添加安全组规则并放行UDP 123端口。具体操作请参见添加安全组规则
  • 目前,所有地域下ECS实例默认采用CST(China Standard Time)时区,您也可以根据自己的业务需求为ECS实例设置或者修改时区。
  • SLES 12 SP5及以上和SLES 15及以上默认使用Chrony实现本地时间和标准时间同步。与以前版本中的NTP服务不同,Chrony可以更快更准确地同步系统时钟,最大程度的减少时间和频率误差。更多请参见 Time Synchronization with NTP。
  • 修改系统时区或时钟同步配置之前,请关停所有SAP应用/数据库服务。

操作步骤

以下以SLES for SAP 15 SP1操作系统为例描述操作步骤:

修改系统时区

  1. 使用如下命令查询当前配置的时区。
    # timedatectl status
          Local time: Fri 2021-07-30 11:58:02 HKT
      Universal time: Fri 2021-07-30 03:58:02 UTC
            RTC time: Fri 2021-07-30 11:58:02
           Time zone: Asia/Hong_Kong (HKT, +0800)
     Network time on: no
    NTP synchronized: yes
     RTC in local TZ: yes
  2. 执行以下命令列出系统支持的时区列表。
    # timedatectl list-timezones
  3. 执行以下命令修改系统时区。
    # timedatectl set-timezone Asia/Shanghai
    示例将系统时区修改成了Asia/Shanghai,请根据您实际的需求来设置。
  4. 执行以下命令更新硬件时钟。
    # hwclock -w
  5. 查询当前时区配置
    # timedatectl status
          Local time: Fri 2021-07-30 11:40:09 CST
      Universal time: Fri 2021-07-30 03:40:09 UTC
            RTC time: Fri 2021-07-30 11:40:09
           Time zone: Asia/Shanghai (CST, +0800)
     Network time on: no
    NTP synchronized: yes
     RTC in local TZ: yes

配置Chrony服务

  1. 使用vim /etc/chrony.conf命令,编辑chrony配置文件。示例如下:
    # Use Alibaba NTP server
    # Public NTP
    # Alicloud NTP
    server ntp1.aliyun.com minpoll 4 maxpoll 10 iburst
    server ntp1.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp10.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp11.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp12.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp2.aliyun.com minpoll 4 maxpoll 10 iburst
    server ntp2.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp3.aliyun.com minpoll 4 maxpoll 10 iburst
    server ntp3.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp4.aliyun.com minpoll 4 maxpoll 10 iburst
    server ntp4.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp5.aliyun.com minpoll 4 maxpoll 10 iburst
    server ntp5.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp6.aliyun.com minpoll 4 maxpoll 10 iburst
    server ntp6.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp7.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp8.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp9.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    # Ignore stratum in source selection.
    stratumweight 0.05
    # Record the rate at which the system clock gains/losses time.
    driftfile /var/lib/chrony/drift
    # Enable kernel RTC synchronization.
    rtcsync
    # In first three updates step the system clock instead of slew
    # if the adjustment is larger than 10 seconds.
    makestep 10 3
    # Allow NTP client access from local network.
    #allow 192.168/16
    # Listen for commands only on localhost.
    bindcmdaddress 127.0.0.1
    bindcmdaddress ::1
    # Serve time even if not synchronized to any NTP server.
    #local stratum 10
    # Disable logging of client accesses.
    noclientlog
    # Send a message to syslog if a clock adjustment is larger than 0.5 seconds.
    logchange 0.5
    logdir /var/log/chrony
    #log measurements statistics tracking
  2. 运行以下命令启动服务并设置开机自启动
    systemctl start chronyd
    systemctl enable chronyd
  3.  运行以下命令,查看本机时间同步状态,验证服务是否已启动。
    chronyc tracking
  4. 如果您需要手工同步时钟,需要使用chronyc工具,并运行makestep命令:
    # chronyc
    chrony version 2.3
    Copyright (C) 1997-2003, 2007, 2009-2016 Richard P. Curnow and others
    chrony comes with ABSOLUTELY NO WARRANTY.  This is free software, and
    you are welcome to redistribute it under certain conditions.  See the
    GNU General Public License version 2 for details.
    chronyc> makestep
    200 OK

参考文档:

  • 本页导读
文档反馈