普遍使用Chrony
现在Linux的发行版已经普遍使用chrony来代替ntpd进行时间同步管理了。
使用以下命令查看你的系统上chrony启动状态:
systemctl status chronyd
如果你的系统没有chronyd,可以使用以下命令进行安装。
yum install chrony -y
一般情况下,chrony只要启动了很快就会从默认的配置中完成时间的同步,所以只需要重启chrony就可以同步时间。
#启动应用systemctl enable --now chronyd#重新启动应用systemctl restart chronyd
Chrony包含两个部分,chronyd是提供时间同步服务的守护进程,chronyc是用来控制chrony的命令行工具。
Chronyc
与ntpd还有一个不同之处就是Chrony自带了一个命令行工具。
System clock:tracking Display system time informationmakestep Correct clock by stepping immediatelymakestep <threshold> <updates>Configure automatic clock steppingmaxupdateskew <skew> Modify maximum valid skew to update frequencywaitsync [<max-tries> [<max-correction> [<max-skew> [<interval>]]]]Wait until synchronised in specified limitsTime sources:sources [-v] Display information about current sourcessourcestats [-v] Display statistics about collected measurementsreselect Force reselecting synchronisation sourcereselectdist <dist> Modify reselection distanceNTP sources:activity Check how many NTP sources are online/offlinentpdata [<address>] Display information about last valid measurementadd server <address> [options]Add new NTP serveradd peer <address> [options]Add new NTP peerdelete <address> Remove server or peerburst <n-good>/<n-max> [<mask>/<address>]Start rapid set of measurementsmaxdelay <address> <delay> Modify maximum valid sample delaymaxdelayratio <address> <ratio>Modify maximum valid delay/minimum ratiomaxdelaydevratio <address> <ratio>Modify maximum valid delay/deviation ratiominpoll <address> <poll> Modify minimum polling intervalmaxpoll <address> <poll> Modify maximum polling intervalminstratum <address> <stratum>Modify minimum stratumoffline [<mask>/<address>] Set sources in subnet to offline statusonline [<mask>/<address>] Set sources in subnet to online statusonoffline Set all sources to online or offline statusaccording to network configurationpolltarget <address> <target>Modify poll targetrefresh Refresh IP addressesManual time input:manual off|on|reset Disable/enable/reset settime commandmanual list Show previous settime entriesmanual delete <index> Delete previous settime entrysettime <time> Set daemon time(e.g. Sep 25, 2015 16:30:05 or 16:30:05)NTP access:accheck <address> Check whether address is allowedclients Report on clients that have accessed the serverserverstats Display statistics of the serverallow [<subnet>] Allow access to subnet as a defaultallow all [<subnet>] Allow access to subnet and all childrendeny [<subnet>] Deny access to subnet as a defaultdeny all [<subnet>] Deny access to subnet and all childrenlocal [options] Serve time even when not synchronisedlocal off Don't serve time when not synchronisedsmoothtime reset|activate Reset/activate time smoothingsmoothing Display current time smoothing stateMonitoring access:cmdaccheck <address> Check whether address is allowedcmdallow [<subnet>] Allow access to subnet as a defaultcmdallow all [<subnet>] Allow access to subnet and all childrencmddeny [<subnet>] Deny access to subnet as a defaultcmddeny all [<subnet>] Deny access to subnet and all childrenReal-time clock:rtcdata Print current RTC performance parameterstrimrtc Correct RTC relative to system clockwritertc Save RTC performance parameters to fileOther daemon commands:cyclelogs Close and re-open log filesdump Dump all measurements to save filesrekey Re-read keys from key fileshutdown Stop daemonClient commands:dns -n|+n Disable/enable resolving IP addresses to hostnamesdns -4|-6|-46 Resolve hostnames only to IPv4/IPv6/both addressestimeout <milliseconds> Set initial response timeoutretries <retries> Set maximum number of retrieskeygen [<id> [<type> [<bits>]]]Generate key for key fileexit|quit Leave the programhelp Generate this help
因为chrony在启动的时候会立刻进行时间同步,所以chronyc的主要用途除了进行配置之外,就是查看当前的状态信息。
配置文件
# Use public servers from the pool.ntp.org project.# Please consider joining the pool (http://www.pool.ntp.org/join.html).# 从下列服务器获取时间server 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.pool.ntp.org iburstserver 3.centos.pool.ntp.org iburst# 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# Enable hardware timestamping on all interfaces that support it.#hwtimestamp *# Increase the minimum number of selectable sources required to adjust# the system clock.#minsources 2# Allow NTP client access from local network.# 允许以下网段的设备访问此服务器的时间同步服务#allow 192.168.0.0/16# Serve time even if not synchronized to a time source.#local stratum 10# Specify file containing keys for NTP authentication.#keyfile /etc/chrony.keys# Specify directory for log files.logdir /var/log/chrony# Select which information is logged.#log measurements statistics tracking
