【Centos】CentOS7.4 同步时间

talk is cheap, show me the code.

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

  • 系统时间 指当前Linux Kernel中的时间

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

查看系统时间 date

[tanpeng@itplh ~]$ date
Fri Mar 27 17:53:52 CST 2020

设置系统时间的命令 date -s "月/日/年 时:分:秒"

[tanpeng@itplh ~]$ sudo date -s "02/27/2020 19:00:00"
Thu Feb 27 19:00:00 CST 2020
[tanpeng@itplh ~]$ date
Thu Feb 27 19:00:08 CST 2020

查看硬件时间的命令 hwclock

[tanpeng@itplh ~]$ sudo hwclock
Fri 27 Mar 2020 05:56:39 PM CST  -0.453631 seconds

设置硬件时间的命令 hwclock –set –date = (月/日/年 时:分:秒)

[tanpeng@itplh ~]$ sudo hsclock -s "02/27/2020 19:00:00"
Thu Feb 27 19:00:00 CST 2020
[tanpeng@itplh ~]$ date
Thu Feb 27 19:00:08 CST 2020

上述提到的是手动设置时间到一个时间点,可能与当前网络的时间有误差

与时间服务器上的时间同步的方法

  1. 安装 ntpdate工具yum -y install ntp ntpdate

  2. 设置系统时间与网络时间同步 ntpdate cn.pool.ntp.org

  3. 将系统时间写入硬件时间 hwclock --systohc

example

[tanpeng@cloud02 ~]$ sudo ntpdate cn.pool.ntp.org
27 Mar 18:20:22 ntpdate[17937]: step time server 111.230.189.174 offset 2502162.541489 sec
[tanpeng@cloud02 ~]$ sudo hwclock --systohc
[tanpeng@cloud02 ~]$ date
Fri Mar 27 18:20:47 CST 2020
[tanpeng@cloud02 ~]$ sudo hwclock
Fri 27 Mar 2020 06:20:56 PM CST  -0.609821 seconds
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值