zoukankan      html  css  js  c++  java
  • Linux下自动调整时间和时区与Internet时间同步

    (原文链接)


    调整linux系统时间和时区与Internet时间同步
    一、修改时区:
    # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    修改为中国的东八区
    # vi /etc/sysconfig/clock
    ZONE="Asia/Shanghai"
    UTC=false
    ARC=false
    二、配置新的时间
    日期设定:
    # date -s 2008/05/06
    时间设定:
    # date -s 18:40:00
    查看硬件时间(BIOS的):
        hwclock [-rw]
        -r:查看现有BIOS时间,默认为-r参数
        -w:将现在的linux系统时间写入BIOS中
        当我们进行完 Linux 时间的校时后,还需要以 hwclock -w 来更新 BIOS 的时间,因为每次开机的时候,系统会重新由 BIOS 将时间读出来,所以, BIOS 才是重要的时间依据。
    # hwclock
    Tue 06 May 2008 03:49:37 PM CST  -0.039646 seconds
    同步BIOS时钟,强制把系统时间写入CMOS:
    # clock -w
    三、实现Internet时间同步(这里可以忽略上面两步)
    方法1. 开机的时候自动网络校时:
        vi /etc/rc.d/rc.local
        /usr/sbin/ntpdate -u 192.168.0.2 192.168.0.3 192.168.0.4;   /sbin/hwclock -w
    方法2. 设定计划任务
    crontab格式如下:
    # 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
    # |  |  |  |  |
    # *  *  *  *  *  command to be executed
    设定crontab计划任务也有两种方式:
    1、写在/etc/crontab里
    代码:
    00 11 * * * root ntpdate 210.72.145.44
    每天11点与中国国家授时中心同步时间
    每天11点与中国国家授时中心同步时间
    当然前提是
    apt-get install ntpdate
    代码也可是
    00 11 * * * root ntpdate us.pool.ntp.org
    2、使用命令crontab -e
    crontab -e
        10 5 * * * root ntpdate us.pool.ntp.org;hwclock -w
    这样每天5:10自动进行网络校时,并同时更新BIOS的时间
    ################################

    同步网络时间:输入ntpdate time.nist.gov同步网络时间

    [root@localhost ~]# ntpdate time.nist.gov

    12 Oct 17:25:01 ntpdate[2784]: step time server 132.163.4.103 offset 1147751.472254 sec

    ##出现以上信息说明同步成功##

    注:如提示命令不存在,直接输入:yum install ntp -y  安装ntp软件包。

  • 相关阅读:
    Prometheus监控告警浅析
    BaikalDB技术实现内幕(三)--代价模型实现
    微服务的熔断原理与实现
    2020双11,阿里巴巴集团数万数据库系统全面上云揭秘
    平行进化论再添证据 牙形刺远隔千里却发育模式相同
    如何利用设计模式改善业务代码?
    SpringBoot 无侵入式实现 API 接口统一 JSON 格式返回
    独家 | 这可能会引领通用AI的下一个重大突破
    iOS 网络优化: 使你的 App 网络交互更流畅
    Java Web整合开发(17) -- Struts 2.x 高级应用
  • 原文地址:https://www.cnblogs.com/blogforly/p/5953878.html
Copyright © 2011-2022 走看看