2017/12/9

  1. 安裝環境
    Debain Jessie

  2. 先安裝 openntpd

    apt-get install openntpd
    
  3. 若要使用國內的 NTP 伺服器,可修改 openntpd 的設定檔,並加入以下設定

    #將預設的國外 NTP 伺服器註解掉
    #servers 0.debian.pool.ntp.org
    #servers 1.debian.pool.ntp.org
    #servers 2.debian.pool.ntp.org
    #servers 3.debian.pool.ntp.org
    
    servers tock.stdtime.gov.tw
    servers time.stdtime.gov.tw
    servers clock.stdtime.gov.tw 
    servers tick.stdtime.gov.tw
    servers watch.stdtime.gov.tw
    
  4. 安裝完後 openntpd 就會自動於 daemon 執行了,若要確認 openntpd 有正確運作,可使用以下指令

    systemctl status openntpd
    
    #執行結果如下,Active 為 running 代表有正確執行
    ● openntpd.service - OpenNTPd Network Time Protocol
       Loaded: loaded (/lib/systemd/system/openntpd.service; enabled)
       Active: active (running) since Sat 2017-12-09 12:05:17 CST; 2h 41min ago
      Process: 3715 ExecStart=/usr/sbin/ntpd $DAEMON_OPTS (code=exited, status=0/SUCCESS)
      Process: 3712 ExecStartPre=/usr/sbin/ntpd -n $DAEMON_OPTS (code=exited, status=0/SUCCESS)
     Main PID: 3717 (ntpd)
       CGroup: /system.slice/openntpd.service
               ├─3717 /usr/sbin/ntpd -f /etc/openntpd/ntpd.conf
               ├─3718 ntpd: ntp engine
               └─3719 ntpd: dns engine
    
  5. 若要手動執行 openntpd,可使用以下指令

    ntpd -dsv
    
  6. 若是出現錯誤訊息:debian ntpd[29354]: adjtime failed: Invalid argument,則要在 /etc/default/openntpd 中加入 DAEMON_OPTS="-s"

參考資料
  NTP 的網路資源
  NTP 新增頻寬
  NTP 伺服器
openntpd: "adjtime failed: Invalid argument"