Centos7时间同步与重启失效问题

Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC)。
系统时间:指当前Linux Kernel中的时间。
硬件时间:主板上有电池供电的时间。

查看系统时间的命令:
date

设置系统时间的命令:
timedatectl set-time "YYYY-MM-DD HH:MM:SS"

查看硬件时间的命令:
hwclock

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

上述提到的是手动设置时间到一个时间点,可能与当前网络的时间有误差。下面介绍一下与时间服务器上的时间同步的方法

1.安装ntpdate工具

    yum -y install ntp ntpdate
 

2.设置系统时间与网络时间同步

	ntpdate cn.pool.ntp.org
 

3.硬件时间和系统时间之间同步

    hwclock --systohc  #将系统时间写入硬件时间
    hwclock --hctosys  #将硬件时间写入系统时间
 

4.强制系统时间写入CMOS中防止重启失效

  hwclock -w
  或clock -w
 

让我们动手将操作系统的时间进行同步吧!

在CentOS Linux中终端命令中执行以下命令:

1、编辑时间配置文件

	vi /etc/sysconfig/clock  
	ZONE="Asia/Shanghai"
	UTC=false                          #设置为false,硬件时钟不于utc时间一致
	ARC=false
 

2、linux的时区设置为上海时区

	ln -sf /usr/share/zoneinfo/Asia/Shanghai   /etc/localtime
 

3、对准时间

	ntpdate 192.43.244.18
 

如果没有安装ntp服务器,刚需要先执行以下命令:

	yum install ntp #安装ntp服务器
 

4、设置硬件时间和系统时间一致并校准

	/sbin/hwclock --systohc
 
 
posted @ 2020-12-03 11:34  缘来不是你我  阅读(1043)  评论(0编辑  收藏  举报