首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用ntpd模拟ntpdate -q?

如何用ntpd模拟ntpdate -q?
EN

Unix & Linux用户
提问于 2018-10-02 20:45:47
回答 1查看 2.6K关注 0票数 2

来自man ntpdate上的CentOS 7.2服务器:

Disclaimer: The functionality of this program is now available in the ntpd program. See the -q command line option in the ntpd - Network Time Protocol (NTP) daemon page. After a suitable period of mourning, the ntpdate program is to be retired from this distribution

来自man ntpd

-q Exit the ntpd just after the first time the clock is set. This behavior mimics that of the ntpdate program, which is to be retired. The -g and -x options can be used with this option. Note: The kernel time discipline is disabled with this option.

这模仿了ntpdate命令的通常功能。但是,ntpdate也有自己的-q标志:

-q Query only - don't set the clock.

ntpd手册页面中,我看不到执行此功能的任何方式。

既然ntpdate最终将被淘汰,那么ntpdate -q目前提供的功能的未来兼容的首选方法是什么呢?

EN

回答 1

Unix & Linux用户

发布于 2018-10-03 06:52:32

查询远程服务器

如果要查询远程ntp服务器,请使用:

代码语言:javascript
复制
# sntp 0.debian.pool.ntp.org
sntp 4.2.8p10@1.3728-o Sun Feb 25 21:22:25 UTC 2018 (1)
2018-10-03 04:34:02.687911 (+0400) -0.002893 +/- 0.063203 0.debian.pool.ntp.org 186.118.171.89 s3 no-leap

集ntpd时间

如果您希望设置服务器时间:

最近版本的ntpd:

代码语言:javascript
复制
# ntpd --version
ntpd 4.2.8p10@1.3728-o Sun Feb 25 21:22:55 UTC 2018 (1)

-q选项将在手册中如下所示:

-q在第一次设置时钟后就退出ntpd。此行为模仿即将退休的ntpdate程序。-g和-x选项可以与此选项一起使用。注意:使用此选项禁用了内核时间规则。

因此,在停止ntp守护进程(取决于系统的service ntpd stopsystemctl stop ntp )之后,请使用以下命令:

代码语言:javascript
复制
# ntpd -gq

-gq告诉ntp守护进程不管偏移量(g)如何更正时间,并在设置时间后立即退出(q)。

然后,重新启动ntpd并检查它是否工作:

代码语言:javascript
复制
# ntpq -pn
票数 2
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/472862

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档