Linux
Servicio de sincronización horaria -chronyd
Instalar
Utilice la herramienta de instalación de paquetes para instalar chrony
y ntp
:
-
Arch Linux
serie:sudo pacman -S ntp chrony
-
Debian
serie:sudo apt install ntp chrony
-
Red Hat
serie:sudo yum install ntp chrony
o
sudo dnf install ntp chrony
Configuración
① En chrony
el archivo de configuración, comente el NTP
servidor de sincronización original y complete NTP
la URL del servidor de sincronización Alibaba o Tencent. El ejemplo es el siguiente:
### 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
Aviso:
Simplemente elige tres o cuatro de ellos.
② Ingrese el siguiente comando para permitir que el firewall pase chronyd
el servicio para que chronyd
el servicio pueda ejecutarse sin problemas:
-
Firewalld
configuración:$ firewall-cmd --add-service=ntp --permanent $ firewall-cmd --reload
-
Ufw
configuración:$ sudo ufw allow ntp $ sudo ufw allow out ntp
administrar
Utilice systemctl
comandos para permitir que chronyd
el servicio se inicie automáticamente en el inicio, habilitar chronyd
el servicio para que se inicie y ver chronyd
el estado de ejecución del servicio. Los comandos específicos son los siguientes:
# systemctl start chronyd.service #启动
# systemctl status chronyd.service #查看
# systemctl enable chronyd.service #设置开机启动
Utilice el siguiente comando para ver la fuente de sincronización horaria:
$ chronyc sources -v
Utilice el siguiente comando para verificar el estado de la fuente de sincronización horaria:
$ chronyc sourcestats -v
Utilice el siguiente comando para habilitar la sincronización horaria NTP:
$ timedatectl set-ntp yes
Utilice el siguiente comando para calibrar el servidor de hora:
$ chronyc tracking
Aviso:
Una vez
/etc/chrony.conf
completada ,chrony
es necesario reiniciar el servicio; de lo contrario, es posible que no surta efecto.