搭建时间同步chrony
安装chrony服务器
[root@localhost ~]# yum -y install chrony
或ubuntu
root@BJ-long:~# apt install chrony -y
改配置
[root@localhost ~]# vim /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 ntp.aliyun.com iburst
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
# Allow NTP client access from local network.
#allow 192.168.0.0/16
allow 0.0.0.0/0
# Serve time even if not synchronized to a time source.
local stratum 10
重启服务并开机启动
[root@localhost ~]# systemctl enable --now chronyd
查看同步时间的服务器ip
[root@localhost ~]# chronyc sources -v

配置客户端
[root@localhost ~]# yum -y install chrony
修改配置文件(centos系统)
[root@localhost ~]# vim /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 172.31.0.17 iburst
重启并开机启动
[root@localhost ~]# systemctl enable --now chronyd
查看同步的ip
[root@localhost ~]# 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               
===============================================================================
^* 172.31.0.17                   3   6    17     2    -23us[  +16us] +/-   31ms
说明:
^*:说明同步成功
^?:说明没有同步
改配置文件(ubuntu系统)
root@BJ-long:~# vim /etc/chrony/chrony.conf
server 172.31.0.17 iburst
启动并开机自启
root@BJ-long:~# systemctl enable --now chronyd
查看同步的ip
root@BJ-long:~# 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               
===============================================================================
^* 172.31.0.17                   3   6    37    13  -4256ns[-1824us] +/-   17ms

实验
[root@localhost ~]# date
Thu Apr 29 11:24:17 CST 2021
[root@localhost ~]# date -s '1 days'
Fri Apr 30 11:24:27 CST 2021
[root@localhost ~]# 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               
===============================================================================
^? 172.31.0.17                   0   6   377     -     +0ns[   +0ns] +/-    0ns
修改的时间,时间为:明天,比如今天29号,明天是30号


等一会就会发现时间同步了

检查时间也是同步了
[root@localhost ~]# date
Thu Apr 29 12:02:14 CST 2021

 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号