English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CentOS7Methods to Modify Server System Time

未知何故,服务器上的系统时间不正确,比实际的UTC快了将近63分钟。在涉及本地文件与远程服务器文件的时间戳校验时,容易产生混淆。

这里记录了系统时间校正的过程。

参考资料:http://www.centoscn.com/CentOS/config/2015/0723/5901.html

在CentOS 7其中有一个命令timedatectl可以帮助我们修改服务器的时区。

1. 查看服务器中的时间设置 timedatectl,它等同于 timedatectl status :

$ timedatectl
Local time: Mon 2016-08-29 16:20:35 CST
Universal time: Mon 2016-08-29 08:20:35 UTC
RTC time: Mon 2016-08-29 08:18:07
Time zone: Asia/Shanghai (CST, +0800)
NTP启用:是
NTP synchronized: no
RTC in local TZ: no
DST active: n/a

2. 了解 timedatectl 命令的各个参数:

$ timedatectl -h
timedatectl [OPTIONS...] COMMAND ...
查询或更改系统时间和日期设置。
-h --help 显示此帮助信息
--version 显示软件包版本
--no-pager 不要将输出管道输入到分页器
--no-ask-password 不提示密码
-H --host=[USER@]HOST 在远程主机上操作
-M --machine=CONTAINER 在本地容器上操作
--调整-系统-时钟 在更改本地RTC模式时调整系统时钟
命令:
显示当前时间设置
set-time TIME Set system time
set-timezone ZONE Set system time zone
list-timezones Show known time zones
set-local-rtc BOOL Control whether RTC is in local time
set-ntp BOOL Control whether NTP is enabled

3. Set time

$ sudo timedatectl set-time 15:26:58$ timedatectl
Local time: Mon 2016-08-29 15:27:00 CST
Universal time: Mon 2016-08-29 07:27:00 UTC
RTC time: Mon 2016-08-29 07:27:00
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a

PS: Let's see how to modify the server system time in CentOS

After the Linux installation is completed, it is generally overseas, which is not very convenient to set tasks, or it may cause the website to obtain the local time incorrectly, so it is necessary to change the server time to be consistent with the local time, that is, to change to Chinese time.

The first command: date –s '"2016-10-31 10:10:10"

The second command: clock –w //Write the date to CMOS

The time is in the format above, and it can be used again after the operation is completed

date

Check the server time, if it is the same as the setting, it means it has succeeded

The following is what the editor introduces to you about CentOS7The method to modify the server system time is provided for your reference. If you have any questions, please leave a message, and the editor will reply to you in time. Also, I would like to express my sincere gratitude to everyone for their support of the Yelling Tutorial website!

You May Also Like