配置时间同步服务

简介: 在Redhat 9.2上,Chrony被用来同步系统时间与NTP服务器。默认情况下,它已在RHEL7/CentOS7中预装。要安装,首先通过`yum -y remove chrony`卸载,然后用`yum -y install chrony`进行安装。安装后,使用`systemctl restart chronyd`重启服务,并用`systemctl enable chronyd`设置开机启动。编辑`/etc/chrony.conf`添加阿里云NTP服务器如`ntp1.aliyun.com`和`ntp2.aliyun.com`以同步时间。使用`chronyc sources -n`确认时间源。

环境
Redhat 9.2

chrony是?络时间协议NTP的实现?式, Chrony是?个开源的?由软件 ,在 RHEL7/CentOS7操作系统已经是默认安装服务,它能保持系统时间与NTP时间服务器的时间 保持同步,让时间始终保持同步。

安装步骤
检查是否安装chrony,我这里已经安装好了,所以我先卸载

[root@admin ~]# rpm -aq| grep chrony
chrony-4.3-1.el9.x86_64
[root@admin ~]# yum -y remove  chrony.x86_64 
正在更新 Subscription Management 软件仓库。
无法读取客户身份


省略。。。。。。。。
已移除:
  chrony-4.3-1.el9.x86_64                                                                                                                                              

完毕!

安装chrony


[root@admin ~]# yum -y install chrony.x86_64   
正在更新 Subscription Management 软件仓库。
无法读取客户身份

本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。

上次元数据过期检查:1 day, 3:22:50 前,执行于 2024年03月17日 星期日 13时48分09秒。
依赖关系解决。

省略。。。。。。。。。。。。

已安装:
  chrony-4.3-1.el9.x86_64                                                                                                                                              

完毕!

重启服务并设置开机自启


[root@admin ~]# systemctl  restart  chronyd
[root@admin ~]# systemctl  status chronyd
● chronyd.service - NTP client/server
     Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; preset: enabled)
     Active: active (running) since Mon 2024-03-18 17:12:04 CST; 9s ago
       Docs: man:chronyd(8)
             man:chrony.conf(5)
    Process: 3261 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
   Main PID: 3263 (chronyd)
      Tasks: 1 (limit: 10804)
     Memory: 1.0M
        CPU: 32ms
     CGroup: /system.slice/chronyd.service
             └─3263 /usr/sbin/chronyd -F 2

3月 18 17:12:04 admin systemd[1]: Starting NTP client/server...
3月 18 17:12:04 admin chronyd[3263]: chronyd version 4.3 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +NTS +SECHASH +IPV6 +DEBUG)
3月 18 17:12:04 admin chronyd[3263]: Initial frequency -10.777 ppm
3月 18 17:12:04 admin chronyd[3263]: Using right/UTC timezone to obtain leap second data
3月 18 17:12:04 admin chronyd[3263]: Loaded seccomp filter (level 2)
3月 18 17:12:04 admin systemd[1]: Started NTP client/server.
3月 18 17:12:09 admin chronyd[3263]: Selected source 202.112.29.82 (2.rhel.pool.ntp.org)
3月 18 17:12:09 admin chronyd[3263]: System clock TAI offset set to 37 seconds
[root@admin ~]# systemctl enable chronyd

打开配置文件设置阿里云的时间同步服务,我们连网就可以自动同步上公共时间

在这个文件中,有两种不同的方法可以找到指定的NTP服务器。

第一个是 “server “指令。这个指令允许你指定你想同步时间的各个NTP服务器。

你也可以用它来指定多个NTP服务器。Chrony软件会自动选择最好的一个。

另一种方法是使用 “pool “指令。你对解析到多个地址的域名使用这个指令。


[root@admin ~]# vim /etc/chrony.conf 
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
pool 2.rhel.pool.ntp.org iburst
server ntp1.aliyun.com iburst  //增加的阿里云NTP服务
server ntp2.aliyun.com iburst   //增加的阿里云NTP服务

# Use NTP servers from DHCP.
sourcedir /run/chrony-dhcp

# 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

# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# Allow NTP client access from local network.
#allow 192.168.0.0/16

# Serve time even if not synchronized to a time source.
#local stratum 10
省略。。。。

查看时间同步源


[root@admin ~]#  chronyc sources -n
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^- dns1.synet.edu.cn             1   6    37    26   +286us[ +286us] +/-   28ms
^- stratum2-1.ntp.mow01.ru.>     2   6    37    26    +36ms[  +36ms] +/-  188ms
^- ntp7.flashdance.cx            2   6    37    26    -16ms[  -16ms] +/-  194ms
^- 139.199.214.202               2   6    37    27  -4527us[-4527us] +/-   61ms
^- 120.25.115.20                 2   6    51    20  -3612us[-3612us] +/-   33ms
^* 203.107.6.88                  2   6    37    29    -95us[-8069us] +/-   36ms
[root@admin ~]#
目录
相关文章
|
网络协议 Linux 数据安全/隐私保护
|
11月前
|
Linux 网络安全
配置Linux服务器时间同步
配置Linux服务器时间同步
配置Linux服务器时间同步
http://www.vxiaotou.com