CentOS8时间同步

CentOS8时间同步

概述

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

安装chrony

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

  • 仓库中直接安装
1
dnf -y install chrony
  • 启动守护进程
1
systemctl enable –now chronyd

时间同步配置

设置时区

  • 联网的情况下一般设置时区后会通过网络同步时间
1
timedatectl set-timezone "Asia/Shanghai"

配置chrony.conf

  • 修改配置加入aliyun pool网络时间,也可以加入多个pool服务器

    1
    vim /etc/chrony.conf
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    ># 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
    >
  • 重新加载配置

    1
    systemctl restart chronyd.service

时间同步

  • 执行时间同步命令

    1
    chronyc sources -v
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    >[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
    >

查看时间

  • 查看当前系统时间

    1
    date
------本文结束感谢您的阅读------
坚持原创技术分享,您的支持将鼓励我继续创作!
0%