linux 时间同步和时区设置

阅读: 评论:0

linux 时间同步和时区设置

linux 时间同步和时区设置

linux 时间同步和时区设置

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

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

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

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

设置系统时间的命令: #date –set(月/日/年 时:分:秒)

例:#date –set “10/11/10 10:15”

查看硬件时间的命令: # hwclock

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

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

  1. 安装ntpdate工具

yum -y install ntp ntpdate

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

ntpdate p

  1. 将系统时间写入硬件时间

hwclock --systohc

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

hwclock -w
  或clock -w

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

1、vi /etc/sysconfig/clock #编辑时间配置文件

ZONE=“Asia/Shanghai”
UTC=false #设置为false,硬件时钟不于utc时间一致
ARC=false

2、ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #linux的时区设置为上海时区

3、ntpdate 192.43.244.18 #对准时间

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

yum install ntp #安装ntp服务器

4、/sbin/hwclock --systohc #设置硬件时间和系统时间一致并校准

更改时区设置

查看系统时间
[root@localhost ~]# date
Tue Jun 13 10:20:13 CST 2017

查看硬件时间
[root@localhost ~]# hwclock --show
Tue 13 Jun 2017 02:11:12 AM CST -0.848845 seconds

可以看出系统时间比硬件时间快,系统时间是准确的

假如系统时间和硬件时间都不准确

更新系统年月日
[root@localhost ~]# timedatectl set-time 2017-06-13

更新系统时分秒
[root@localhost ~]# timedatectl set-time 10:25:17

更新时区(亚洲-中国-上海)
[root@localhost ~]# timedatectl set-timezone Asia/Shanghai

将硬件时钟调整为与系统时钟一致
[root@localhost ~]# timedatectl set-local-rtc 1
或者
[root@localhost ~]# hwclock --systohc --localtime

将日期写入CMOS
[root@localhost ~]# clock –w

本文发布于:2024-02-01 01:41:28,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170672288832934.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:时区   时间   linux
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23