我是靠谱客的博主 爱撒娇高跟鞋,最近开发中收集的这篇文章主要介绍【Linux】Linux服务器时区设置和时间同步,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

        我们在安装Linux服务器的时候,可能会为了图方便,直接安装为系统默认的时区和语言,比如英语。但是,当系统安装启动后,我们会发现系统的时间是12小时制,这个与我们习惯的24小时制有一定的区别,看系统时间的时候可能会感觉有点怪怪的。所以,这个时候,我们就需要将系统的时区修改为5) Asia -  9) China - 1) Beijing Time。

# date
Sun Apr 17 00:49:40 EDT 2022
# 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
10) Cyprus
27) Lebanon
44) Tajikistan
11) East Timor
45) Thailand
12) Georgia
29) Malaysia
46) Turkmenistan
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:
Sun Apr 17 12:50:04 CST 2022.
Universal Time is now:
Sun Apr 17 04:50:04 UTC 2022.
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
# rm /etc/localtime
rm: remove symbolic link ‘/etc/localtime’? y
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# date
Sun Apr 17 12:50:30 CST 2022

        如果我们需要同步本地服务器的时间,可以通过与中国国家授时中心的NTP服务器来进行时间同步。

# yum install -y ntpdate
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================================================================
Package
Arch
Version
Repository
Size
=========================================================================================================================================================
Installing:
ntpdate
x86_64
4.2.6p5-29.el7.centos.2
base
87 k
Transaction Summary
=========================================================================================================================================================
Install
1 Package
Total download size: 87 k
Installed size: 121 k
Downloading packages:
ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm
|
87 kB
00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : ntpdate-4.2.6p5-29.el7.centos.2.x86_64
1/1
Verifying
: ntpdate-4.2.6p5-29.el7.centos.2.x86_64
1/1
Installed:
ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2
Complete!
// 中国国家授时中心的NTP官方服务器
# ntpdate -u ntp.ntsc.ac.cn
17 Apr 12:59:04 ntpdate[1348]: adjust time server 114.118.7.161 offset -0.001488 sec

最后

以上就是爱撒娇高跟鞋为你收集整理的【Linux】Linux服务器时区设置和时间同步的全部内容,希望文章能够帮你解决【Linux】Linux服务器时区设置和时间同步所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(31)

评论列表共有 0 条评论

立即
投稿
返回
顶部