Linux下使用ntpdate进行时间同步

如果在Linux系统里,时间日期错误怎么办?

如题,我们可以使用ntpdate进行时间同步,来确保我们的时间和北京时间一致。

1、安装ntpdate,执行以下命令

# yum install ntpdate -y

2、手工同步网络时间,执行以下命令,将从time.nist.gov同步时间

# ntpdate 0.asia.pool.ntp.org

若上面的时间服务器不可用,也可以选择以下服务器同步时间

  time.nist.gov
  time.nuri.net
  0.asia.pool.ntp.org
  1.asia.pool.ntp.org
  2.asia.pool.ntp.org
  3.asia.pool.ntp.org

3、使用crontab计划任务定时更新网络时间,修改crontab文件,在末尾增加* */1 * * * ntpdate 0.asia.pool.ntp.org,每隔1小时同步一次时间。

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
 *  */1  *  *  * ntpdate 0.asia.pool.ntp.org

4、使用date查看当前时间

[root@lookphp lib]# date
2018年 04月 03日 星期二 12:15:19 CST

5、系统时间同步到硬件,防止系统重启后时间被还原

# hwclock --systohc
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容