chrony时间同步简明设置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/stevensxiao/article/details/85103186

场景

TimesTen Scaleout User Guide中提到:

It is important to ensure that the system clocks of every host in your grid are roughly synchronized. Synchronized system clocks ensure that timestamps of transactions and logs are accurate on all hosts.

也就是说,grid成员之间是需要时间同步的,此处不涉及到ZooKeeper主机,因为ZooKeeper服务并不依赖于时间同步机制。

此处我们配置管理服务器(10.0.0.11)为时间同步服务器,其它的数据主机为数据同步客户端,服务使用chrony而非NTP,因为chrony更简洁,也更准确。

在配置前,请确认chrony依据安装:

[oracle@datahost1 ~]$ sudo yum info chrony
Loaded plugins: ulninfo
Installed Packages
Name        : chrony
Arch        : x86_64
Version     : 3.2
Release     : 2.0.1.el7
Size        : 476 k
Repo        : installed
From repo   : anaconda
Summary     : An NTP client/server
URL         : https://chrony.tuxfamily.org
License     : GPLv2
Description : A client/server for the Network Time Protocol, this program keeps your
            : computer's clock accurate. It was specially designed to support
            : systems with intermittent internet connections, but it also works well
            : in permanently connected environments. It can use also hardware reference
            : clocks, system real-time clock or manual input as time references.

如果未安装:

sudo yum install chrony

服务器端设置

默认的/etc/chrony.conf文件内容如下:

[oracle@mgmthost1 ~]$ cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.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

以下为修改的部分,共两处,含义见英文注释:

...
# Allow NTP client access from local network.
allow 10.0.0.0/24

# Serve time even if not synchronized to a time source.
local stratum 10
...

重启服务,服务器端就配置完成了:

[oracle@mgmthost1 ~]$ sudo systemctl restart chronyd

和服务器端相关的一些命令:

[oracle@mgmthost1 ~]$ chronyc
chrony version 3.2
Copyright (C) 1997-2003, 2007, 2009-2017 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
System clock:
tracking                    Display system time information
makestep                    Correct clock by stepping immediately
makestep <threshold> <updates>
                            Configure automatic clock stepping
maxupdateskew <skew>        Modify maximum valid skew to update frequency
waitsync [<max-tries> [<max-correction> [<max-skew> [<interval>]]]]
                            Wait until synchronised in specified limits

Time sources:
sources [-v]                Display information about current sources
sourcestats [-v]            Display statistics about collected measurements
reselect                    Force reselecting synchronisation source
reselectdist <dist>         Modify reselection distance

NTP sources:
activity                    Check how many NTP sources are online/offline
ntpdata [<address>]         Display information about last valid measurement
add server <address> [options]
                            Add new NTP server
add peer <address> [options]
                            Add new NTP peer
delete <address>            Remove server or peer
burst <n-good>/<n-max> [<mask>/<address>]
                            Start rapid set of measurements
maxdelay <address> <delay>  Modify maximum valid sample delay
maxdelayratio <address> <ratio>
                            Modify maximum valid delay/minimum ratio
maxdelaydevratio <address> <ratio>
                            Modify maximum valid delay/deviation ratio
minpoll <address> <poll>    Modify minimum polling interval
maxpoll <address> <poll>    Modify maximum polling interval
minstratum <address> <stratum>
                            Modify minimum stratum
offline [<mask>/<address>]  Set sources in subnet to offline status
online [<mask>/<address>]   Set sources in subnet to online status
polltarget <address> <target>
                            Modify poll target
refresh                     Refresh IP addresses

Manual time input:
manual off|on|reset         Disable/enable/reset settime command
manual list                 Show previous settime entries
manual delete <index>       Delete previous settime entry
settime <time>              Set daemon time
                            (e.g. Sep 25, 2015 16:30:05 or 16:30:05)

NTP access:
accheck <address>           Check whether address is allowed
clients                     Report on clients that have accessed the server
serverstats                 Display statistics of the server
allow [<subnet>]            Allow access to subnet as a default
allow all [<subnet>]        Allow access to subnet and all children
deny [<subnet>]             Deny access to subnet as a default
deny all [<subnet>]         Deny access to subnet and all children
local [options]             Serve time even when not synchronised
local off                   Don't serve time when not synchronised
smoothtime reset|activate   Reset/activate time smoothing
smoothing                   Display current time smoothing state

Monitoring access:
cmdaccheck <address>        Check whether address is allowed
cmdallow [<subnet>]         Allow access to subnet as a default
cmdallow all [<subnet>]     Allow access to subnet and all children
cmddeny [<subnet>]          Deny access to subnet as a default
cmddeny all [<subnet>]      Deny access to subnet and all children

Real-time clock:
rtcdata                     Print current RTC performance parameters
trimrtc                     Correct RTC relative to system clock
writertc                    Save RTC performance parameters to file

Other daemon commands:
cyclelogs                   Close and re-open log files
dump                        Dump all measurements to save files
rekey                       Re-read keys from key file

Client commands:
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 <retries>           Set maximum number of retries
keygen [<id> [<type> [<bits>]]]
                            Generate key for key file
exit|quit                   Leave the program
help                        Generate this help

