Ubuntu 時區 Etc/UTC&NTP
時區 Etc/UTC
timedatectl # 確認 Time zone: Etc/UTC
sudo timedatectl set-timezone Etc/UTC # 修改为 Time zone: Etc/UTC
NTP 來源
- Ubuntu 24.04 預設用 systemd-timesyncd 做時間同步(不是 ntpd/chrony)。做法是:每台主機都改同一份設定。
- 編輯 /etc/systemd/timesyncd.conf:
sudo vim /etc/systemd/timesyncd.conf - 把裡面的 [Time] 段改成(舉例):
NTP=ntp1.your-company.com FallbackNTP=ntp.ubuntu.com #⚠️ 重點:NTP= 那行所有主機要填同一個位址,這就是「同一個 NTP 來源」的要求。
若公司有內部 NTP 伺服器 → 填那個。
若沒有 → 全台統一填 pool.ntp.org 或 ntp.ubuntu.com(但要一致,別這台填 A 那台填 B)。
## 重启NTP,并验证状态
```bash
sudo systemctl restart systemd-timesyncd # 重启NTP
timedatectl timesync-status # 看 Status: "synchronized" 與實際連的 NTP 位址
检测内容说明
Server: 192.168.64.31 ← 連上內部 NTP 來源
Stratum: 4 ← 層級正常(越小越接近源頭,4 很合理)
Offset: +120.827ms ← 本機比 NTP 慢約 120 毫秒
Packet count: 1 ← 已成功收到封包
设定脚本
#!/usr/bin/env bash
# Ubuntu 24.04 標準主機部署(後安裝)
# 規格:時區 Etc/UTC / NTP 192.168.64.31 / Docker 24.0+ & Compose v2.20+ / 磁碟 LVM 留 8G(安裝時做)
set -euo pipefail
echo "== 1/4 時區 -> Etc/UTC =="
timedatectl set-timezone Etc/UTC
echo "== 2/4 NTP 來源 -> 192.168.64.31 =="
cat > /etc/systemd/timesyncd.conf <<'EOF'
NTP=192.168.64.31
FallbackNTP=ntp.ubuntu.com
EOF
systemctl restart systemd-timesyncd
echo "== 3/4 安裝 Docker Engine + Compose v2 =="
apt-get update
apt-get install -y ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker
echo "== 4/4 驗證 =="
timedatectl | grep -E "Time zone|synchronized"
docker --version
docker compose version
发布时间: