linux下搭建时间服务器

目录

1.配置chronyd, 使其从其他NTP服务器去同步时间  (配置一个aliyun可用,再配置一个不可用的)

(1)首先查看是否有chrony配置文件:rpm -qa | grep chrony

(2)没有配置文件的可下载:yum install chrony -y

(3)进入到 /etc/chrony.conf目录下进行编辑:vim /etc/chrony.conf

(4)重启时间服务器:systemctl restart chronyd

(5) 使用timedatectl查看:当前系统时钟是否已同步,ntp服务器是否可用

(6) 需要查看:时间源的状态: ^? .^*

(7)跟踪当前的同步状态:

(8)强制同步:chronyc -a makestep

2. 配置chrony:需要有两台机器,一台作为时间服务器,一台作为客户端   时间服务器的要求:不从网络同步时间,使用本地时间   客户端要求:从我们时间服务器同步时间,要求能同步成功   也要分别查看状态

(1)分别进入到两台机器下的chrony.conf文件目录进行编辑

(2)打开 local stratum 10(当外网时间服务器同步失败时,可以用本地时间来提供时间)

(3)进去到客户端的chrony.conf文件目录:vim /etc/chrony.conf

(4)把服务器和客户端的时间服务器都重启一下:systemctl restart chronyd

(5)查看当前系统时钟是否已同步,ntp服务器是否可用:timedatectl status 

(6)跟踪当前的同步态:chronyc sources -v

(7)跟踪当前的同步态:chronyc tracking -v

(8)强制同步:chronyc -a makestep


1.配置chronyd, 使其从其他NTP服务器去同步时间
  (配置一个aliyun可用,再配置一个不可用的)

(1)首先查看是否有chrony配置文件:rpm -qa | grep chrony

[root@localhost ~]# rpm -qa | grep chrony
chrony-4.1-1.el8.x86_64

(2)没有配置文件的可下载:yum install chrony -y

(3)进入到 /etc/chrony.conf目录下进行编辑:vim /etc/chrony.conf

在时间池下面添加阿里云的时间服务器地址:server ntp.aliyun.com iburst

[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).
#pool 2.rhel.pool.ntp.org iburst  #时间池
server ntp.aliyun.com iburst      #阿里云时间服务器地址
server s1a.time.edu.cn iburst     #不可用时间地址

(4)重启时间服务器:systemctl restart chronyd

(5) 使用timedatectl查看:当前系统时钟是否已同步,ntp服务器是否可用

[root@localhost ~]# timedatectl status 
               Local time: Fri 2022-09-23 13:34:58 CST
           Universal time: Fri 2022-09-23 05:34:58 UTC
                 RTC time: Fri 2022-09-23 05:34:58
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes         #系统时钟已同步
              NTP service: active      #NTP可用
          RTC in local TZ: no

(6) 需要查看:时间源的状态: ^? .^*

[root@localhost ~]# chronyc sources -v

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current best, '+' = combined, '-' = not combined,
| /             'x' = may be in error, '~' = too variable, '?' = unusable.
||                                                 .- 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               
===============================================================================
^* 203.107.6.88                  2   6    37    54   +270us[+5720us] +/-   38ms

#^*表示服务器同步到的源

(7)跟踪当前的同步状态:

chronyc tracking -v

[root@localhost ~]# chronyc tracking -v
Reference ID    : CB6B0658 (203.107.6.88)
Stratum         : 3
Ref time (UTC)  : Fri Sep 23 05:40:12 2022
System time     : 0.003046409 seconds slow of NTP time
Last offset     : -0.004557295 seconds
RMS offset      : 0.004715970 seconds
Frequency       : 1.199 ppm slow
Residual freq   : +6.425 ppm
Skew            : 1.112 ppm
Root delay      : 0.057348818 seconds
Root dispersion : 0.002519696 seconds
Update interval : 64.9 seconds
Leap status     : Normal

chronyc sourcestats -v

[root@localhost ~]# chronyc sourcestats -v
                             .- 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
==============================================================================
203.107.6.88                7   7   201    +35.041     54.227  +1551us  1410us

chronyc activity -v

[root@localhost ~]# chronyc activity -v
200 OK
1 sources online
0 sources offline
0 sources doing burst (return to online)
0 sources doing burst (return to offline)
0 sources with unknown address

(8)强制同步:chronyc -a makestep

[root@localhost ~]# chronyc -a makestep 
200 OK


2. 配置chrony:需要有两台机器,一台作为时间服务器,一台作为客户端
   时间服务器的要求:不从网络同步时间,使用本地时间
   客户端要求:从我们时间服务器同步时间,要求能同步成功
   也要分别查看状态

(1)分别进入到两台机器下的chrony.conf文件目录进行编辑

进入服务器的chrony.conf文件目录:vim /etc/chrony.conf

把阿里云的时间服务器地址注销,再添加一个不可用的时间服务器地址

[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).
#pool 2.rhel.pool.ntp.org iburst
#server ntp.aliyun.com iburst       #注销阿里云服务器地址
server s1a.time.edu.cn iburst       #添加一个不可用服务器地址

(2)打开 local stratum 10(当外网时间服务器同步失败时,可以用本地时间来提供时间)

# Serve time even if not synchronized to a time source.
local stratum 10    

在文件下方找到#local stratum 10,把#删掉并保存

(3)进去到客户端的chrony.conf文件目录:vim /etc/chrony.conf

在时间服务器地址池加入阿里云时间服务器地址:server 192.168.153.133  iburst(服务器的地址)

[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).
#pool 2.rhel.pool.ntp.org iburst
server 192.168.153.133 iburst    #服务器的地址

(4)把服务器和客户端的时间服务器都重启一下:systemctl restart chronyd

[root@localhost ~]# systemctl restart chronyd   #服务器
[root@localhost ~]# systemctl restart chronyd   #客户端

(5)查看当前系统时钟是否已同步,ntp服务器是否可用:timedatectl status 

[root@localhost ~]# timedatectl status 
               Local time: Fri 2022-09-23 14:48:48 EDT
           Universal time: Fri 2022-09-23 18:48:48 UTC
                 RTC time: Fri 2022-09-23 18:48:48
                Time zone: America/New_York (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

(6)跟踪当前的同步态:chronyc sources -v

[root@localhost ~]# chronyc sources -v

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current best, '+' = combined, '-' = not combined,
| /             'x' = may be in error, '~' = too variable, '?' = unusable.
||                                                 .- 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               
===============================================================================
^* 192.168.153.133             10   6    37    36    +7655ns[+1019us] +/- 168us

(7)跟踪当前的同步态:chronyc tracking -v

[root@localhost ~]# chronyc tracking -v
Reference ID    : C0A8508D (192.168.153.133)
Stratum         : 11
Ref time (UTC)  : Mon Sep 23 14:53:34 2022
System time     : 0.000029581 seconds fast of NTP time
Last offset     : +0.000031582 seconds
RMS offset      : 0.000959051 seconds
Frequency       : 12.656 ppm slow
Residual freq   : +0.000 ppm
Skew            : 4.522 ppm
Root delay      : 0.000450131 seconds
Root dispersion : 0.000094597 seconds
Update interval : 64.9 seconds
Leap status     : Normal

(8)强制同步:chronyc -a makestep

[root@localhost ~]# chronyc -a makestep 
200 OK

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值