zoukankan      html  css  js  c++  java
  • Linux 修改同步internet 时间

    安装时间同步软件
    apt-get install ntpdate
    # tzselect 选择当前系统时区
    # 或者通过复制文件修改系统时区设置
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    
    # 同步系统时间
    /usr/sbin/ntpdate -s us.pool.ntp.org
    # 同步硬件时间
    /usr/sbin/hwclock --systohc
    

    使用方式任务进行同步时间
    方法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里
    代码:

    # 每天11点与中国国家授时中心同步时间
    00 11 * * * root ntpdate 210.72.145.44
    # 或者
    00 11 * * * root ntpdate us.pool.ntp.org
    

    2、使用命令crontab -e

    crontab -e 
    # 每天5:10自动进行网络校时,并同时更新BIOS的时间
    10 5 * * * root ntpdate us.pool.ntp.org;hwclock -w 
    

    一些常用的授时中心

    中国国家北京时间授时中心:
    http://www.time.ac.cn/stime.asp
    其他网络时间服务器地址如下
    time.nist.gov(美国)
    ntp.fudan.edu.cn(复旦)(国内用户推荐使用此服务器)
    timekeeper.isi.edu
    subitaneous.cpsc.ucalgary.ca
    usno.pa-x.dec.com
    time.twc.weather.com
    swisstime.ethz.ch
    ntp0.fau.de
    ntp3.fau.de
    time-a.nist.gov
    time-b.nist.gov
    time-nw.nist.gov
    nist1-sj.glassey.com

    -----------------------------------------------------
    说明:
      a).代码仅供学习交流
      b).本文根据自身经验及网络总结所作,如有错误,谢谢指教
      c).转载请注明出处。
    -----------------------------------------------------
  • 相关阅读:
    【Python学习】URL编码解码&if __name__ == '__main__'
    【Python学习】邮件发送
    【Python学习】网络编程
    【Python学习】接口开发
    【Python学习】操作Sqllite
    【Python学习】操作Mongodb
    【Python学习】操作Redis
    【Python学习】操作Mysql
    jzoj6003
    jzoj5995
  • 原文地址:https://www.cnblogs.com/xqbumu/p/5435317.html
Copyright © 2011-2022 走看看