系统时间(System Time):由内核维护的时间
硬件时间(Hardware Time):由BIOS提供的时间
时间相关命令:
查询修改系统时间:date
查询修改硬件时间:hwclock
hwclock -w :将系统时间写入硬件时间
timedatectl : 看看时区;
ntp 端口 123
Chrony:
Chrony是一个开源的自由软件,它能保持系统时钟与时钟服务器(NTP)同步,让时间保持精确。它由两个程序组成:chronyd和chronyc。
chronyd是一个后台运行的守护进程,用于调整内核中运行的系统时钟和时钟服务器同步。它确定计算 机增减时间的比率,并对此进行补偿。
chronyc 提供了一个用户界面,用于监控性能并进行多样化的配置。它可以在chronyd实例控制的计算机上工作,也可以在一台不同的远程计算机上工作
配置文件:Chrony启动时,它会读取/etc/chrony.conf配置文件中的设置
服务端安装chrony
[root@localhost ~]# yum install chrony –y #安装chrony
服务端配置chrony主机: cat /etc/chrony.conf
#server 0.rhel.pool.ntp.org iburst --注释这4行,由于是内网环境,所以无法跟外部时间服务器进行时间同步。
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
server 192.168.100.1 iburst --添加这一行,表示与本机同步时间
server ntp-sz.ch1.la iburst
server ntp.gwadar.cn iburst
local stratum 10 --该行取消注释
# Allow NTP client access from local network.
allow 192.168.100.0/24 --允许哪些服务器到这台服务器来同步时间
设置开机自启
#systemctl start chronyd
#systemctl status chronyd --查看chronyd服务状态
#systemctl enable chronyd --开机启动
查看时间同步源状态:chronyc sourcestats -v
[root@localhost ~]# chronyc sourcestats -v
210 Number of sources = 4
.- Number of sample points in measurement set.
/ .- Number of residual runs with same sign.
| / .- Length of measurement set (time).
| | / .- Est. clock freq error (ppm).
| | | / .- Est. error in freq.
| | | | / .- Est. offset.
| | | | | | On the -.
| | | | | | samples. \
| | | | | | |
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
==============================================================================
ntp6.flashdance.cx 9 6 334 -14.185 53.087 -25ms 3061us
120.25.115.20 9 5 331 +0.068 6.495 +2316ns 349us
5.20.0.21 9 5 333 -2.901 34.809 +1544us 2018us
ntp7.flashdance.cx 9 7 334 -6.846 6.969 -19ms 544us
查看时间同步源:# chronyc sources -v
[root@localhost ~]# chronyc sources -v
210 Number of sources = 4
.-- 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
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^- ntp6.flashdance.cx 2 6 377 24 -25ms[ -25ms] +/- 245ms
^* 120.25.115.20 2 6 377 28 -501us[ -821us] +/- 27ms
^- 5.20.0.21 2 6 377 25 -44us[ -44us] +/- 213ms
^- ntp7.flashdance.cx 2 6 377 24 -12ms[ -12ms] +/- 231ms
客户端安装chrony
[root@localhost ~]# yum install chrony –y
客户端配置文件:cat /etc/chrony.conf
[root@localhost ~]# vi /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.rhel.pool.ntp.org iburst --注释这4行
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
server 192.168.10.16 iburst ---添加该行,表示到这台服务器去同步时间。
客户端启动服务
#systemctl start chronyd
#systemctl status chronyd --查看chronyd服务状态
#systemctl enable chronyd --开机启动
timedatectl 查看未同步时间
[root@node1 ~]# timedatectl
Local time: Tue 2018-10-23 04:28:18 EDT
Universal time: Tue 2018-10-23 08:28:18 UTC
RTC time: Tue 2018-10-23 08:28:18
Time zone: America/New_York (EDT, -0400)
NTP enabled: n/a
NTP synchronized: no #未同步时间
RTC in local TZ: no
DST active: yes
Last DST change: DST began at
Sun 2018-03-11 01:59:59 EST
Sun 2018-03-11 03:00:00 EDT
Next DST change: DST ends (the clock jumps one hour backwards) at
Sun 2018-11-04 01:59:59 EDT
Sun 2018-11-04 01:00:00 EST
查看日期时间及NTP状态:# timedatectl
查看和配置时区:# timedatectl list-timezones;# timedatectl set-timezone Asia/Shanghai
修改日期时间:# timedatectl set-time "2018-10-21 11:50:00"(可以只修改其中一个)
开启NTP:# timedatectl set-ntp true/flase
查看chrony服务所有conf配置文件分布# rpm -ql chrony |grep conf
检查chrony服务配置文件所在# rpm -qc chrony
查看chrony安装情况# rpm -qi chrony
检查ntp安装情况# yum search ntp |grep ^ntp.x86_64或# yum search ntp(列出所有ntp相关包)