centos 9 时间同步服务

在 CentOS 9 中,默认的时间同步服务是 chrony,而不是传统的 ntpd。 因此,建议使用 chrony 来配置和管理时间同步。 以下是使用 chrony 配置 NTP 服务的步骤:

  1. 安装 chrony

首先,确保系统已安装 chrony。 在 CentOS 9 中,chrony 通常已预安装。 如果未安装,可以使用以下命令进行安装:

bash 复制代码
sudo dnf install -y chrony
  1. 启动并启用 chronyd 服务

安装完成后,启动 chronyd 服务,并设置为开机自启:

bash 复制代码
sudo systemctl enable --now chronyd
  1. 配置 NTP 服务器

编辑 /etc/chrony.conf 配置文件,添加或修改 NTP 服务器地址。 例如,使用阿里云的 NTP 服务器:

bash 复制代码
sudo vi /etc/chrony.conf

在文件中找到以下行:

bash 复制代码
ini

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool (https://www.pool.ntp.org/join.html).

#pool 2.centos.pool.ntp.org iburst

#pool 2.centos.pool.ntp.org iburst

#pool 2.centos.pool.ntp.org iburst

#pool 2.centos.pool.ntp.org iburst

将其替换为:

bash 复制代码
ini

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool (https://www.pool.ntp.org/join.html).

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

保存并退出编辑器。

  1. 重启 chronyd 服务

修改配置后,重启 chronyd 服务以使更改生效:

bash 复制代码
sudo systemctl restart chronyd
  1. 验证时间同步状态

使用以下命令检查时间同步状态:

bash 复制代码
chronyc tracking

如果输出中显示 System clock synchronized: yes,则表示时间同步成功。

此外,您还可以使用以下命令查看 NTP 服务器的同步状态:

bash 复制代码
chronyc sources

如果输出中有 ^* 标记的服务器,表示该服务器正在被使用进行时间同步。

  1. 设置时区

如果需要设置时区,可以使用 timedatectl 命令:

bash 复制代码
sudo timedatectl set-timezone Asia/Shanghai

请根据您的实际时区进行调整。

通过以上步骤,您可以在 CentOS 9 上成功配置 NTP 服务,确保系统时间的准确性。

相关推荐
hugerat18 分钟前
在AI的帮助下,用C++构造微型http server
linux·c++·人工智能·http·嵌入式·嵌入式linux
ha20428941941 小时前
Linux操作系统学习记录之----自定义协议(网络计算器)
linux·网络·学习
想唱rap1 小时前
MYSQL在ubuntu下的安装
linux·数据库·mysql·ubuntu
java_logo1 小时前
QWEN3 企业级 Docker 容器化部署指南
运维·docker·容器·qwen3部署·qwen3部署文档·qwen3部署教程·qwen3部署方案
糖~醋排骨1 小时前
DHCP服务的搭建
linux·服务器·网络
huohaiyu1 小时前
网络中的一些基本概念
运维·服务器·网络
Kiyra1 小时前
虚拟机假死?SSH 能连却卡 Logo 界面
运维·ssh
dust_and_stars2 小时前
ubuntu24使用apt安装VS-code-server code-server
linux·服务器·windows
码农小韩2 小时前
基于Linux的C++学习——循环
linux·c语言·开发语言·c++·算法
tap.AI2 小时前
Deepseek(九)多语言客服自动化:跨境电商中的多币种、多语种投诉实时处理
运维·人工智能·自动化