CentOS时钟同步服务器

时间:2023-03-09 16:33:43
CentOS时钟同步服务器

①本地时钟服务器需要安装chrony服务,可以通过yum、rpm、源码包安装,chrony支持C/S模式

②编辑本地时钟服务,使其指向提供标准时间服务器,例如:中国国家授时中心NTP服务器。

修改配置文件/etc/chrony.conf,

server 210.72.145.44 iburst   (210.72.145.44为中国国家授时中心NTP服务器,可以填写域名)

allow 管理网络网段ip/24

并重启服务,systemctl restart chronyd.service

③通过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

||                                                /   xxxx = adjusted offset,

||         Log2(Polling interval) -.             |    yyyy = measured offset,

||                                  \            |    zzzz = estimated error.

||                                   |           |                         

MS Name/IP address         Stratum Poll Reach LastRx Last sample

===============================================================================

^? 210.72.145.44                 0   6     0   10y     +0ns[   +0ns] +/-    0ns

④编辑本地其他服务器,使其时钟同步与本地时钟服务器

vim /etc/chrony.conf

server 控制节点ip iburst

⑤查看本地时区

timedatectl status

⑥修改本地时区和时间

timedatectl set-local-rtc 1 # 将硬件时钟调整为与本地时钟一致, 0 为设置为 UTC 时间

timedatectl set-timezone Asia/Shanghai # 设置系统时区为上海

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime