chrony时间同步服务(2)

[root@ntp-server ~]# timedatectl
      Local time: Tue 2018-08-21 14:02:35 CST
  Universal time: Tue 2018-08-21 06:02:35 UTC
        RTC time: Tue 2018-08-21 06:02:33
      Time zone: Asia/Shanghai (CST, +0800)
    NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@ntp-server ~]# timedatectl
list-timezones  set-ntp        set-timezone   
set-local-rtc  set-time        status
[root@ntp-server ~]# timedatectl list-timezones | grep -i shanghai
Asia/Shanghai

//关闭NTP
[root@ntp-server ~]# timedatectl set-ntp false
[root@ntp-server ~]# timedatectl
      Local time: Tue 2018-08-21 14:15:36 CST
  Universal time: Tue 2018-08-21 06:15:36 UTC
        RTC time: Tue 2018-08-21 06:15:36
      Time zone: Asia/Shanghai (CST, +0800)
    NTP enabled: no
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

//启用NTP
[root@ntp-server ~]# timedatectl set-ntp true
[root@ntp-server ~]# timedatectl
      Local time: Tue 2018-08-21 14:16:02 CST
  Universal time: Tue 2018-08-21 06:16:02 UTC
        RTC time: Tue 2018-08-21 06:16:02
      Time zone: Asia/Shanghai (CST, +0800)
    NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

//查看一下ntpdate由哪个包提供的
[root@ntp-server ~]# yum provides ntpdate
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
ntpdate-4.2.6p5-25.el7_3.2.x86_64 : Utility to set the date and time via NTP
Repo        : dvd

//如果没有请安装ntpdate
[root@ntp-server ~]# yum install ntpdate.x86_64
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.6p5-25.el7_3.2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================
 Package            Arch              Version                        Repository      Size
==========================================================================================
Installing:
 ntpdate            x86_64            4.2.6p5-25.el7_3.2            dvd            86 k

Transaction Summary
==========================================================================================
Install  1 Package

Total download size: 86 k
Installed size: 121 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : ntpdate-4.2.6p5-25.el7_3.2.x86_64                                      1/1
  Verifying  : ntpdate-4.2.6p5-25.el7_3.2.x86_64                                      1/1

Installed:
  ntpdate.x86_64 0:4.2.6p5-25.el7_3.2                                                   

Complete!


2.配置时间同步服务器
[root@ntp-server ~]# vim /etc/chrony.conf
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
server ntp4.aliyun.com iburst
server ntp5.aliyun.com iburst
server ntp6.aliyun.com iburst
server ntp7.aliyun.com iburst

allow 172.16.10.0/24

//验证服务端是否能同步时间
[root@ntp-server ~]# chronyc sources -v
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
||      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             
===============================================================================
^* 120.25.115.20                2  6    17    22  -117us[ -948us] +/-  24ms

//看一下服务器时间
[root@ntp-server ~]# date
Tue Aug 21 15:31:29 CST 2018

//看一下客户端时间 时间不对需要同步
[root@ntp-client ~]# date
Fri Aug 20 14:10:28 CST 2010

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/12543.html