debian 系统安装配置chrony


参考网址 : https://techviewleo.com/how-to-configure-chrony-ntp-server-on-debian/

timedatectl 命令管理系统时间

在Debian 11 | 10系统上,可以使用timedatectl命令获取有关系统时钟及其设置的信息,以及启用和停止时间同步服务。
它具有以下语法:

timedatectl [OPTIONS…] {COMMAND}

直接使用timedatectl 有如下的输出

$ timedatectl
               Local time: Wed 2022-01-12 04:27:05 EST
           Universal time: Wed 2022-01-12 09:27:05 UTC
                 RTC time: Wed 2022-01-12 09:27:06
                Time zone: Asia/Shanghai (EST, +0800)
System clock synchronized: yes
              NTP service: inactive
          RTC in local TZ: no

使用timedatectl 设置时间和日期

sudo timedatectl set-time '2022-01-12 12:55:00'

列出所有可用的时区

$ timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Algiers
Africa/Bissau
Africa/Cairo
Africa/Casablanca
Africa/Ceuta
Africa/El_Aaiun
Africa/Johannesburg
Africa/Juba
Africa/Khartoum
Africa/Lagos
Africa/Maputo
Africa/Monrovia
Africa/Nairobi
Africa/Ndjamena
Africa/Sao_Tome
Africa/Tripoli
....

设定系统时区为Asia/Shanghai

sudo timedatectl set-timezone Asia/Shanghai

在debian 系统上安装 chrony

sudo apt update
sudo apt install chrony

启动chrony程序以及设置开机启动

sudo systemctl start chronyd
sudo systemctl enable chronyd

在debian 系统上配置chrony, 配置文件位置 /etc/chrony/chrony.conf

配置文件内容

# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usable directives.

# Include configuration files found in /etc/chrony/conf.d.
confdir /etc/chrony/conf.d

# Use Debian vendor zone.
# pool 2.debian.pool.ntp.org iburst
server ntp1.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp2.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp3.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp4.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp5.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp6.aliyun.com minpoll 4 maxpoll 10 iburst
# Use time sources from DHCP.
sourcedir /run/chrony-dhcp

# Use NTP sources found in /etc/chrony/sources.d.
sourcedir /etc/chrony/sources.d

# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys

其中pool 2.debian.pool.ntp.org iburst 是系统默认的
下方这些是针对国内服务器添加的,添加后可以重启chrony systemctl restart chronyd
server ntp1.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp2.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp3.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp4.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp5.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp6.aliyun.com minpoll 4 maxpoll 10 iburst

chrony服务的一些命令

chronyc sources -v #查看源时间服务器
chronyc tracking #查看chrony程序的时钟信息
chronyc sourcestats # 查看时间服务器统计