chronyc> tracking
Reference ID    : 81FA23FA (x.ns.gin.ntt.net)
Stratum         : 3
Ref time (UTC)  : Wed Dec 19 10:13:38 2018
System time     : 0.000008470 seconds slow of NTP time
Last offset     : -0.010182994 seconds
RMS offset      : 0.005926364 seconds
Frequency       : 6.033 ppm slow
Residual freq   : +10.523 ppm
Skew            : 1.731 ppm
Root delay      : 0.218899384 seconds
Root dispersion : 0.002497401 seconds
Update interval : 0.8 seconds
Leap status     : Normal
chronyc> activity
200 OK
4 sources online
0 sources offline
0 sources doing burst (return to online)
0 sources doing burst (return to offline)
0 sources with unknown address
chronyc> sources
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^- ntp.paina.net                 2   6    37    62   +900us[ +900us] +/-   65ms
^* x.ns.gin.ntt.net              2   6    37    63   +402us[-9781us] +/-  112ms
^? ntp-b2.nict.go.jp             1   6     1    64   +167us[+4717us] +/-   39ms
^+ y.ns.gin.ntt.net              2   6    37    63   -557us[  -11ms] +/-  142ms
chronyc> sourcestats
210 Number of sources = 4
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
ntp.paina.net               6   5   137    +26.369    282.404  +2502us  4540us
x.ns.gin.ntt.net            6   3   136     -2.296    118.258   +553us  1491us
ntp-b2.nict.go.jp           2   0    64     +0.002   2000.000  -5706us  4000ms
y.ns.gin.ntt.net            6   3   136     -0.549    145.024   -716us  1820us
chronyc> exit

客户端设置

客户端也是使用chronyd服务。
修改/etc/chrony.conf文件,对于默认的配置文件,只需要修改移除,即server指向管理服务器的IP地址10.0.0.11:

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# server 0.pool.ntp.org iburst
# server 1.pool.ntp.org iburst
# server 2.pool.ntp.org iburst
server 10.0.0.11

# 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

重启服务:

systemctl restart chronyd

相关监控命令如下:

[oracle@datahost1 ~]$ chronyc
chrony version 3.2
Copyright (C) 1997-2003, 2007, 2009-2017 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> sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* mgmthost1                     2   6   377    19   +271us[ +324us] +/-   47ms
chronyc> activity
200 OK
1 sources online
0 sources offline
0 sources doing burst (return to online)
0 sources doing burst (return to offline)
0 sources with unknown address
chronyc> tracking
Reference ID    : 0A00000B (mgmthost1)
Stratum         : 3
Ref time (UTC)  : Wed Dec 19 10:20:16 2018
System time     : 0.000195726 seconds fast of NTP time
Last offset     : +0.000053017 seconds
RMS offset      : 0.004054334 seconds
Frequency       : 3.973 ppm slow
Residual freq   : -0.075 ppm
Skew            : 23.666 ppm
Root delay      : 0.077822976 seconds
Root dispersion : 0.002500026 seconds
Update interval : 64.5 seconds
Leap status     : Normal
chronyc> sourcestats
210 Number of sources = 1
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
mgmthost1                   8   4   454     -0.075     24.249  -2895ns  1797us
chronyc> exit

检查系统时间同步的设置:

[oracle@datahost1 ~]$ timedatectl
      Local time: Wed 2018-12-19 18:21:34 CST
  Universal time: Wed 2018-12-19 10:21:34 UTC
        RTC time: Wed 2018-12-19 10:21:35
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

确认

在时间同步服务器上可以检查客户端的状态,注意必须用root用户执行,否则报501错:

[oracle@mgmthost1 ~]$ sudo chronyc
chrony version 3.2
Copyright (C) 1997-2003, 2007, 2009-2017 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> clients
Hostname                      NTP   Drop Int IntL Last     Cmd   Drop Int  Last
===============================================================================
localhost                       0      0   -   -     -       1      0   -   278
datahost3                       5      0   6   -     6       0      0   -     -
datahost1                       4      0   6   -    55       0      0   -     -
datahost4                       4      0   6   -    48       0      0   -     -
datahost2                       4      0   6   -    33       0      0   -     -
chronyc> exit

从管理节点上查询时间:

[oracle@mgmthost1 ~]$ ttGridAdmin hostExec date
Commands executed on:
  ttdatahost1 rc 0
  ttdatahost2 rc 0
  ttdatahost3 rc 0
  ttdatahost4 rc 0
  ttmgmthost1 rc 0
Return code from ttdatahost1: 0
Output from ttdatahost1:
Wed Dec 19 18:22:27 CST 2018
Return code from ttdatahost2: 0
Output from ttdatahost2:
Wed Dec 19 18:22:27 CST 2018
Return code from ttdatahost3: 0
Output from ttdatahost3:
Wed Dec 19 18:22:27 CST 2018
Return code from ttdatahost4: 0
Output from ttdatahost4:
Wed Dec 19 18:22:27 CST 2018
Return code from ttmgmthost1: 0
Output from ttmgmthost1:
Wed Dec 19 18:22:27 CST 2018

参考

  1. https://chrony.tuxfamily.org/faq.html
  2. https://docs.oracle.com/database/timesten-18.1/TTGRD/reporting.htm#TTGRD371

猜你喜欢

转载自blog.csdn.net/stevensxiao/article/details/85103186