中午正吃饭,客户打来电话,有个数据库时间和北京时间相差10多分钟了,影响到同步任务,赶紧赶回到电脑边查看,该机器是台虚拟机,操作系统是oracle linux 7.9。
1、定时任务中有时间同步的,且cron日志一直有显示执行,但机器时间和北京时间相差10多分钟。
2、因业务紧急,直接手动执行命令,同步成功
3、/var/log/message中没有任何关于时间同步的信息。客户查看云平台时间都和北京时间一致,赶紧安抚客户,不再使用ntpdate方式,修改成chrony了
[root@xgfwdb ~]#yum -y install chrony
[root@xgfwdb ~]#systemctl enable chronyd
[root@xgfwdb ~]#systemctl start chronyd
[root@xgfwdb ~]#systemctl status chronyd
编辑/etc/chrony.conf文件,增加以下时间源
server 192.168.100.250 iburst
[root@xgfwdb ~]#systemctl restart chronyd
[root@xgfwdb ~]#timedatectl status # 查看时间同步状态
[root@xgfwdb ~]#timedatectl set-ntp true # 开启网络时间同步
[root@xgfwdb ~]# chronyc sources -v
210 Number of sources = 2
.-- 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
===========================================================================
^? bogon 0 9 0 - +0ns[ +0ns] +/- 0ns
^* 192.168.100.250 4 8 377 274 +307us[ +506us] +/- 51ms
rpm -qa | grep chrony
systemctl is-enable chronyd
systemctl enable chronyd --- 开机自启动
systemctl start chronyd --- 启动
systemctl restart chronyd
server 172.23.11.240 iburst
时钟配置-linux8-linux 8
yum -y install chrony
cp /etc/chrony.conf /etc/chrony.conf.bak
echo ' ' >> /etc/chrony.conf
echo 'server 59.78.109.11 iburst' >> /etc/chrony.conf
echo 'server 202.120.111.3 iburst' >> /etc/chrony.conf
echo 'server 202.120.111.30 iburst' >> /etc/chrony.conf
systemctl restart chronyd && systemctl enable chronyd
chronyc tracking
hwclock --systohc; hwclock -w;date;hwclock
chronyc 命令
查看ntp时钟源 #chronyc sources -v 或者