1、服务器端Centos Linux 8.1 默认安装了chronyd服务。我们只需要配置即可。 配置文件配置 红色部分是需要服务器配置的,这是基本配置,主要在于实现基本功能。
# Use public servers from the pool. project. # Please consider joining the pool (http://www.pool./join.html). # pool 2.centos.pool. iburst # 同步哪台服务器上的时间 server 192.168.94.133 iburst # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Allow NTP client access from local network. # allow 192.168.0.0/16 # 允许哪个网段的客户端同步时间,133这台是服务器。 allow 192.168.94.0/24 # Serve time even if not synchronized to a time source. # 字面翻译,提供时间即使没有同步一个时间源。 local stratum 10 # Specify file containing keys for NTP authentication. keyfile /etc/chrony.keys # Get TAI-UTC offset and leap seconds from the system tz database. leapsectz right/UTC 启动chronyd,并设置开机自启 [root@filesystem ~]# systemctl start chronyd [root@filesystem ~]# systemctl enable chronyd 查看时间同步情况,本地能够同步才能够让其他节点进行同步 timedatectl是一个时间配置工具,用于设定时间、与时间相关的配置等。 [root@filesystem ~]# timedatectl Local time: 五 2020-05-29 11:17:46 EDT Universal time: 五 2020-05-29 15:17:46 UTC RTC time: 五 2020-05-29 15:17:46 Time zone: America/New_York (EDT, -0400) # 当此值为yes代表同步成功,如果为no就代表未同步,或同步失败。 System clock synchronized: yes NTP service: active RTC in local TZ: no [root@filesystem ~]# 查看当前时间是从哪里同步过来的,这里显示的是主机名。不影响。 [root@filesystem ~]# chronyc sources 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* filesystem 10 7 377 537 +11us[ +25us] +/- 30us [root@filesystem ~]# 防火墙配置
2、客户端配置配置文件配置
# Use public servers from the pool. project. # Please consider joining the pool (http://www.pool./join.html). # pool 2.centos.pool. iburst server 192.168.94.133 iburst 配置开机自启 [root@node1 ~]# systemctl restart chronyd [root@node1 ~]# systemctl enable chronyd [root@node1 ~]# 查看同步状态及信息 [root@node1 ~]# timedatectl Local time: 五 2020-05-29 11:28:12 EDT Universal time: 五 2020-05-29 15:28:12 UTC RTC time: 五 2020-05-29 15:28:12 Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no [root@node1 ~]# chronyc sources 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* filesystem 11 6 17 34 -520ns[+7955ns] +/- 15ms [root@node1 ~]# 我们看到是yes,但是如何判断它是原来的时间还是同步好了。毕竟很多系统不同步时间也是近似的。 3、设置时间我们对chronyd服务器端进行时间修改。 这里说明一点,时间的修改只能在时间不进行同步的状态下进行,也就是说,如果时间是同步中的,是不允许修改时间的。对时间进行保护。 [root@filesystem ~]# timedatectl Local time: 五 2020-05-29 11:30:40 EDT Universal time: 五 2020-05-29 15:30:40 UTC RTC time: 五 2020-05-29 15:30:40 Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no [root@filesystem ~]# 我们测试效果,关掉ntp,修改时间
[root@filesystem ~]# timedatectl set-ntp 0 [root@filesystem ~]# timedatectl set-time "2020-06-01 01:01:01" [root@filesystem ~]# timedatectl set-ntp 1 [root@filesystem ~]# systemctl restart chronyd [root@filesystem ~]# timedatectl Local time: 一 2020-06-01 01:01:20 EDT Universal time: 一 2020-06-01 05:01:20 UTC RTC time: 一 2020-06-01 05:01:20 Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no [root@filesystem ~]# 客户端查看时间 [root@node1 ~]# systemctl restart chronyd [root@node1 ~]# [root@node1 ~]# timedatectl Local time: 一 2020-06-01 01:01:55 EDT Universal time: 一 2020-06-01 05:01:55 UTC RTC time: 五 2020-05-29 15:46:52 Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no [root@node1 ~]# 客户端不重启服务也是能同步的,如果你下去做实验的话,可以测试下。 读书和健身总有一个在路上 |
|