首先,我在这里搜索了答案,它不是标准的禁用/清除 ntp/chrony。我可以运行 dpkg -l | grep ntp 和 dpkg -l | grep chrony,但都没有返回任何内容,所以我知道它与此不冲突。它也是 ubuntu 20.04 的全新 vagrant 映像,没有从以前版本的 ubuntu 升级留下的任何垃圾。
启用 systemd-timesyncd 后,启动时无法启动和同步时间。
systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:systemd-timesyncd.service(8)
/lib/systemd/system/systemd-timesyncd.service 中没有任何条件可以阻止它,并且都是默认设置
[Unit]
Description=Network Time Synchronization
Documentation=man:systemd-timesyncd.service(8)
ConditionCapability=CAP_SYS_TIME
ConditionVirtualization=!container
DefaultDependencies=no
After=systemd-sysusers.service
Before=time-set.target sysinit.target shutdown.target
Conflicts=shutdown.target
Wants=time-set.target time-sync.target
[Service]
AmbientCapabilities=CAP_SYS_TIME
CapabilityBoundingSet=CAP_SYS_TIME
ExecStart=!!/lib/systemd/systemd-timesyncd
LockPersonality=yes
MemoryDenyWriteExecute=yes
NoNewPrivileges=yes
PrivateDevices=yes
PrivateTmp=yes
ProtectControlGroups=yes
ProtectHome=yes
ProtectHostname=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
ProtectKernelLogs=yes
ProtectSystem=strict
Restart=always
RestartSec=0
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
RuntimeDirectory=systemd/timesync
StateDirectory=systemd/timesync
SystemCallArchitectures=native
SystemCallErrorNumber=EPERM
SystemCallFilter=@system-service @clock
Type=notify
User=systemd-timesync
WatchdogSec=3min
[Install]
WantedBy=sysinit.target
Alias=dbus-org.freedesktop.timesync1.service
/etc/systemd/timesyncd.conf 仅包含以下内容
[Time]
NTP=0.us.pool.ntp.org
FallbackNTP=ntp.ubuntu.com 1.us.pool.ntp.org time.cloudflare.com
但是当我使用 systemctl restart systemd-timesyncd 手动启动它时,它运行良好,只有在启动时才会进入死亡状态。
systemctl restart systemd-timesyncd
systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-07-29 20:34:51 UTC; 6s ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 1347 (systemd-timesyn)
Status: "Initial synchronization to time server 23.175.208.10:123 (0.us.pool.ntp.org)."
Tasks: 2 (limit: 2320)
Memory: 1.3M
CGroup: /system.slice/systemd-timesyncd.service
└─1347 /lib/systemd/systemd-timesyncd
我甚至可以将 systemctl restart systemd-timesyncd 放入 rc.local,它在 rc.local 运行后启动时可以正常工作。我可以采用这种方式并称其为好,但它肯定应该在没有它的情况下工作。我在 /var/log/syslog 中也找不到任何故障迹象。
如果重要的话,这是一个 VirtualBox VM,但我最终需要在 EC2 上进行设置。