Skip to content
View in the app

A better way to browse. Learn more.

PHP论坛人

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

時區設定與時間同步

Featured Replies

----------------------------------
時區設定與時間同步
----------------------------------

在伺服器環境中,正確設定時區並啟用時間同步服務非常重要。若系統時間不準確,可能導致:

日誌時間錯亂

排程任務異常

SSL憑證錯誤

安全驗證失敗


因此建議在系統部署完成後立即確認時間設定






查看目前時間與時區
timedatectl


範例輸出:
Local time: Sun 2026-02-15 09:10:45 UTC
Time zone: UTC (UTC, +0000)



更改系統時區,例如,設定為上海時區
timedatectl set-timezone Asia/Shanghai



再次確認時區是否變更成功
timedatectl


應顯示:
Local time: Sun 2026-02-15 17:16:37 CST
Time zone: Asia/Shanghai (CST, +0800)





---------------------------
啟用網路時間同步 (NTP)
---------------------------

Debian 13預設使用:systemd-timesyncd,通常已預設啟用,可先確認
timedatectl status



若顯示:
System clock synchronized: no
NTP service: n/a




需要安裝
apt install -y systemd-timesyncd




再確認一次
timedatectl status


顯示:
System clock synchronized: yes
NTP service: n/a

現在System clock synchronized: yes 正常運作,不過NTP伺服器還未設定





自訂NTP伺服器
編輯 設定檔
vi /etc/systemd/timesyncd.conf



在該檔案中,找到 [Time],然後在底下新增2行內容

[Time]

NTP=pool.ntp.org 0.asia.pool.ntp.org 1.asia.pool.ntp.org 2.asia.pool.ntp.org
FallbackNTP=time.cloudflare.com time.google.com




儲存檔案並離開vi編輯器
按 Esc,輸入 :wq,按 Enter





---------------------------
啟用並重啟時間同步服務
---------------------------


啟用
systemctl enable systemd-timesyncd



重啟
systemctl restart systemd-timesyncd



查看服務狀態
systemctl status systemd-timesyncd



啟用NTP時間同步
timedatectl set-ntp true



查看同步狀態
timedatectl timesync-status

範例輸出

ntp.org.png

確認整體時間狀態
timedatectl



預期顯示

System clock synchronized: yes
系統時鐘已與遠端時間伺服器同步。表示你的系統時間準確,不會因為時間漂移而導致憑證驗證、日誌時間戳記、定時任務等出現問題

NTP service: active
負責時間同步的後台服務正在運行,會持續自動校準時間






補充說明

避免衝突:若使用其他NTP客戶端 (如 chrony 或 ntp),請勿同時啟用 systemd-timesyncd

防火牆設定:確保伺服器能連線至UDP 123埠,否則NTP無法正常運作

檢查日誌:若同步失敗,可查看日誌
journalctl -u systemd-timesyncd

Edited by Jack

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.