建立企业内部时间同步服务器为其他主机提供时间同步服务

image-20210102233751517
  • centos8 10.0.0.8 ntp/chrony server
  • centos7 10.0.0.7 other server

chrony server 10.0.0.8 启动chronyd服务

root@8  ~]# systemctl enable --now chronyd
root@8  ~]# systemctl is-active chronyd.service
active
root@8  ~]# systemctl is-enabled chronyd.service
enabled

chrony server 10.0.0.8 修改配置文件

root@8  ~]# awk '!/^(#|$)/{print}' /etc/chrony.conf
pool ntp1.aliyun.com iburst
pool ntp2.aliyun.com iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
allow 10.0.0.0/24   #允许该网段同步时间服务
#allow 0.0.0.0/0 #如果想为所有机器提供同步服务 需要设置0.0.0.0/0
keyfile /etc/chrony.keys
leapsectz right/UTC
logdir /var/log/chrony

root@8  ~]# systemctl restart chronyd

root@8  ~]# ss -lnu|awk '{print}'
State     Recv-Q    Send-Q       Local Address:Port        Peer Address:Port
UNCONN    0         0                 10.0.0.8:53               0.0.0.0:*
UNCONN    0         0                127.0.0.1:53               0.0.0.0:*
UNCONN    0         0                  0.0.0.0:123              0.0.0.0:*
UNCONN    0         0                127.0.0.1:323              0.0.0.0:*
UNCONN    0         0                127.0.0.1:323              0.0.0.0:*
UNCONN    0         0                    [::1]:53                  [::]:*
UNCONN    0         0                    [::1]:323                 [::]:*
UNCONN    0         0                    [::1]:323                 [::]:*
#修改配置文件后 重启服务
#123/udp端口是10.0.0.8作为服务端提供时间同步服务给其他公司内部服务器的
#323/udp端口是10.0.0.8作为客户端与阿里云同步的

other server 10.0.0.7故意修改错误时间 进行时间同步

root@7  ~]# yum -y install chrony
root@7  ~]# systemctl enable --now chronyd

root@7  ~]# date
Sat Jan  2 23:50:37 CST 2021
root@7  ~]# date -s '1day'
Sun Jan  3 23:50:43 CST 2021
root@7  ~]# date
Sun Jan  3 23:50:48 CST 2021

root@7  ~]# sed -r '/^(#|$)/d' /etc/chrony.conf
server 10.0.0.8 iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
logdir /var/log/chrony

root@7  ~]# systemctl restart chronyd

root@7  ~]# 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
===============================================================================
^* 10.0.0.8                      3   6    17     1  -3454ns[ +288us] +/-   23ms

root@7  ~]# date
Sat Jan  2 23:51:31 CST 2021

你可能感兴趣的:(建立企业内部时间同步服务器为其他主机提供时间同步服务)