zoukankan      html  css  js  c++  java
  • Linux下ntpdate时间同步

    1 简介

          Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC)。

          系统时间:指当前Linux Kernel中的时间。

          硬件时间:主板上有电池供电的时间。

          查看系统时间的命令: #date

    2 修改Linux的时区:

          查看当前时区:date -R

         出现的是:Thu, 03 Jan 2019 18:25:04 -0800

         修改/etc/sysconfig/clock文件   
                  ZONE="Asia/Shanghai"

                  UTC=false

                  ARC=false                    

         然后执行:

                 rm   -f /etc/localtime 

                 cp  /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

          

    3 根据设置硬件时间

         查看硬件时间:hwclock  -r

         系统时间同步到硬件时间:hwclock  -w

    4 Linux下ntpdate时间同步

         Ntp服务器配置: yum -y install ntp ntpdate

         时间同步方法

                同步命令               # ntpdate ntp服务器域名或IP           例:# ntpdate 1.cn.pool.ntp.org

                http://www.pool.ntp.org是NTP的官方网站,在这上面我们可以找到离我们国家的NTP Server cn.pool.ntp.org.

        自动运行同步时间脚本设定

               # crontab  -e

               添加脚本例子如下:                                   

    #每20分钟执行一次
    */20 * * * *   /usr/sbin/ntpdate 192.168.1.10 ;/sbin/hwclock -w > /dev/null #2>&1         
    #每天早晨5点半执行  
    30 5 * * *    /usr/sbin/ntpdate 192.168.1.10 ;/sbin/hwclock -w > /dev/null #2>&1

             ※ 前面五个*号代表五个数字,数字的取值范围和含义如下:

              分钟(0-59) 小時(0-23) 日期(1-31) 月份(1-12) 星期(0-6)//0代表星期天

          设定完毕后,可使用# crontab –l 查看上面的设定。

  • 相关阅读:
    Golang基础笔记
    PHP面试题
    PHP操作文件常用函数
    转:C#委托与事件
    转:Tkinter教程之Text(2)篇
    Tkinter教程之Text篇(1)
    转:Python 从FTP 下载数据的例子
    转:Python模块学习 ---- httplib HTTP协议客户端实现
    转:Python yield 使用浅析
    有用的网址地址
  • 原文地址:https://www.cnblogs.com/t0404/p/10290930.html
Copyright © 2011-2022 走看看