概述
随着大数据的飞速发展,服务器集群化,时间同步显得和外重要,不允许有任何差错。
最近发现CentOS8 已经不在支持ntpd软件包, 同时也无法通过官方软件仓库安装, CentOS8上使用Chrony配置NTP服务器,用于同步时间。 它有两个程序,chrony和chronyd, chronyd是守护进程 ,chrony是一个命令行界面程序,可以用来监控chronyd的性能,并修改各种操作参数。
软件包安装
系统自动已经安装,则不需安装
从仓库中直接安装
dnf install chrony -y
启动chrony
systemctl start chronyd.service && systemctl enable chronyd.service
查看是否启动成功
systemctl status chronyd.service
设置时间同步
设置时区 (这步很重要,把时区改成当地时区 )
timedatectl set-timezone "Asia/Shanghai"
编辑配置文件(使系统同步阿里云的时间)
vi /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 注释掉
server ntp.aliyun.com iburst 新增行
server cn.ntp.org.cn iburst 新增行
重启服务
systemctl restart chronyd.service
时间同步
执行时间同步命令
[root@wang ~]# chronyc sources -v
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current best, '+' = combined, '-' = not combined,
| / 'x' = may be in error, '~' = too variable, '?' = unusable.
|| .- 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
===============================================================================
^- 203.107.6.88 2 6 37 13 -8096us[-8096us] +/- 24ms
^* 111.230.50.201 3 6 37 13 +17us[+4642us] +/- 61ms
验证时间
查看当前系统时间
date