linux时间管理
文章目录
- linux时间管理
- 系统时间设置
- date命令
- tzselect命令
- windows自动对时
- 自动对时chronyd服务
- 部署时间服务器
- 服务端
- 客户端
linux时间管理
系统时间设置
date命令
[root@server ~ 16:26:58]# date
2025年 09月 15日 星期一 16:42:21 CST
#修改时间
[root@server ~ 16:42:21]# date -s '2025-09-19'
tzselect命令
查询时区名称。
[root@server ~ 14:03:25]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.1) Africa2) Americas3) Antarctica4) Arctic Ocean5) Asia6) Atlantic Ocean7) Australia8) Europe9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 2
Please select a country.1) Anguilla 19) Dominican Republic 37) Peru2) Antigua & Barbuda 20) Ecuador 38) Puerto Rico3) Argentina 21) El Salvador 39) St Barthelemy4) Aruba 22) French Guiana 40) St Kitts & Nevis5) Bahamas 23) Greenland 41) St Lucia6) Barbados 24) Grenada 42) St Maarten (Dutch)7) Belize 25) Guadeloupe 43) St Martin (French)8) Bolivia 26) Guatemala 44) St Pierre & Miquelon9) Brazil 27) Guyana 45) St Vincent
10) Canada 28) Haiti 46) Suriname
11) Caribbean NL 29) Honduras 47) Trinidad & Tobago
12) Cayman Islands 30) Jamaica 48) Turks & Caicos Is
13) Chile 31) Martinique 49) United States
14) Colombia 32) Mexico 50) Uruguay
15) Costa Rica 33) Montserrat 51) Venezuela
16) Cuba 34) Nicaragua 52) Virgin Islands (UK)
17) Curaçao 35) Panama 53) Virgin Islands (US)
18) Dominica 36) Paraguay
#? 49
Please select one of the following time zone regions.1) Eastern (most areas) 16) Central - ND (Morton rural)2) Eastern - MI (most areas) 17) Central - ND (Mercer)3) Eastern - KY (Louisville area) 18) Mountain (most areas)4) Eastern - KY (Wayne) 19) Mountain - ID (south); OR (east)5) Eastern - IN (most areas) 20) MST - Arizona (except Navajo)6) Eastern - IN (Da, Du, K, Mn) 21) Pacific7) Eastern - IN (Pulaski) 22) Alaska (most areas)8) Eastern - IN (Crawford) 23) Alaska - Juneau area9) Eastern - IN (Pike) 24) Alaska - Sitka area
10) Eastern - IN (Switzerland) 25) Alaska - Annette Island
11) Central (most areas) 26) Alaska - Yakutat
12) Central - IN (Perry) 27) Alaska (west)
13) Central - IN (Starke) 28) Aleutian Islands
14) Central - MI (Wisconsin border) 29) Hawaii
15) Central - ND (Oliver)
windows自动对时
自动对时chronyd服务
修改对齐时间为ntp.aliyun.com
[root@server ~ 13:57:59]# vim /etc/chrony.conf
[root@server ~ 14:01:16]# head /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server ntp.aliyun.com iburst# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
[root@server ~ 14:01:22]# systemctl restart chronyd
[root@server ~ 14:01:41]# ping ntp.aliyun.com
PING ntp.aliyun.com (203.107.6.88) 56(84) bytes of data.
64 bytes from 203.107.6.88 (203.107.6.88): icmp_seq=1 ttl=128 time=125 ms
64 bytes from 203.107.6.88 (203.107.6.88): icmp_seq=2 ttl=128 time=130 ms
64 bytes from 203.107.6.88 (203.107.6.88): icmp_seq=3 ttl=128 time=128 ms
64 bytes from 203.107.6.88 (203.107.6.88): icmp_seq=4 ttl=128 time=128 ms
64 bytes from 203.107.6.88 (203.107.6.88): icmp_seq=5 ttl=128 time=126 ms
64 bytes from 203.107.6.88 (203.107.6.88): icmp_seq=6 ttl=128 time=127 ms
64 bytes from 203.107.6.88 (203.107.6.88): icmp_seq=7 ttl=128 time=123 ms
^C
--- ntp.aliyun.com ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6009ms
rtt min/avg/max/mdev = 123.402/127.220/130.118/2.134 ms
#查看对齐对象
[root@server ~ 14:03:18]# chronyc sources -v
210 Number of sources = 1.-- Source mode '^' = server, '=' = peer, '#' = local clock./ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 203.107.6.88 2 6 37 33 -73us[ -290us] +/- 74ms
部署时间服务器
chrony既可以作为客户端,也可以作为服务端(为客户端提供对时服务)。
服务端
[root@server ~ 14:22:11]# vim /etc/chrony.conf[root@server ~ 14:30:42]# tail -n 5 /etc/chrony.conf# Select which information is logged.
#log measurements statistics tracking
bindaddress 10.1.8.10# 配置监听地址
allow 10.1.8.0/24# 配置允许哪些网段主机同步
#重启服务
[root@server ~ 14:23:47]# systemctl restart chronyd
客户端
# 修改对时服务器
[root@client ~ 14:22:40]$ vim /etc/chrony.conf
# 与单个服务器 10.1.8.10 对时
[root@client ~ 14:33:37]# head -n 10 /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 10.1.8.10 iburst# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift[root@client ~ 14:27:02]# systemctl restart chronyd
[root@client ~ 14:27:15]# chronyc sources -v
210 Number of sources = 1.-- Source mode '^' = server, '=' = peer, '#' = local clock./ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^? server.dyx.cloud 0 6 0 - +0ns[