关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

云服务器CentOS 7时间管理

发布时间:2021/4/13 12:07:33
香港云服务器

一、CentOS 7查看时间

1. 查看系统时间

12345[root@Charramma ~]# dateTue Apr  6 17:35:18 CST 2021[root@Charramma ~]# date -RTue, 06 Apr 2021 17:35:54 +0800

2. 查看硬件时间

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

二、CentOS 7 更新时间

1. 更新系统时间

1.1 手动更新系统时间

timedatectl 修改年月日

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

timedatectl 修改时分秒

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

直接使用 date -s 修改

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

1.2 自动更新系统时间

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

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

1.3 修改系统时区

timedatectl list-timezones列出所有时区

12[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命令默认只同步系统时间,可以通过修改配置让硬件时间和系统时间一起更新

123[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