安装chrony
[root@localhost ~]# dnf -y install chrony
时间同步
1.设置时区
[root@localhost ~]# timedatectl set-timezone "Asia/Shanghai"
2.配置chrony.conf
添加时间服务器参数:pool ntp.aliyun.com iburst
[root@localhost ~]# 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
保存配置文件.
3.重新加载配置
[root@localhost ~]# systemctl restart chronyd.service
4.时间同步
提示:506 Cannot talk to daemon //需要重新执行上面加载配置
[root@localhost ~]# chronyc sources -v
210 Number of sources = 4
.-- 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
===============================================================================
^? electrode.felixc.at 3 6 3 19 +28ms[ +28ms] +/- 156ms
^* 203.107.6.88 2 6 77 31 -77us[ -809us] +/- 28ms
^- ntp1.flashdance.cx 2 6 77 29 -4879us[-4879us] +/- 189ms
^- ntp7.flashdance.cx 2 6 33 24 -7839us[-7839us] +/- 227ms
5.查看时间
[root@localhost ~]# date
2021年 03月 17日 星期三 15:38:51 CST
其他时间指令
- 查看当前系统时间 date
- 修改当前系统时间 date -s "2021-03-17 00:00:00"
- 查看硬件时间 hwclock --show
- 修改硬件时间 hwclock --set --date "2021-03-17 00:00:00"
- 同步系统时间和硬件时间 hwclock --hctosys
- 保存时钟 clock -w
- 重启系统 reboot