安卓系统

如何在centos 7上设置或更改时区

3 6 Centos7网卡接口名称规则—阿里云ECS服务器与CentOS实战学习教程(价值288元)

3 6 Centos7网卡接口名称规则—阿里云ECS服务器与CentOS实战学习教程(价值288元)

目录:

Anonim

在CentOS上,系统的时区是在安装过程中设置的,但以后可以轻松更改。

对于许多与系统相关的任务和过程,使用正确的时区很重要。 例如,cron守护程序使用系统的时区执行cron作业,而日志文件中的时间戳基于同一系统的时区。

本教程说明了如何在CentOS 7上设置或更改时区。

先决条件

为了能够更改系统的时区,您需要以root用户或具有sudo特权的用户身份登录。

检查当前时区

在CentOS和其他现代Linux发行版中,您可以使用 timedatectl 命令显示和设置当前系统的时间和时区。

timedatectl

下面的输出显示系统的时区设置为UTC:

Local time: Wed 2019-02-06 22:43:42 UTC Universal time: Wed 2019-02-06 22:43:42 UTC RTC time: Wed 2019-02-06 22:43:42 Time zone: Etc/UTC (UTC, +0000) NTP enabled: no NTP synchronized: yes RTC in local TZ: no DST active: n/a

通过将 /etc/localtime 符号链接到 /usr/share/zoneinfo 目录中的二进制时区标识符来配置系统时区。 因此,检查时区的另一种方法是使用ls命令显示symlink指向的路径:

ls -l /etc/localtime

lrwxrwxrwx. 1 root root 29 Dec 11 09:25 /etc/localtime ->../usr/share/zoneinfo/Etc/UTC

在CentOS中更改时区

在更改时区之前,您需要找出要使用的时区的长名称。 时区命名约定通常使用“地区/城市”格式。

要列出所有可用时区,可以列出 /usr/share/zoneinfo 目录中的文件,也可以使用 timedatectl 命令。

timedatectl list-timezones

… America/Tijuana America/Toronto America/Tortola America/Vancouver America/Whitehorse America/Winnipeg…

确定了您所在位置的时区后,以sudo用户身份运行以下命令:

sudo timedatectl set-timezone your_time_zone

例如,要将系统的时区更改为 America/Toronto

sudo timedatectl set-timezone America/Toronto

运行 timedatectl 命令以验证更改:

timedatectl

Local time: Wed 2019-02-06 17:47:10 EST Universal time: Wed 2019-02-06 22:47:10 UTC RTC time: Wed 2019-02-06 22:47:10 Time zone: America/Toronto (EST, -0500) NTP enabled: no NTP synchronized: yes RTC in local TZ: no DST active: no Last DST change: DST ended at Sun 2018-11-04 01:59:59 EDT Sun 2018-11-04 01:00:00 EST Next DST change: DST begins (the clock jumps one hour forward) at Sun 2019-03-10 01:59:59 EST Sun 2019-03-10 03:00:00 EDT

通过创建符号链接来更改时区

删除当前的 /etc/localtime 文件或符号链接:

sudo rm -rf /etc/localtime

确定要配置的时区并创建符号链接:

sudo ln -s /usr/share/zoneinfo/America/Toronto /etc/localtime

您可以通过列出 /etc/localtime 文件或发出 date 命令来验证它:

date

Wed Feb 6 17:52:58 EST 2019

结论

在本指南中,我们显示了您更改CentOS系统的时区。 如有任何疑问,请随时发表评论。

centos终端