打赏
Fork me on GitHub

[原]CentOS 7 chrony 笔记

~]# timedatectl  status
      Local time: Sun 2018-08-26 21:01:15 CST        ==> 本地系统实际时间,设置时间timedatectl set-time 15:58:30
                                                                           设置日期timedatectl set-time 20151120
                                                                           设置时间日期timedatectl set-time '16:10:40 2015-11-20'
      Universal time: Sun 2018-08-26 13:01:15 UTC    ==> 世界统一时间
      RTC time: Sun 2018-08-26 13:01:15              ==> 硬件时钟的时间
      Time zone: Asia/Shanghai (CST, +0800)          ==> 当前时区,查看可用时区timedatectl list-timezones
                                                                   设置当前时区timedatectl set-timezone "Asia/Shanghai"
                                                                   设置世界统一时区timedatectl set-timezone UTC
      NTP enabled: yes                               ==> 开启自动同步时间服务器功能,timedatectl set-ntp true 或 timedatectl set-ntp false
      NTP synchronized: yes                          ==> 与时间服务器的同步状态,如果显示yes,则同步成功
      RTC in local TZ: no                            ==> 将时区设置为本地时区,timedatectl set-local-rtc 1
                                                         硬件时钟设置为协调世界时(UTC)timedatectl set-local-rtc 0
      DST active: n/a



[root@network ~]# 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               
===============================================================================
^? controller                    9   6    37    47   +123us[ +123us] +/-   25ms           ==>如果前面是有个?表明时间服务器不可达 

如果一直显示为? 表示网络没有设置正确,需要设置配置文件中的网络
server : 10.50.10.10
client : 10.50.10.20
编辑 /etc/chrony.conf

【client】

# Allow NTP client access from local network.
#allow 192.168.0.0/16
allow 10.50.10.0/16

【server】

# Allow NTP client access from local network.
#allow 192.168.0.0/16
allow 10.50.10.20/24

再重新检查是否可以同步

[root@network ~]# 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               
===============================================================================
^* controller                    9   6   177    46    +19us[  -65us] +/-   36ms         ==>如果前面是有个*表明时间服务器可同步








常用的命令:
启动chronyd进程
systemctl start chronyd.service
强制单次进行时间同步  
chronyd -q 'server <时间服务器域名> iburst'
或者
ntpdate <ntp_server_name>
## 查看 ntp服务器是否可以正常同步
ntpdate -d <ntp_server_name>
## 查看 ntp_servers 状态
chronyc sources -v
## 查看 ntp_sync 状态
chronyc sourcestats -v
## 查看 ntp_servers 是否在线
chronyc activity -v
## 查看 ntp 详细信息
chronyc tracking -v







当执行ntpdate -d <ntp_server_name>出现 NTP. Server dropped: strata too high  
可能原因是时间服务器stratum 值过高  调低就可以了  比如server为 8   client为9  则正常
当执行ntpdate -d <ntp_server_name>出现Server dropped: no data  
可能原因可以使用journalctl -xe 来查看,可能是selinux没有关闭 可以在/etc/selinux/conf中disable

 

 

posted @ 2018-08-26 23:05  my_cool2007  阅读(2067)  评论(0编辑  收藏  举报