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服务,否则可能会不生效。
本文详细介绍如何在Linux系统上安装并配置chronyd服务,包括使用包管理器安装,修改NTP服务器地址,配置防火墙,以及设置chronyd开机自启动和时间同步操作。重点介绍了如何添加阿里和腾讯NTP服务器,并提供相关命令实例。

598

被折叠的 条评论
为什么被折叠?



