Debian修改时区及定时同步时间
先查看Debian的默认时区:
root@devops:~# timedatectl
Local time: Fri 2022-11-24 10:13:29 UTC
Universal time: Fri 2022-11-24 10:13:29 UTC
RTC time: Fri 2022-11-24 10:13:29
Time zone: UTC (UTC, +0000)
System clock synchronized: no
NTP service: inactive
RTC in local TZ: no
现在当前是UTC,修改为Asia/Shanghai
root@devops:~# timedatectl set-timezone Asia/Shanghai
查看修改情况:
root@devops:~# timedatectl
Local time: Fri 2022-11-24 10:15:51 CST
Universal time: Fri 2022-11-24 10:15:51 UTC
RTC time: Fri 2022-11-24 10:15:52
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
查看当前所有时区:
root@devops:~# timedatectl list-timezones
安装ntpdate同步工具:
root@devops:~# apt install ntpdate -y
自动同步时间
接下来我们设置让系统每隔60分钟自动更新时间,输入以下命令
root@devops:~# crontab -e
添加定时任务每小时同步一次:
*/60 * * * * /usr/sbin/ntpdate pool.ntp.org
如果ntp服务在运行的时候,直接运行ntpdate可能会报错,直接停掉ntpd服务即可
root@devops:~# systemctl stop ntp
root@devops:~# systemctl disable ntp
Synchronizing state of ntp.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable ntp
Removed /etc/systemd/system/multi-user.target.wants/ntp.service.
Tag标签:「时区 ntp debian」更新时间:「2022-11-25 10:06:32」阅读次数:「1458」