Linux 服务器时间跟踪配置 选项 |
值 |
描述 |
/etc/sysconfig/clock |
UTC |
指定时区 |
timedatectl set-local-rtc 1 |
|
将本地 RTC 设置为 UTC |
timedatectl set-ntp true |
|
启用 NTP |
systemctl enable ntpd |
|
在系统启动时启用 NTP |
systemctl start ntpd |
|
启动 NTP 服务 |
chronyc sources |
|
显示 NTP 源 |
Linux 服务器时间跟踪配置
在 Linux 服务器上,准确的时间跟踪对于许多任务至关重要,例如日志记录、安全、监控和自动化。
本文档介绍了在 Linux 服务器上配置时间跟踪的步骤。
配置时区
第一步是配置正确的时区。
这可以在 /etc/sysconfig/clock 文件中完成。
例如,要将时区设置为 UTC,可以使用以下命令:
sudo vi /etc/sysconfig/clock
ZONE="UTC"
保存并关闭文件。
同步本地 RTC
接下来,需要将本地实时时钟 (RTC) 与系统时钟同步。
这确保服务器启动时本地 RTC 已正确设置。
要执行此操作,请使用以下命令:
timedatectl set-local-rtc 1
启用 NTP
网络时间协议 (NTP) 用于从时间服务器同步系统时间。
在 Linux 上,NTP 服务由 ntpd 守护进程管理。
要启用 NTP,请使用以下命令:
timedatectl set-ntp true
在启动时启用 NTP 服务
为了确保 NTP 服务在系统启动时自动启动,请使用以下命令:
systemctl enable ntpd
启动 NTP 服务
最后,使用以下命令启动 NTP 服务:
systemctl start ntpd
验证配置
要验证 NTP 配置,请使用以下命令:
chronyc sources
这将显示 NTP 源列表及其状态。