sudo sh -c 'cat << EOF > /lib/systemd/system/chronyd.service [Unit] Description=Chrony Network Time Synchronization Service After=network.target [Service] Type=forking EnvironmentFile=-/usr/local/chrony/etc/chronyd.conf ExecStart=/usr/local/chrony/sbin/chronyd -f /usr/local/chrony/etc/chronyd.conf ExecReload=/bin/systemctl restart chronyd [Install] WantedBy=multi-user.target EOF'
4.执行命令,加载下 chronyd 启动脚本文件:
1
$ sudo systemctl daemon-reload
5.启动 chronyd 服务并将其设置为开机启动:
1
$ sudo systemctl enable --now chronyd.service
6.查看启动状态:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
$ sudo systemctl status chronyd.service ● chronyd.service - Chrony Network Time Synchronization Service Loaded: loaded (/lib/systemd/system/chronyd.service; disabled; vendor p> Active: active (running) since Fri 2024-03-15 00:31:05 UTC; 9s ago Process: 274154 ExecStart=/usr/local/chrony/sbin/chronyd -f /usr/local/c> Main PID: 274156 (chronyd) Tasks: 1 (limit: 4558) Memory: 272.0K CPU: 8ms CGroup: /system.slice/chronyd.service └─274156 /usr/local/chrony/sbin/chronyd -f /usr/local/chrony/et>
Mar 15 00:31:05 vm002-ubuntu2204 systemd[1]: Starting Chrony Network Time Sy> Mar 15 00:31:05 vm002-ubuntu2204 chronyd[274156]: chronyd version 4.5 starti> Mar 15 00:31:05 vm002-ubuntu2204 chronyd[274156]: Running with root privileg> Mar 15 00:31:05 vm002-ubuntu2204 chronyd[274156]: Frequency -10.905 +/- 1000> Mar 15 00:31:05 vm002-ubuntu2204 systemd[1]: Started Chrony Network Time Syn>
$ sudo sh -c 'cat << EOF > /lib/systemd/system/chronyc.service [Unit] Description=Chrony Network Time Synchronization Service After=network.target [Service] Type=forking EnvironmentFile=-/usr/local/chrony/etc/chronyc.conf ExecStart=/usr/local/chrony/sbin/chronyd -f /usr/local/chrony/etc/chronyc.conf ExecReload=/bin/systemctl restart chronyc [Install] WantedBy=multi-user.target EOF'
4.执行命令,加载下 chronyc 启动脚本文件:
1
$ sudo systemctl daemon-reload
5.启动 chronyc 服务并将其设置为开机启动:
1
$ sudo systemctl enable --now chronyc.service
6.执行命令,查看下 chronyc 启动状态:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
$ sudo systemctl status chronyc.service ● chronyc.service - Chrony Network Time Synchronization Service Loaded: loaded (/lib/systemd/system/chronyc.service; disabled; vendor preset: enabled) Active: active (running) since Fri 2024-03-15 00:20:12 UTC; 6s ago Process: 59028 ExecStart=/usr/local/chrony/sbin/chronyd -f /usr/local/chrony/etc/chronyc.conf (co> Main PID: 59030 (chronyd) Tasks: 1 (limit: 4557) Memory: 288.0K CPU: 9ms CGroup: /system.slice/chronyc.service └─59030 /usr/local/chrony/sbin/chronyd -f /usr/local/chrony/etc/chronyc.conf
Mar 15 00:20:12 vm002-ubuntu2204 systemd[1]: Starting Chrony Network Time Synchronization Service... Mar 15 00:20:12 vm002-ubuntu2204 chronyd[59030]: chronyd version 4.5 starting (+CMDMON +NTP +REFCLOCK> Mar 15 00:20:12 vm002-ubuntu2204 chronyd[59030]: Running with root privileges Mar 15 00:20:12 vm002-ubuntu2204 chronyd[59030]: Initial frequency 1.898 ppm Mar 15 00:20:12 vm002-ubuntu2204 systemd[1]: Started Chrony Network Time Synchronization Service.
7.动态查看系统日志,可以发现:
1 2 3 4
Mar 15 00:31:41 vm002-ubuntu2204 chronyd[59980]: Running with root privileges Mar 15 00:31:41 vm002-ubuntu2204 chronyd[59980]: Frequency -10.869 +/- 0.795 ppm read from /var/lib/chrony/drift Mar 15 00:31:41 vm002-ubuntu2204 systemd[1]: Started Chrony Network Time Synchronization Service. Mar 15 00:31:45 vm002-ubuntu2204 chronyd[59980]: Selected source 10.10.10.203