NTP配置

Chrony时间同步服务

chrony 与 ntp 一样,既可以做服务端,也可以做客户端。

使用的是 UDP 协议。

兼容以前的 ntp服务,所以本地会启动两个UDP端口。

ntp服务端口,123

chrony服务端口,323

服务端配置

修改 /etc/chrony.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
# 配置当前服务器向指定NTP服务器同步时间,例如这里先向11.1.36.1同步时间
server 11.1.36.1 iburst

服务端需要把下面的allow内容打开,并做适当配置。
# Allow NTP client access from local network.
#allow 192.168.0.0/16

#如果上面使用server字段配置的时间服务器同步时间失败,默认情况下当前时间服务器是不会向客户端同步时间的,
#这是因为担心当前节点的时间不准确(因为当前节点没有和定义中的server时间服务器进行同步),如果我们想要在
#server指定的时间服务器同步失败的情况下依旧返回当前时间服务器的时间给客户端,需要开启该参数,这一项参
#数配置在生产环境中还是相当危险的,因此建议大家在server字段中指定互联网的网络时间,否则可能会出现整个
#集群时间都错的的一致!
local stratum 10

客户端配置

修改 /etc/chrony.conf

1
server 11.1.36.1 iburst

重点修改这部分,可以多行,多个NTP服务地址。

server NTP服务端 iburst

启动 chronyd 服务

1
systemctl restart chronyd

查看服务状态

1
systemctl status chronyd

查看同步

1
chronyc sources -v

样例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@test-mysql5 ~]# 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
===============================================================================
^* 11.1.36.1 1 6 377 125 +5239ns[-1566ns] +/- 744us

通过 -v 可以得知,^* 表示当前的时间服务器同步成功

手动同步

1
2
3
4
5
# 手动同步系统时间
chronyc -a makestep

# 查看时间同步源
chronyc sources -v

参考链接

https://www.cnblogs.com/yinzhengjie/p/12292549.html


补充

设置系统时区和时间

1
2
3
4
5
6
7
8
9
[root@test-mysql5 ~]# timedatectl 
Local time: Thu 2023-07-20 17:02:41 CST
Universal time: Thu 2023-07-20 09:02:41 UTC
RTC time: Thu 2023-07-20 09:03:02
Time zone: n/a (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

查看上海时区

1
2
[root@test-mysql5 ~]# timedatectl list-timezones |grep -E "Asia/Shang*"
Asia/Shanghai

设置系统时区为上海

1
[root@test-mysql5 ~]# timedatectl set-timezone "Asia/Shanghai"

帮助信息

1
[root@test-mysql5 ~]# timedatectl --help
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2022-2023 ligongzhao
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~

支付宝
微信