如何计算两个不同Linux服务器之间的系统时间偏移量?

时间:2010-02-19 14:31:27

标签: linux time transactions

我们有两个Linux服务器,ServerA和ServerB。 ServerA上的系统时间似乎略微落后于ServerB,只有几百分之一秒。

我正在尝试诊断分布式事务的问题,并注意到两个服务器的时间之间存在轻微的不一致,但我需要一些方法来证明它。我需要的东西能告诉我“ServerA是ServerB后面的0.002秒”。也许并不像这样冗长,但你得到了这张照片。

有没有办法证明这一点?即是否有一个实用程序/脚本/命令可以用来告诉我究竟有什么偏移量?

3 个答案:

答案 0 :(得分:5)

您可以在两台服务器上以仅查询模式使用ntpdate并比较结果(例如,报告每台服务器的距离)。当然,将它们与同一时间源进行比较。并建议管理员,如果机器尚未与ntpd保持同步,那么它们应该是。{如果时间对您正在做的事情至关重要,那么您应该有一个本地时间服务器,它定期与外部世界同步,并与您的本地服务器同步。

答案 1 :(得分:0)

您可以使用NTP同步2台服务器,例如ntpdate

答案 2 :(得分:0)

使用名为 request.post( 'https://server.com/index.php/rest/V1/integration/admin/token', { form:postData, headers:{ "Content-Type": "application/json" } },function (error, response, body) { console.log('error:', error); // Print the error if one occurred console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received console.log('body:', body); // Print the HTML for the Google homepage. res.json({ 'error': error, 'statusCode': response && response.statusCode, 'body': body }) }); 的实用程序,clockdiff包的一部分。您需要使用root运行它,例如iputils,其输出如下:

sudo clockdiff <hostname>