首页 > 代码库 > RH124-10 时间同步NTP

RH124-10 时间同步NTP

[student@localhost Desktop]$ timedatectl

      Local time: Sat 2017-06-03 21:58:12 CST

  Universal time: Sat 2017-06-03 13:58:12 UTC

        Timezone: Asia/Shanghai (CST, +0800)

     NTP enabled: yes

NTP synchronized: no

 RTC in local TZ: no

      DST active: n/a

[student@localhost Desktop]$ 


对时间设定需要root


远程到server0

[root@server0 ~]# timedatectl list-timezones  查看支持的时区

Africa/Abidjan

Africa/Accra

Africa/Addis_Ababa

Africa/Algiers



[root@server0 ~]# timedatectl set-timezone "America/New_York"

[root@server0 ~]# timedatectl 

      Local time: Sat 2017-06-03 10:09:02 EDT

  Universal time: Sat 2017-06-03 14:09:02 UTC

        RTC time: Sat 2017-06-03 22:09:02

        Timezone: America/New_York (EDT, -0400)

     NTP enabled: yes

NTP synchronized: no

 RTC in local TZ: no

      DST active: yes

 Last DST change: DST began at

                  Sun 2017-03-12 01:59:59 EST

                  Sun 2017-03-12 03:00:00 EDT

 Next DST change: DST ends (the clock jumps one hour backwards) at

                  Sun 2017-11-05 01:59:59 EDT

                  Sun 2017-11-05 01:00:00 EST

[root@server0 ~]# 




[root@server0 ~]# timedatectl set-time 22:25:00  设置 时间



[root@server0 ~]# timedatectl set-ntp true

[root@server0 ~]# timedatectl 

      Local time: Sat 2017-06-03 22:27:06 EDT

  Universal time: Sun 2017-06-04 02:27:06 UTC

        RTC time: Sun 2017-06-04 02:27:07

        Timezone: America/New_York (EDT, -0400)

     NTP enabled: yes

NTP synchronized: no

 RTC in local TZ: no

      DST active: yes

 Last DST change: DST began at

                  Sun 2017-03-12 01:59:59 EST

                  Sun 2017-03-12 03:00:00 EDT

 Next DST change: DST ends (the clock jumps one hour backwards) at

                  Sun 2017-11-05 01:59:59 EDT

                  Sun 2017-11-05 01:00:00 EST


[root@server0 ~]# vim /etc/chrony.conf

 写入 

server content.example.com iburst 目的是  让系统知道从哪里同步NTP时间

[root@server0 ~]# systemctl enable chronyd

[root@server0 ~]# systemctl restart chronyd

[root@server0 ~]# 

大约需要五分钟才可以同步


检验:

[root@server0 ~]# timedatectl     命令1

      Local time: Sat 2017-06-03 10:22:59 EDT

  Universal time: Sat 2017-06-03 14:22:59 UTC

        RTC time: Sat 2017-06-03 14:22:59

        Timezone: America/New_York (EDT, -0400)

     NTP enabled: yes   看这里

NTP synchronized: yes   看这里

 RTC in local TZ: no

      DST active: yes

 Last DST change: DST began at

                  Sun 2017-03-12 01:59:59 EST

                  Sun 2017-03-12 03:00:00 EDT

 Next DST change: DST ends (the clock jumps one hour backwards) at

                  Sun 2017-11-05 01:59:59 EDT

                  Sun 2017-11-05 01:00:00 EST

[root@server0 ~]# chronyc sources -v   命令2

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

===============================================================================

^* classroom.example.com         8   6    37    28   +230ns[ +164us] +/- 1082us

[root@server0 ~]# chro

chronyc  chronyd  chroot   

[root@server0 ~]# chronyc   命令3

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> waitsync   命令4

try: 1, refid: 172.25.254.254, correction: 0.000006130, skew: 1.482

chronyc> 


本文出自 “HCIE_38xx” 博客,谢绝转载!

RH124-10 时间同步NTP