Linux
时间同步服务 - chronyd
安装
使用软件包安装工具安装chrony
和ntp
:
-
Arch Linux
系列:sudo pacman -S ntp chrony
-
Debian
系列:sudo apt install ntp chrony
-
Red Hat
系列:sudo yum install ntp chrony
或者
sudo dnf install ntp chrony
配置
① 在chrony
配置文件中,将原授时NTP
服务器注释,并填入阿里或腾讯NTP
授时服务器网址,示例如下:
### SPECIFY YOUR NTP SERVERS
# Most computers using chrony will send measurement requests to one or
# more 'NTP servers'. You will probably find that your Internet Service
# Provider or company have one or more NTP servers that you can specify.
# Failing that, there are a lot of public NTP servers. There is a list
# you can access at http://support.ntp.org/bin/view/Servers/WebHome or
# you can use servers from the pool.ntp.org project.
#! server 0.arch.pool.ntp.org iburst
#! server 1.arch.pool.ntp.org iburst
#! server 3.arch.pool.ntp.org iburst
#pool 2.arch.pool.ntp.org iburst
# The URL of Tencent NTP network time server is as follows:
! server ntp.tencent.com iburst
! server ntp2.tencent.com iburst
! server ntp3.tencent.com iburst
! server ntp4.tencent.com iburst
! server ntp5.tencent.com iburst
# The URL of Ali NTP network time server is as follows:
! server ntp.aliyun.com iburst
! server ntp1.aliyun.com iburst
! server ntp2.aliyun.com iburst
! server ntp3.aliyun.com iburst
! server ntp4.aliyun.com iburst
! server ntp5.aliyun.com iburst
! server ntp6.aliyun.com iburst
! server ntp7.aliyun.com iburst
pool ntp1.tencent.com
注意:
选择其中三、四个即可。
② 输入如下命令,使得防火墙为chronyd
服务放行,以便chronyd
服务顺利运行:
-
Firewalld
设置:$ firewall-cmd --add-service=ntp --permanent $ firewall-cmd --reload
-
Ufw
设置:$ sudo ufw allow ntp $ sudo ufw allow out ntp
管理
使用systemctl
命令允许chronyd
服务开机自启动、使得chronyd
服务启动并查看chronyd
服务的运行状态,具体命令如下所示:
# systemctl start chronyd.service #启动
# systemctl status chronyd.service #查看
# systemctl enable chronyd.service #设置开机启动
使用如下命令,查看时间同步源:
$ chronyc sources -v
使用如下命令,查看时间同步源状态:
$ chronyc sourcestats -v
使用如下命令,启用NTP时间同步:
$ timedatectl set-ntp yes
使用如下命令,校准时间服务器:
$ chronyc tracking
注意:
配置完
/etc/chrony.conf
后,需重启chrony
服务,否则可能会不生效。