首页 > 其他 > 详细

CentOS 7时间管理

时间:2021-04-06 12:33:45      阅读:23      评论:0      收藏:0      [点我收藏+]

CentOS 7时间管理

一、CentOS 7查看时间

1. 查看系统时间

[root@Charramma ~]# date
Tue Apr  6 17:35:18 CST 2021

[root@Charramma ~]# date -R
Tue, 06 Apr 2021 17:35:54 +0800

2. 查看硬件时间

[root@Charramma ~]# hwclock
Tue 06 Apr 2021 05:36:45 PM CST  -0.226496 seconds

二、CentOS 7 更新时间

1. 更新系统时间

1.1 手动更新系统时间

timedatectl 修改年月日

[root@Charramma ~]# timedatectl set-time 2018-08-30
[root@Charramma ~]# date
Thu Aug 30 00:00:01 CST 2018

timedatectl 修改时分秒

[root@Charramma ~]# timedatectl set-time 10:12:15
[root@Charramma ~]# date        
date
Thu Aug 30 10:12:20 CST 2018

直接使用 date -s 修改

[root@Charramma ~]# date -s "2020-02-12 13:13:13"
Wed Feb 12 13:13:13 CST 2020

1.2 自动更新系统时间

使用ntp服务设置系统时间与网络时间同步

[root@Charramma ~]# yum install ntp -y
[root@Charramma ~]# ntpdate cn.pool.ntp.org

1.3 修改系统时区

timedatectl list-timezones列出所有时区

[root@Charramma ~]# timedatectl list-timezones
[root@Charramma ~]# timedatectl set-timezone Asia/Ho_Chi_Minh

或者直接复制时区文件

[root@Charramma ~]# cp /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime

2. 更新硬件时间

2.1 手动更新硬件时间

[root@Charramma ~]# hwclock --set --date "2020-02-23 12:12:13"

2.2 自动更新硬件时间

ntpdate命令默认只同步系统时间,可以通过修改配置让硬件时间和系统时间一起更新

[root@Charramma ~]# sed -i ‘s/SYNC_HWCLOCK=no/SYNC_HWCLOCK=yes/‘ /etc/sysconfig/ntpdate
[root@Charramma ~]# systemctl restart ntpdate
[root@Charramma ~]# ntpdate cn.pool.ntp.org

2.3 将系统时间写入硬件时间

-w --systohc

[root@Charramma ~]# hwclock --systohc

或者

[root@Charramma ~]# timedatectl set-local-rtc 1

将日期写入CMOS

[root@Charramma ~]# clock -w

2.4 将硬件时间写入系统时间

-s --hctosys

[root@Charramma ~]# hwclock --hctosys

CentOS 7时间管理

原文:https://www.cnblogs.com/CharrammaBlog/p/14620703.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!