介绍:
-
由于IT系统中,准确的计时非常重要,有很多种原因需要准确计时:
-
在网络传输中,数据包括和日志需要准确的时间戳
-
各种应用程序中,如订单信息,交易信息等 都需要准确的时间戳
-
Linux的两个时钟:
-
硬件时钟RTC (Real Time Clock):即BIOS时钟,也就是我们主板中用电池供电的时钟,是将时间写入到BIOS中,系统断电后时间不会丢失,可以在开机时通过主板程序中进行设置
[root@server ~]# hwclock
2024-11-15 16:16:51.261766+08:00 -
系统时钟 (System Clock) :顾名思义也就是Linux系统内核时钟、软件时钟,是由Linux内核来提供的,系统时钟是基于内存,如果系统断电时间就会丢失
[root@server ~]# date
Fri Nov 15 04:17:40 PM CST 2024
[root@server ~]# date -s 10:00 #设置时间
[root@server ~]# hwclock -s #同步硬件时间
设置日期时间
- timedatectl命令设置:
[root@server ~]# timedatectl
Local time: Sun 2024-11-17 09:54:22 CST #本地时间
Universal time: Sun 2024-11-17 01:54:22 UTC #世界时间
RTC time: Sun 2024-11-17 01:54:22 #硬件时间
Time zone: Asia/Shanghai (CST, +0800) #时区
System clock synchronized: yes #时间是否已经同步
NTP service: active #时间同步服务器已启动
RTC in local TZ: no # no表示硬件时钟设置为协调世界时(UTC),yes表示硬件时钟设置为本地时间- date命令设置:
[root@server ~]# date +"%Y-%m-%d %H:%M:%S" # 格式显示
安装:
# 默认已安装,若需要安装则可执行:
[root@server ~]# yum install chrony -y
[root@server ~]# systemctl start chronyd
[root@server ~]# systemctl enable chronyd
chrony配置文件分析:
[root@se