首页 » Linux基础 » 使用ntpdate命令同步系统时间

使用ntpdate命令同步系统时间

 

很多时候Linux操作系统都是在虚拟机中安装的,经常需要关机开机,这时候就可能导致系统的时间不正确了。我们可以使用ntpdate这个命令来同步系统时间。

如果没有这个命令的话需要安装ntpdate这个包:

[root@kandiannet fanxiaomo520]# yum install ntpdate
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
base | 3.7 kB 00:00
data_myyumsource | 4.1 kB 00:00 ...
extras | 3.4 kB 00:00
extras/primary_db | 29 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 4.7 MB 00:00
Resolving Dependencies
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.6p5-12.el6.centos.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
ntpdate x86_64 4.2.6p5-12.el6.centos.1 updates 79 k

Transaction Summary
================================================================================
Install 1 Package(s)

Total download size: 79 k
Installed size: 123 k
Is this ok [y/N]: y
Downloading Packages:
ntpdate-4.2.6p5-12.el6.centos.1.x86_64.rpm | 79 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : ntpdate-4.2.6p5-12.el6.centos.1.x86_64 1/1
Verifying : ntpdate-4.2.6p5-12.el6.centos.1.x86_64 1/1

Installed:
ntpdate.x86_64 0:4.2.6p5-12.el6.centos.1

Complete!

然后同步并写入硬件时钟:


[root@kandiannet fanxiaomo520]# ntpdate time.windows.com && hwclock -w
1 Nov 18:54:08 ntpdate[4337]: step time server 52.168.138.145 offset 99646.910274 sec
[root@kandiannet fanxiaomo520]# date
Wed Nov 1 18:54:19 CST 2017

 

原文链接:使用ntpdate命令同步系统时间,转载请注明来源!

0