时间同步出错

前沿拓展:

时间同步出错

Windows与Internet时间同步不上,大致有两种状况: 争历沿粒鲁房消1、在获取最近一次同过Windows XP中内置的Internet连接防火墙除外。 如果以上两种方法还没有解决,将“自动与 Internet 时间


打开虚拟机进入AlmaLinux,使用 dnf install mysql安装mysql数据库,突然弹出如下所示的错误:

# dnf module list mysql
AlmaLinux 8 – BaseOS 0.0 B/s | 0 B 00:10
Errors during downloading metadata for repository 'baseos':
– Curl error (60): Peer certificate cannot be authenticated with given CA certificates for https://mirrors.almalinux.org/mirrorlist/8/baseos [SSL certificate problem: certificate is not yet valid]
Error: Failed to download metadata for repo 'baseos': Cannot prepare internal mirrorlist: Curl error (60): Peer certificate cannot be authenticated with given CA certificates for https://mirrors.almalinux.org/mirrorlist/8/baseos [SSL certificate problem: certificate is not yet valid]

顿时蒙了,使用ping检查一下网络,一切正常,哪里出错了呢?只能搜索一下,可能是虚拟机的系统时间不对导致的。可能是因为虚拟机没有电池,无法记住时间,因此需要同步时间,centos8 和 rocky linux 8 默认不带ntpdate,可以使用chrony进行时间同步,chrony也是一个ntp协议的实现,默认安装。

时间同步出错

第一使用 timedatectl 查询一下系统时钟。

timedatectl命令可以查询和更改系统时钟和设置,你可以使用此命令来设置或更改当前的日期,时间和时区,或实现与远程NTP服务器的自动系统时钟同步。

# timedatectl
Warning: The system is configured to read the RTC time in the local time zone.

This mode cannot be fully supported. It will create various problems

with time zone changes and daylight saving time adjustments. The RTC

time is never updated, it relies on external facilities to maintain it.

If at all possible, use RTC in UTC by calling

'timedatectl set-local-rtc 0'.
// 关闭硬件时钟校准
# timedatectl set-local-rtc 0

根据输出结果,系统启用了硬件校准时间,可是虚拟机没有硬件时钟,根据提示输入命令 timedatectl set-local-rtc 0 关闭硬件校准时间。

再次运行 timedatectl,输出结果中的 RTC in local TZ: no 表示硬件时钟已经关闭。

# timedatectl
Local time: Sat 2022-11-26 05:17:00 EST
Universal time: Sat 2022-11-26 10:17:00 UTC
RTC time: Sat 2022-11-26 10:17:00
Time zone: America/New_York (EST, -0500)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no

如果输出结果中的NTP service服务处于不活动状态,那么可以使用下面的命令激活它

timedatectl set-ntp true

此时运行 dnf install mysql 应该正常了,如果不正常,那么重启chrony服务或者等一会。

chrony是一个ntp协议的实现程序,既可以当做服务端,也可以充当客户端;它专为间歇性互联网连接的系统而设计,当然也能良好应用于持久互联网连接的环境;chrony有三个时间参考:硬件时钟、实时时钟以及手动同步。

RHEL7中默认使用chrony作为时间服务器,也支持NTP,需要额外安装。NTP与chrony不能同时存在,只能用其中一个,并将另一个mask掉。

还可以在chrony配置文件中添加 阿里云和国家授时中心,这样校时更快。

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.pool.ntp.org iburst
//添加阿里云和国家授时中心
server ntp.aliyun.com iburst
server ntp.ntsc.ac.cn iburst

重启服务

systemctl restart chronyd

查看服务

# chronyc sourcestats -v

使用timedatectl还可以将时区设置为亚洲上海。

timedatectl set-timezone Asia/Shanghai

拓展知识:

前沿拓展:

时间同步出错

Windows与Internet时间同步不上,大致有两种状况: 争历沿粒鲁房消1、在获取最近一次同过Windows XP中内置的Internet连接防火墙除外。 如果以上两种方法还没有解决,将“自动与 Internet 时间


打开虚拟机进入AlmaLinux,使用 dnf install mysql安装mysql数据库,突然弹出如下所示的错误:

# dnf module list mysql
AlmaLinux 8 – BaseOS 0.0 B/s | 0 B 00:10
Errors during downloading metadata for repository 'baseos':
– Curl error (60): Peer certificate cannot be authenticated with given CA certificates for https://mirrors.almalinux.org/mirrorlist/8/baseos [SSL certificate problem: certificate is not yet valid]
Error: Failed to download metadata for repo 'baseos': Cannot prepare internal mirrorlist: Curl error (60): Peer certificate cannot be authenticated with given CA certificates for https://mirrors.almalinux.org/mirrorlist/8/baseos [SSL certificate problem: certificate is not yet valid]

顿时蒙了,使用ping检查一下网络,一切正常,哪里出错了呢?只能搜索一下,可能是虚拟机的系统时间不对导致的。可能是因为虚拟机没有电池,无法记住时间,因此需要同步时间,centos8 和 rocky linux 8 默认不带ntpdate,可以使用chrony进行时间同步,chrony也是一个ntp协议的实现,默认安装。

时间同步出错

第一使用 timedatectl 查询一下系统时钟。

timedatectl命令可以查询和更改系统时钟和设置,你可以使用此命令来设置或更改当前的日期,时间和时区,或实现与远程NTP服务器的自动系统时钟同步。

# timedatectl
Warning: The system is configured to read the RTC time in the local time zone.

This mode cannot be fully supported. It will create various problems

with time zone changes and daylight saving time adjustments. The RTC

time is never updated, it relies on external facilities to maintain it.

If at all possible, use RTC in UTC by calling

'timedatectl set-local-rtc 0'.
// 关闭硬件时钟校准
# timedatectl set-local-rtc 0

根据输出结果,系统启用了硬件校准时间,可是虚拟机没有硬件时钟,根据提示输入命令 timedatectl set-local-rtc 0 关闭硬件校准时间。

再次运行 timedatectl,输出结果中的 RTC in local TZ: no 表示硬件时钟已经关闭。

# timedatectl
Local time: Sat 2022-11-26 05:17:00 EST
Universal time: Sat 2022-11-26 10:17:00 UTC
RTC time: Sat 2022-11-26 10:17:00
Time zone: America/New_York (EST, -0500)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no

如果输出结果中的NTP service服务处于不活动状态,那么可以使用下面的命令激活它

timedatectl set-ntp true

此时运行 dnf install mysql 应该正常了,如果不正常,那么重启chrony服务或者等一会。

chrony是一个ntp协议的实现程序,既可以当做服务端,也可以充当客户端;它专为间歇性互联网连接的系统而设计,当然也能良好应用于持久互联网连接的环境;chrony有三个时间参考:硬件时钟、实时时钟以及手动同步。

RHEL7中默认使用chrony作为时间服务器,也支持NTP,需要额外安装。NTP与chrony不能同时存在,只能用其中一个,并将另一个mask掉。

还可以在chrony配置文件中添加 阿里云和国家授时中心,这样校时更快。

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.pool.ntp.org iburst
//添加阿里云和国家授时中心
server ntp.aliyun.com iburst
server ntp.ntsc.ac.cn iburst

重启服务

systemctl restart chronyd

查看服务

# chronyc sourcestats -v

使用timedatectl还可以将时区设置为亚洲上海。

timedatectl set-timezone Asia/Shanghai

拓展知识:

原创文章,作者:九贤生活小编,如若转载,请注明出处:http://www.wangguangwei.com/56246.html