CentOS8时间同步
阅读原文时间:2022年03月17日阅读:6

CentOS8中默认已经不再支持ntpd软件包,同时也无法通过官方软件仓库安装, CentOS8上使用Chrony配置NTP服务器,用于同步时间。 它有两个程序,chrony和chronyd, chronyd是守护进程 ,chrony是一个命令行界面程序,可以用来监控chronyd的性能,并修改各种操作参数。

安装chrony
系统会默认安装并启动,如果系统不存在则需要安装此工具库。

仓库中直接安装

dnf -y install chrony

 启动守护进程

systemctl enable –now chronyd

时间同步配置

设置时区 联网的情况下一般设置时区后会通过网络同步时间

timedatectl set-timezone "Asia/Shanghai"

配置chrony.conf

修改配置加入aliyun pool网络时间,也可以加入多个pool服务器 vim /etc/chrony.conf

# Use public servers from the pool.ntp.org project.

Please consider joining the pool (http://www.pool.ntp.org/join.html).

pool 2.centos.pool.ntp.org iburst

pool ntp.aliyun.com 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

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

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

Specify directory for log files.

logdir /var/log/chrony

Select which information is logged.

#log measurements statistics tracking

重新加载配置

systemctl restart chronyd.service

时间同步

_执行时间同步命令


chronyc sources -v

[root@k8smaster ~]# chronyc sources -v

210 Number of sources = 5

.-- 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

^- ntp5.flashdance.cx 2 6 377 6 +8255us[+8255us] +/- 139ms
^- 185.216.231.25 2 7 13 6 +10ms[ +10ms] +/- 98ms
^- 119.28.206.193 2 6 377 9 +1016us[+1001us] +/- 62ms
^* dns1.synet.edu.cn 2 6 377 8 -1423us[-1438us] +/- 9294us
^+ 203.107.6.88 2 6 377 7 +2107us[+2107us] +/- 17ms

验证查看时间
查看当前系统时间
date

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器