You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求指导NTP服务配置及问题排查

请求指导NTP服务配置及问题排查

Hi Goutham, let's walk through setting up and troubleshooting NTP (or its modern replacement, Chrony) step by step — I’ve helped lots of folks fix similar issues, so let’s get this sorted out.


第一步:安装NTP/Chrony服务

First up, make sure you have the right package installed. The tool you use depends on your Linux distro:

  • For Debian/Ubuntu:
    sudo apt update && sudo apt install ntp -y
    # 或者推荐用更轻量、更可靠的Chrony:
    # sudo apt install chrony -y
    
  • For RHEL/CentOS/Rocky Linux:
    sudo dnf install ntp -y
    # 或者Chrony(部分系统默认已预装):
    # sudo dnf install chrony -y
    

第二步:配置NTP服务器

Next, edit the configuration file to use reliable, geographically close NTP servers (local servers sync faster than global ones). For example, if you're in Asia, use the Asia pool:

如果你用的是ntpd:

Edit the config file with your preferred editor:

sudo nano /etc/ntp.conf

Replace the default server lines with:

server 0.asia.pool.ntp.org iburst
server 1.asia.pool.ntp.org iburst
server 2.asia.pool.ntp.org iburst
server 3.asia.pool.ntp.org iburst

The iburst flag helps speed up initial synchronization.

如果你用的是Chrony(推荐):

Edit the config file:

sudo nano /etc/chrony.conf

Update the pool lines to:

pool 0.asia.pool.ntp.org iburst
pool 1.asia.pool.ntp.org iburst
pool 2.asia.pool.ntp.org iburst
pool 3.asia.pool.ntp.org iburst

第三步:启动服务并设置开机自启

Save the config file, then restart the service and enable it to run on boot:

  • For ntpd:
    sudo systemctl restart ntp
    sudo systemctl enable ntp
    
  • For Chrony:
    sudo systemctl restart chronyd
    sudo systemctl enable chronyd
    

问题排查(针对你重启后仍有问题的情况)

Let's dig into why your sync isn't working:

  1. 检查服务运行状态

    # 针对ntpd:
    sudo systemctl status ntp
    # 针对Chrony:
    sudo systemctl status chronyd
    

    Look for "active (running)" in the output. If it's failed, the error message will likely point to a config typo or permission issue.

  2. 验证同步状态

    • 针对ntpd:
      ntpq -p
      
      You should see a * next to one of the servers — that means it's the active sync source. If all lines show ?, your server can't reach the NTP pools.
    • 针对Chrony:
      chronyc tracking
      
      Look for Leap status: Normal — that means sync is working. Leap status: Not synchronised indicates a problem.
  3. 检查防火墙规则
    NTP uses UDP port 123, so make sure your firewall isn't blocking traffic on this port:

    • 针对UFW(Debian/Ubuntu):
      sudo ufw allow 123/udp
      
    • 针对firewalld(RHEL/CentOS):
      sudo firewall-cmd --add-port=123/udp --permanent
      sudo firewall-cmd --reload
      
  4. 查看系统日志
    Logs will tell you exactly what's going wrong:

    # 针对ntpd:
    sudo journalctl -u ntp -f
    # 针对Chrony:
    sudo journalctl -u chronyd -f
    

    Look for errors like "no server suitable for synchronization found" or "connection refused" — these will clue you in on whether it's a network issue or config problem.

  5. 校准硬件时钟
    If your system clock is drastically off, NTP might refuse to sync. First check the current time:

    date
    

    If it's way incorrect, manually set it close to the real time first (then restart the NTP service):

    sudo date -s "2024-05-20 14:30:00"
    

Let me know if any of these steps hit a snag, or if you see specific error messages in the logs — I’ll help you dig deeper!

备注:内容来源于stack exchange,提问作者Goutham An

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 11:04:43