在 Debian 系统中设置时间戳通常涉及以下步骤:
查看当前时间:
date
手动设置系统时间:
sudo date -s "YYYY-MM-DD HH:MM:SS"
设置为本地时间或 UTC:
sudo timedatectl set-local-rtc 1
sudo timedatectl set-local-rtc 0
同步系统时间到硬件时钟:
sudo timedatectl set-time 'YYYY-MM-DD HH:MM:SS' --systohc
从硬件时钟读取时间并设置系统时间:
sudo hwclock --hctosys
查看可用时区:
timedatectl list-timezones
设置时区:
sudo timedatectl set-timezone Your/Time_Zone
手动设置时区(不推荐):
/etc/timezone
文件:sudo nano /etc/timezone
Europe/Paris
systemd-timesyncd
服务:sudo systemctl restart systemd-timesyncd
安装 NTP:
sudo apt-get install ntp
配置 NTP:
/etc/ntp.conf
文件,添加或修改 NTP 服务器地址:server time.nist.gov iburst
重启 NTP 服务:
sudo systemctl restart ntp
验证时间同步:
sudo ntpq -p
使用 systemd-timesyncd 进行时间同步(Debian 10 及以上版本):
/etc/systemd/timesyncd.conf
文件:sudo nano /etc/systemd/timesyncd.conf
[Time]
NTP=10.3.170.32
FallbackNTP=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org
systemd-timesyncd
服务:sudo systemctl restart systemd-timesyncd
验证时间同步:
timedatectl status
通过以上步骤,您可以在 Debian 系统中设置和配置时间戳,确保系统时间的准确性和同步性。