Linux-设置时区及ntp服务器
设置时区
-
查看现在的时区
[root@proxy ~]# timedatectl Local time: Tue 2025-12-30 14:29:03 CST Universal time: Tue 2025-12-30 06:29:03 UTC RTC time: Tue 2025-12-30 06:29:03 Time zone: Asia/Shanghai (CST, +0800) System clock synchronized: yes NTP service: active RTC in local TZ: no -
列出时区列表,找到需要需改的时区
[root@proxy ~]# timedatectl list-timezones Africa/Abidjan Africa/Accra ... Asia/Shanghai ... -
设置时区
[root@proxy ~]# timedatectl set-timezone Asia/Shanghai
设置ntp服务器
-
下载ntp服务
dnf install chrony -
修改配置文件
vim /etc/chrony.conf# 注释掉原来的 server 行 # pool pool.ntp.org iburst # 使用阿里云 NTP 服务器 server ntp1.aliyun.com iburst server ntp2.aliyun.com iburst server ntp3.aliyun.com iburst server ntp4.aliyun.com iburst server ntp5.aliyun.com iburst server ntp6.aliyun.com iburst server ntp7.aliyun.com iburst -
启用chronyd服务
systemctl enable --now chronyd -
查看NTP数据源
[root@proxy ~]# chronyc sources -v .-- Source mode '^' = server, '=' = peer, '#' = local clock. / .- Source state '*' = current best, '+' = combined, '-' = not combined, | / 'x' = may be in error, '~' = too variable, '?' = unusable. || .- 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 =============================================================================== ^+ 118.31.40.99 2 6 377 4 -123us[ -123us] +/- 37ms ^* 203.107.6.88 2 6 377 6 -3181us[-3722us] +/- 41ms