麒麟系统时间不准需先设时区再启同步服务:1.用timedatectl设asia/shanghai;2.启用systemd-timesyncd或chrony(推荐);3.必要时用ntpdate强制校准并同步硬件时钟。

如果您在麒麟操作系统中发现系统时间不准确或与时区不符,则可能是由于未启用时间同步服务或时区配置错误。以下是设置时间同步及调整时区的具体步骤:
一、检查并设置系统时区
正确配置时区是确保时间显示准确的前提,系统需识别所在地理区域以应用对应的标准时间和夏令时规则。
1、查看当前时区设置:
执行命令 timedatectl status,观察输出中的“Time zone”字段。
2、列出所有可用时区:
执行命令 timedatectl list-timezones | grep -i china,筛选出中国大陆常用时区。
3、设置为上海时区(CST,UTC+8):
执行命令 sudo timedatectl set-timezone Asia/Shanghai。
4、验证修改结果:
再次运行 timedatectl status,确认“Time zone”已更新为 Asia/Shanghai (CST, +0800)。
二、启用systemd-timesyncd服务(轻量级NTP客户端)
systemd-timesyncd 是麒麟OS默认集成的轻量级网络时间同步服务,适用于大多数桌面和基础服务器场景,无需额外安装。
1、检查服务当前状态:
执行命令 systemctl is-active systemd-timesyncd,若返回 inactive 则需启用。
2、启用并启动服务:
执行命令 sudo systemctl enable --now systemd-timesyncd。
3、配置自定义NTP服务器(可选):
创建配置目录与文件:sudo mkdir -p /etc/systemd/timesyncd.conf.d/;
编辑配置文件:sudo nano /etc/systemd/timesyncd.conf.d/ntp-servers.conf;
写入以下内容:
[Time]
NTP=ntp.aliyun.com ntp.tencent.com cn.pool.ntp.org。
4、重启服务使配置生效:
执行命令 sudo systemctl restart systemd-timesyncd。
三、使用chrony配置高精度时间同步
chrony 更适合对时间精度要求较高的环境,支持断网补偿、快速收敛和内网NTP源部署,是麒麟V10推荐的时间同步方案。
1、安装chrony服务:
执行命令 sudo apt install chrony(Debian系)或 sudo yum install chrony(RHEL系)。
2、编辑主配置文件:
执行命令 sudo nano /etc/chrony/chrony.conf;
注释掉默认的 public pool 行,添加国内可靠源:
server ntp.aliyun.com iburst
server ntp.tencent.com iburst
server cn.pool.ntp.org iburst。
3、启动并设为开机自启:
执行命令 sudo systemctl start chronyd;
执行命令 sudo systemctl enable chronyd。
4、验证同步状态:
执行命令 chronyc tracking 查看偏移量与同步源;
执行命令 chronyc sources -v 查看当前连接的NTP服务器详情。
四、使用ntpd服务(传统方式)
ntpd 为经典NTP守护进程,兼容性广,但资源占用略高于chrony,适用于需长期稳定运行且版本较老的麒麟环境。
1、安装ntp软件包:
执行命令 sudo apt install ntp 或 sudo yum install ntp。
2、备份原始配置:
执行命令 sudo cp /etc/ntp.conf /etc/ntp.conf.bak。
3、编辑配置文件:
执行命令 sudo nano /etc/ntp.conf;
替换 server 行为:
server ntp.aliyun.com iburst prefer
server ntp.tencent.com iburst。
4、启动服务并检查:
执行命令 sudo systemctl start ntpd;
执行命令 sudo systemctl enable ntpd;
执行命令 ntpq -p 查看对等节点状态。
五、手动强制时间同步(临时校准)
当服务尚未生效或需立即修正明显偏差时,可绕过守护进程直接调用同步工具进行一次性校准。
1、停止正在运行的时间同步服务(避免冲突):
执行命令 sudo systemctl stop systemd-timesyncd chronyd ntpd。
2、安装ntpdate工具(如未预装):
执行命令 sudo apt install ntpdate 或 sudo yum install ntpdate。
3、执行强制同步:
执行命令 sudo ntpdate -u ntp.aliyun.com;
若提示“no server suitable for synchronization”,请更换为 ntp.tencent.com 或 cn.pool.ntp.org。
4、将系统时间写入硬件时钟:
执行命令 sudo hwclock --systohc。










