龙空技术网

Centos时区及时间设定以及同步

寒笛过霜天 83

前言:

此时各位老铁们对“centos7查看系统时间”大约比较关切,我们都需要知道一些“centos7查看系统时间”的相关资讯。那么小编也在网摘上搜集了一些对于“centos7查看系统时间””的相关文章,希望朋友们能喜欢,你们一起来了解一下吧!

CentOS7

查看时区时间信息

> # timedatectl

Local time: Mon 2018-01-15 22:39:30 CST

Universal time: Mon 2018-01-15 14:39:30 UTC

RTC time: Mon 2018-01-15 14:39:28

Time zone: Asia/Shanghai (CST, +0800)

NTP enabled: no

NTP synchronized: no

RTC in local TZ: no

DST active: n/a

设置时区

> # tzselect

Please identify a location so that time zone rules can be set correctly.

Please select a continent or ocean.

1) Africa

2) Americas

3) Antarctica

4) Arctic Ocean

5) Asia

6) Atlantic Ocean

7) Australia

8) Europe

9) Indian Ocean

10) Pacific Ocean

11) none - I want to specify the time zone using the Posix TZ format.

#? 5

Please select a country.

1) Afghanistan 18) Israel 35) Palestine

2) Armenia 19) Japan 36) Philippines

3) Azerbaijan 20) Jordan 37) Qatar

4) Bahrain 21) Kazakhstan 38) Russia

5) Bangladesh 22) Korea (North) 39) Saudi Arabia

6) Bhutan 23) Korea (South) 40) Singapore

7) Brunei 24) Kuwait 41) Sri Lanka

8) Cambodia 25) Kyrgyzstan 42) Syria

9) China 26) Laos 43) Taiwan

10) Cyprus 27) Lebanon 44) Tajikistan

11) East Timor 28) Macau 45) Thailand

12) Georgia 29) Malaysia 46) Turkmenistan

13) Hong Kong 30) Mongolia 47) United Arab Emirates

14) India 31) Myanmar (Burma) 48) Uzbekistan

15) Indonesia 32) Nepal 49) Vietnam

16) Iran 33) Oman 50) Yemen

17) Iraq 34) Pakistan

#? 9

Please select one of the following time zone regions.

1) Beijing Time

2) Xinjiang Time

#? 1

The following information has been given:

China

Beijing Time

Therefore TZ='Asia/Shanghai' will be used.

Local time is now: Mon Jan 15 22:44:51 CST 2018.

Universal Time is now: Mon Jan 15 14:44:51 UTC 2018.

Is the above information OK?

1) Yes

2) No

#? 1

You can make this change permanent for yourself by appending the line

TZ='Asia/Shanghai'; export TZ

to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you

can use the /usr/bin/tzselect command in shell scripts:

Asia/Shanghai

注意: CentOS6 兼容

ntp同步

yum install ntp

systemctl start ntpd

systemctl enable ntpd

CentOS6

系统时间修改

查看系统时间

> # date

Mon Jan 15 18:19:41 CST 2018

修改时间 date -s 修改时间

将系统日期设定为2013年03月04日

> # date -s 03/04/2013

将系统时间设定为上午10:38

> # date -s 10:38

修改完后执行:clock -w, 强制将时间写入COMS!

> # clock -w

修改时区

查看时区

> date -R

Mon, 15 Jan 2018 18:19:49 +0800

修改时区:(将Asia/shanghai-上海时区写入当前时区)

> # cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

解释:

-f:强行复制文件或目录, 不论目标文件或目录是否已存在;

提示是否覆盖, 输入Y回车,

然后 #date

查看时区和时间(CST, 中国时区)

ntp同步时间

> # yum install ntp

> # ntpdate pool.ntp.org

NTP服务为自启动

> # chkconfig ntpd on

> # chkconfig --list ntpd

ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

使用计划任务更新系统的时间

*/20 * * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1

标签: #centos7查看系统时间 #centos7查看当前时间 #centos显示时间命令 #centos查询时间设置 #centos锁屏时间命令