设置系统时间、时区

目标

  同步服务器的系统时间和时区

演示操作

命令:date

语法:date 选项 参数
-s 设置时间

[root@jenkins log]# date -s "2022-02-17 14:25:59"
2022年 02月 17日 星期四 14:25:59 HKT

命令:timedatectl

语法:timedatectl 选项 参数
set-timezone 设置时区

[root@jenkins log]# timedatectl 
      Local time: 四 2022-02-17 14:20:27 CST
  Universal time: 四 2022-02-17 06:20:27 UTC
        RTC time: 四 2022-02-17 06:20:27
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
[root@jenkins log]# timedatectl set-timezone Asia/Hong_Kong 
[root@jenkins log]# timedatectl 
      Local time: 四 2022-02-17 14:20:58 HKT
  Universal time: 四 2022-02-17 06:20:58 UTC
        RTC time: 四 2022-02-17 06:20:58
       Time zone: Asia/Hong_Kong (HKT, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
  • chrony时间同步服务

    修改时间同步服务器地址,使其进行时间同步。

[root@jenkins ~]# vim /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 139.199.215.251 iburst

##查看时间同步状态
[root@jenkins ~]# 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               
===============================================================================
^* 139.199.215.251               2   6   277    16  +2108us[+1747us] +/-   42ms
文档更新时间: 2022-02-17 14:46   作者:xiubao yan