chronyd时间同步服务

CentOS7.6 chrony配置

CentOS7.6默认安装了chrony保持系统时间与时间服务器(NTP)同步。在内网中,我们需要搭建一台时钟服务器用于统一内网的系统时间。

服务端配置

​ 进入chrony配置文件

1
2
3
4
5
6
7
8
9
[root@appsrv ~]# vim /etc/chrony.conf 
修改如下几行

24 # Allow NTP client access from local network.
25 allow all 允许的主机
26
27 local 不管自己的时间和NTP服务器对不对得上都把自己的时间发布给客服端
28 # Serve time even if not synchronized to a time source.
29 local stratum 10

点击并拖拽以移动

​ 重启chronyd服务

1
[root@appsrv ~]# systemctl restart chronyd

点击并拖拽以移动

客服端配置

​ 进入chrony配置文件

1
2
3
4
5
6
7
[root@storagesrv ~]# vim /etc/chrony.conf 

3 #server 0.centos.pool.ntp.org iburst
4 #server 1.centos.pool.ntp.org iburst
5 #server 2.centos.pool.ntp.org iburst
6 #server 3.centos.pool.ntp.org iburst
7 server 192.168.100.100 iburst 设置ntp服务器为服务端

点击并拖拽以移动

1
2
[root@storagesrv ~]# systemctl restart chronyd
[root@storagesrv ~]# timedatectl set-ntp yes

点击并拖拽以移动

​ 配置crontab(计时器)每5分钟同步一次时间。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@storagesrv ~]# vim /etc/crontab 

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
*/5 * * * * ntpdate 192.168.100.100

/usr/shin/ntpdate 是执行的命令
192.168.100.100 是ntpdate的参数

点击并拖拽以移动

查看服务器端连接的客户端状态信息

1
[root@appsrv ~]# chronyc clients

点击并拖拽以移动

查看客户端状态信息

1
2
3
[root@storagesrv ~]# timedatectl set-ntp yes
[root@storagesrv ~]# date
Wed Feb 21 23:57:02 CST 2024

点击并拖拽以移动