zoukankan      html  css  js  c++  java
  • Linux服务器同步Intetnet时间

    Linux服务器同步Intetnet时间

    在使用linux服务器(虚拟机)的过程中,经常会发现使用一段时间后,linux服务器的时间和我的宿主机的时间不一致,而宿主机的时间确实是internet时间,安装linux时选择的时区也是Asia/Shanghai,下面说说虚拟机和Internet时间同步的方法。

    1、先查看当前服务器(linux系统)时间:

    [root@heyong ~]# date
    Thu Jan 17 03:24:35 CST 2019

     

    2.hwclock命令   (即hardwareclock系统硬件时间)

    [root@heyong ~]# hwclock
    Thu 17 Jan 2019 03:24:36 PM CST  -0.332157 seconds

    将系统时间写入到系统硬件当中

    [root@heyong ~]# hwclock -w

     

    3.ntpdate

    ntpdate 是一个linux时间同步服务软件,查看本机是否安装ntpdate服务,如果没有安装,请 yum install -y ntpdate;

    同步时间:

    [root@heyong ~] ntpdate time.nist.gov

    或者

    [root@heyong ~] ntpdate ntp1.aliyun.com

    执行:ntpdate ntp1.aliyun.com

    [root@heyong ~]# ntpdate ntp1.aliyun.com
    17 Jan 10:29:51 ntpdate[8345]: step time server 120.25.115.20 offset 31.542281 sec

    出现上述结果代表时间同步成功,上面的大致意思为调整时间为服务器120.25.115.20的时间,相差31.542281秒的时间

    如果上面time.nist.gov服务器同步不了,可以换下面几个时间服务器试试:

    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

    4.定时执行时间同步任务

    [root@kvm01 ~]# crontab -e

    * */1 * * * root ntpdatetime.nuri.net;hwclock -w

    即:每隔一个小时同步一下internet时间。

  • 相关阅读:
    杭电2054
    M1/M2总结
    软件开发相关的读书笔记 问题与方法
    代码复审1234跟我一起来
    电梯调度算法简述
    Pair_Work Project
    读书笔记摘录:
    Individual Project
    个人阅读作业——软件工程M1/M2的总结
    个人阅读作业2
  • 原文地址:https://www.cnblogs.com/heyongboke/p/10282565.html
Copyright © 2011-2022 走看看