全国业务电话:
8.1 NTP
  CGSL 系统为标准服务器版本,为满足大多数用户的需求,系统提供了大量的通用服务和基本功能,本章主要介绍常用服务和系统基本功能的配置和使用。
 
8.1 NTP
 
  NTP(Network Time Protocol)是用来使系统和一个精确的时间源保持时间同步的协议。通常用于局域网上的若干台主机通过互联网与其他的 NTP主机同步时钟,接着再向局域网内其他客户端提供时间同步服务。
 
  CGSLV5 默认 ntp 组件由 Chrony 代替。
 
  Chrony 是网络事件协议的(ntp)的另一种实现,与网络事件协议后台程序(ntpd)不同,它可以更快地且更准确地同步系统时钟。请注意,ntpd 仍包含其中以提供需要运行 NTP 服务的客户使用(需要重新从安装光盘安装)。
 
  注意:Chrony 不能使用本地时间作为时钟源(原 ntpd 可以使用本地时间作为时钟源)。
 
  Chrony 的优势包括:
 
  ●更快的同步只需要数分钟并非数小时时间,从而最大程度减少了时间和频率的误差,这对于并非全天 24 小时运行的台式计算机或系统而言非常有用。
 
  ●能够更快地响应时钟频率的快速变化,这对于具备不稳定始终的虚拟机或导致始终频率发生变化的节能技术而言非常有用。
 
  ●在初始同步后,它不会停止时钟,以防对需要系统时间保持单调的应用程序造成影响。
 
  ●在应对临时非对称延迟时(例如,在大规模下载造成链接饱和时)提供了更好的稳定性。
 
  ●无需对服务器进行定期轮询,因此具备间歇性网络连接的系统仍然可以快速同步时钟。

8.1.1 Chrony 配置文件
 
  Chrony 服务主要通过/etc/chrony.conf 配置。本节主要介绍该配置文件中的主要影响配置。
 
8.1.1.1 上级时间服务器
 
  首先用 server 这个参数设定上级时间服务器,语法为:
 
    server IP 地址或域名 [prefer]  
 
8.1.1.2 权限设置
 
  权限的设定,主要的语法为:
 
    allow IP 地址 mask 子网掩码  
 
8.1.1.3 driftfile 参数
 
  在与上级时间服务器联系时所花费的时间,记录在 driftfile 参数后面的文件内。语法为:
 
    driftfile 包含路径的文件名  
 
  注意: driftfile 后面接的文件需要使用完整的路径文件名,不能是链接文件,并且文件的权限需要设定成 ntpd 守护进程可以写入。
 
8.1.2 NTP 配置实例
 
  下面以本地配置一个服务器与客户端为例介绍 CGSL NTP 的配置过程。
 
8.1.2.1 服务器端配置
 
  1、首先查询 chrony 软件版本
 
    #rpm -q chrony  
 
    chrony-1.29.1-1.el7.x86_64  
 
  如果没有,可以从 CGS L 安装盘上查找,找到后用 rpm 命令安装,示例如下:
 
    # rpm –ivh chrony-1.29.1-1.el7.x86_64.rpm  
 
  2、编辑配置文件

    #vi /etc/ chrony.conf  
 
  修改配置文件/etc/chrony.conf,使用 192.168.17.234 为上层时钟源,并对下级客户端 192.168.17 网段开放权限
 
    
  # Use public servers from the pool.ntp.org project.
 
  # Please consider joining the pool (http://www.pool.ntp.org/join.html).
 
  server 192.168.17.234 iburst 配置上层时钟源,不能为本机
 
 
  # Ignore stratum in source selection.
 
  stratumweight 0
 
  # Record the rate at which the system clock gains/losses time.
 
  driftfile /var/lib/chrony/drift 配置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
 
  allow 192.168.17/24配置下层客户端的访问权限
 
 
  # 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
 
 
  keyfile /etc/chrony.keys
 
 
  # Specify the key used as password for chronyc.
 
  commandkey 1
 
  # Generate command key if missing.
 
  generatecommandkey
 
 
  # 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









































































  3、重启 chrony 服务
 
    # systemctl restart chrony  
 
  4、查看 ntp 服务状态
 
  如果同步正常,显示如下:
 
    
  # chronyc sources -v
 
  210 Number of sources = 1
 
  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 
  / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
 
  | /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
 
  ||                                                 .- xxxx [ yyyy ] +/- zzzz
 
  ||                                                /   xxxx = adjusted offset,
 
  ||         Log2(Polling interval) -.             |    yyyy = measured offset,
 
  ||                                  \            |    zzzz = estimated error.
 
  ||                                   |           |
 
  MS Name/IP address         Stratum Poll Reach LastRx Last sample
 
  ===============================================================
  ================
 
  ^* 192.168.17.234                6   7   377   128  -1712ns[-2000ns] +/-   11ms




























8.1.2.2 客户端配置
 
  1、首先查询 chrony 软件包
 
    #rpm -q chrony  
 
    chrony-1.29.1-1.el7.x86_64  
 
  如果没有可以从 CGS Linux 安装盘上查找,找到后用下面的命令安装:
 
    # rpm –ivh chrony-1.29.1-1.el7.x86_64.rpm  
 
  2、编辑/etc/ chrony.conf,假设上层时钟源为 192.168.17.215,则保留如下内容:
 
    
  # Use public servers from the pool.ntp.org project.
 
  # Please consider joining the pool (http://www.pool.ntp.org/join.html).
 
  server 192.168.17.215配置上层时钟源,不能为本机
 
 
  # Ignore stratum in source selection.
 
  stratumweight 0
 
 
  # Record the rate at which the system clock gains/losses time.
 
  driftfile /var/lib/chrony/drift配置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.
 
  # 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
 
 
  keyfile /etc/chrony.keys
 
  # Specify the key used as password for chronyc.
 
  commandkey 1
 
 
  # Generate command key if missing.
 
  generatecommandkey
 
 
  # 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





































































  3、、重启 chrony 服务:
 
    # systemctl restart chrony  
 
  4、检查 ntp 服务状态
 
  结果如下则同步正常:

    
  # chronyc sources -v
 
  210 Number of sources = 1
 
  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 
  / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
 
  | /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
 
  ||                                                 .- xxxx [ yyyy ] +/- zzzz
 
  ||                                                /   xxxx = adjusted offset,
 
  ||         Log2(Polling interval) -.             |    yyyy = measured offset,
 
  ||                                  \            |    zzzz = estimated error.
 
  ||                                   |           |
 
  MS Name/IP address         Stratum Poll Reach LastRx Last sample
 
  ==============================================================
  =================
 
  ^* 192.168.17.215                7   7   377    92    -22us[  -27us] +/-   10ms



























 
  如果输出和上面相似,则说明时间服务器成功,服务启动后,会自动同步时间。





  • 操作系统微信公众号

  • CPI微信公众号

© 2004-2020 广东中兴新支点技术有限公司  版权所有  (www.gd-linux.com)  粤ICP备15061780号-2

新支点OS业务:

QQ客服