page counter next up previous contents
Next: ntpd 使用 Up: Chronyd vs. ntpd 校時 Previous: 前言   Contents

chronyd 使用

  1. chrony 是 RHEL/CentOS 7 預設的校時 dameon,設定檔在 /etc/chrony.conf,新增校時伺服器 server.deyu.wang,其中 iburst 選項是用來加速初始同步。
    [root@kvm81 ~]# vim /etc/chrony.conf 
    server deyu.wang
    [root@kvm81 ~]# grep deyu /etc/chrony.conf 
    server server.deyu.wang iburst
    
  2. 重新啟動 chronyd。
    [root@kvm81 ~]# systemctl restart chronyd.service
    
  3. chronyd 預設開機啟動,不放心可再設定一次。
    [root@kvm81 ~]# systemctl enable chronyd.service
    
  4. 追踪 chronyd 校時來源伺服器。
    [root@kvm81 ~]# chronyc tracking
    Reference ID    : 192.168.122.1 (deyu.wang)
    Stratum         : 4
    Ref time (UTC)  : Tue Jan 20 03:01:00 2015
    System time     : 124520.273437500 seconds slow of NTP time
    Last offset     : 0.000016787 seconds
    RMS offset      : 11733.896484375 seconds
    Frequency       : 0.074 ppm slow
    Residual freq   : 0.007 ppm
    Skew            : 0.413 ppm
    Root delay      : 0.006454 seconds
    Root dispersion : 0.045809 seconds
    Update interval : 59.5 seconds
    Leap status     : Normal
    
  5. 使用 chronyc 命令檢查 chronyd 校時來源伺服器,server.deyu.wang 已在表列中。
    [root@kvm81 ~]# chronyc sources
    210 Number of sources = 5
    MS Name/IP address         Stratum Poll Reach LastRx Last sample
    ===============================================================================
    ^- server.deyu.wang              3   6   177    52   -837us[ -831us] +/-   55ms
    ^- ns.rpb.gov.tw                 2   6   377    48  +3203us[+3209us] +/-  426ms
    ^+ 117-56-73-145.HINET-IP.hi     3   6   377   241   -102us[ +142us] +/-  106ms
    ^+ 220-135-58-124.HINET-IP.h     3   6   377    47   +248us[ +248us] +/-   76ms
    ^* 123-204-45-116.static.see     3   6   377    50   -636us[ -630us] +/-   67ms
    
  6. chronyc 是互動式指令,若不知道此指令可以使用哪些 command?可以先進入其互動式模式中,輸入 help 命令,就可以列出可用的 command。
    [root@kvm7 ~]# chronyc 
    chrony version 1.29.1
    Copyright (C) 1997-2003, 2007, 2009-2013 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> help
    Commands:
    accheck <address> : Check whether NTP access is allowed to <address>
    activity : Check how many NTP sources are online/offline
    add peer <address> ... : Add a new NTP peer
    add server <address> ... : Add a new NTP server
    allow [<subnet-addr>] : Allow NTP access to that subnet as a default
    allow all [<subnet-addr>] : Allow NTP access to that subnet and all children
    burst <n-good>/<n-max> [<mask>/<masked-address>] : Start a rapid set of measurements
    clients : Report on clients that have accessed the server
    cmdaccheck <address> : Check whether command access is allowed to <address>
    cmdallow [<subnet-addr>] : Allow command access to that subnet as a default
    cmdallow all [<subnet-addr>] : Allow command access to that subnet and all children
    cmddeny [<subnet-addr>] : Deny command access to that subnet as a default
    cmddeny all [<subnet-addr>] : Deny command access to that subnet and all children
    cyclelogs : Close and re-open logs files
    delete <address> : Remove an NTP server or peer
    deny [<subnet-addr>] : Deny NTP access to that subnet as a default
    deny all [<subnet-addr>] : Deny NTP access to that subnet and all children
    dump : Dump all measurements to save files
    local off : Disable server capability for unsynchronised clock
    local stratum <stratum> : Enable server capability for unsynchronised clock
    makestep : Jump the time to remove any correction being slewed
    manual off|on|reset : Disable/enable/reset settime command and statistics
    manual list : Show previous settime entries
    maxdelay <address> <new-max-delay> : Modify maximum round-trip valid sample delay for source
    maxdelayratio <address> <new-max-ratio> : Modify max round-trip delay ratio for source
    maxdelaydevratio <address> <new-max-ratio> : Modify max round-trip delay dev ratio for source
    maxpoll <address> <new-maxpoll> : Modify maximum polling interval of source
    maxupdateskew <new-max-skew> : Modify maximum skew for a clock frequency update to be made
    minpoll <address> <new-minpoll> : Modify minimum polling interval of source
    minstratum <address> <new-min-stratum> : Modify minimum stratum of source
    offline [<mask>/<masked-address>] : Set sources in subnet to offline status
    online [<mask>/<masked-address>] : Set sources in subnet to online status
    password [<new-password>] : Set command authentication password
    polltarget <address> <new-poll-target> : Modify poll target of source
    reselect : Reselect synchronisation source
    rtcdata : Print current RTC performance parameters
    settime <date/time (e.g. Nov 21, 1997 16:30:05 or 16:30:05)> : Manually set the daemon time
    sources [-v] : Display information about current sources
    sourcestats [-v] : Display estimation information about current sources
    tracking : Display system time information
    trimrtc : Correct RTC relative to system clock
    waitsync [max-tries [max-correction [max-skew]]] : Wait until synchronised
    writertc : Save RTC parameters to file
    
    authhash <name>: Set command authentication hash function
    dns -n|+n : Disable/enable resolving IP addresses to hostnames
    dns -4|-6|-46 : Resolve hostnames only to IPv4/IPv6/both addresses
    timeout <milliseconds> : Set initial response timeout
    retries <n> : Set maximum number of retries
    exit|quit : Leave the program
    help : Generate this help
    
    chronyc>
    
  7. 重新啟動 chronycd。
    [root@kvm81 ~]# systemctl restart chronyd.service
    
  8. -l 選項查看 chrony 自動校時狀態及工作紀錄,倒數第二行,系統調整時間 127369.424623 秒。
    [root@kvm81 ~]# systemctl status chronyd.service -l
    chronyd.service - NTP client/server
       Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled)
       Active: active (running) since Mon 2015-01-19 01:26:00 CST; 1 day 11h ago
      Process: 18379 ExecStartPost=/usr/libexec/chrony-helper add-dhclient-servers (code=exited, status=0/SUCCESS)
      Process: 18376 ExecStart=/usr/sbin/chronyd -u chrony $OPTIONS (code=exited, status=0/SUCCESS)
     Main PID: 18378 (chronyd)
       CGroup: /system.slice/chronyd.service
               └─18378 /usr/sbin/chronyd -u chrony
    
    Jan 19 01:26:00 kvm81.deyu.wang systemd[1]: Starting NTP client/server...
    Jan 19 01:26:00 kvm81.deyu.wang chronyd[18378]: chronyd version 1.29.1 starting
    Jan 19 01:26:00 kvm81.deyu.wang chronyd[18378]: Linux kernel major=3 minor=10 patch=0
    Jan 19 01:26:00 kvm81.deyu.wang chronyd[18378]: hz=100 shift_hz=7 freq_scale=1.00000000 nominal_tick=10000 slew_delta_tick=833 max_tick_bias=1000 shift_pll=2
    Jan 19 01:26:00 kvm81.deyu.wang chronyd[18378]: Frequency 0.008 +/- 0.068 ppm read from /var/lib/chrony/drift
    Jan 19 01:26:00 kvm81.deyu.wang systemd[1]: Started NTP client/server.
    Jan 19 01:26:08 kvm81.deyu.wang chronyd[18378]: Selected source 120.119.28.1
    Jan 19 01:26:08 kvm81.deyu.wang chronyd[18378]: System clock wrong by 127369.424623 seconds, adjustment started
    Jan 20 12:48:57 kvm81.deyu.wang chronyd[18378]: System clock was stepped by 127369.425 seconds
    
  9. chronyc 手動校時。
    [root@kvm81 ~]# date -s 2015-01-19
    Mon Jan 19 00:00:00 CST 2015
    [root@kvm81 ~]# chronyc -a makestep
    200 OK
    200 OK
    [root@kvm81 ~]# date
    Tue Jan 20 11:27:29 CST 2015
    



2015-12-04